Class: Thin::Backends::UnixServer

Inherits:
Base
  • Object
show all
Defined in:
lib/thin/backends/unix_server.rb

Overview

Backend to act as a UNIX domain socket server.

Instance Attribute Summary collapse

Attributes inherited from Base

#maximum_connections, #maximum_persistent_connections, #no_epoll, #persistent_connection_count, #server, #ssl, #ssl_options, #threaded, #timeout

Instance Method Summary collapse

Methods inherited from Base

#config, #connection_finished, #empty?, #running?, #size, #ssl?, #start, #stop, #stop!, #threaded?

Constructor Details

#initialize(socket) ⇒ UnixServer

Returns a new instance of UnixServer.



8
9
10
11
12
# File 'lib/thin/backends/unix_server.rb', line 8

def initialize(socket)
  raise PlatformNotSupported, 'UNIX domain sockets not available on Windows' if Thin.win?
  @socket = socket
  super()
end

Instance Attribute Details

#socketObject

UNIX domain socket on which the server is listening for connections.



6
7
8
# File 'lib/thin/backends/unix_server.rb', line 6

def socket
  @socket
end

Instance Method Details

#closeObject

Free up resources used by the backend.



34
35
36
# File 'lib/thin/backends/unix_server.rb', line 34

def close
  remove_socket_file
end

#connectObject

Connect the server



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/thin/backends/unix_server.rb', line 15

def connect
  at_exit { remove_socket_file } # In case it crashes
  old_umask = File.umask(0)
  begin
    EventMachine.start_unix_domain_server(@socket, UnixConnection, &method(:initialize_connection))
    # HACK EventMachine.start_unix_domain_server doesn't return the connection signature
    #      so we have to go in the internal stuff to find it.
  @signature = EventMachine.instance_eval{@acceptors.keys.first}
  ensure
    File.umask(old_umask)
  end
end

#disconnectObject

Stops the server



29
30
31
# File 'lib/thin/backends/unix_server.rb', line 29

def disconnect
  EventMachine.stop_server(@signature)
end

#to_sObject



38
39
40
# File 'lib/thin/backends/unix_server.rb', line 38

def to_s
  @socket
end