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, #threaded, #timeout

Instance Method Summary collapse

Methods inherited from Base

#config, #connection_finished, #empty?, #running?, #size, #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.



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

def close
  remove_socket_file
end

#connectObject

Connect the server



15
16
17
18
19
20
21
# File 'lib/thin/backends/unix_server.rb', line 15

def connect
  at_exit { remove_socket_file } # In case it crashes
  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}
end

#disconnectObject

Stops the server



24
25
26
# File 'lib/thin/backends/unix_server.rb', line 24

def disconnect
  EventMachine.stop_server(@signature)
end

#to_sObject



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

def to_s
  @socket
end