Class: Thin::Backends::AttachSocket
- Inherits:
-
Base
- Object
- Base
- Thin::Backends::AttachSocket
- Defined in:
- lib/thin/attach_socket.rb
Overview
Backend to act as a TCP server using an already opened file descriptor. Currently requires a patched EventMachine like github.com/ibc/EventMachine-LE
If you’re running thin inside a reactor with other servers, then pass preserve_reactor: true. This ensures that when you stop the Thin server, it will not stop your reactor.
If you’re doing that you probably also want to pass signals: false so that you can control when thin shuts down:
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(host, port, options) ⇒ AttachSocket
constructor
A new instance of AttachSocket.
- #stop! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host, port, options) ⇒ AttachSocket
Returns a new instance of AttachSocket.
32 33 34 35 36 |
# File 'lib/thin/attach_socket.rb', line 32 def initialize(host, port, ) @socket = [:socket] @preserve_reactor = !![:preserve_reactor] super() end |
Instance Method Details
#connect ⇒ Object
38 39 40 |
# File 'lib/thin/attach_socket.rb', line 38 def connect @signature = EventMachine.attach_server(@socket, Connection, &method(:initialize_connection)) end |
#disconnect ⇒ Object
42 43 44 |
# File 'lib/thin/attach_socket.rb', line 42 def disconnect EventMachine.stop_server(@signature) end |
#stop! ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/thin/attach_socket.rb', line 50 def stop! if @preserve_reactor # This is the code for super, with the EM::stop call removed. @running = false @stopping = false @connections.each { |connection| connection.close_connection_after_writing } close else super end end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/thin/attach_socket.rb', line 46 def to_s "socket:#{@socket.inspect}" end |