Class: Thin::Backends::TcpServer
- Defined in:
- lib/thin/backends/tcp_server.rb
Overview
Backend to act as a TCP socket server.
Instance Attribute Summary collapse
-
#host ⇒ Object
Address and port on which the server is listening for connections.
-
#port ⇒ Object
Address and port on which the server is listening for connections.
Attributes inherited from Base
#maximum_connections, #maximum_persistent_connections, #no_epoll, #persistent_connection_count, #server, #ssl, #ssl_options, #threaded, #threadpool_size, #timeout
Instance Method Summary collapse
-
#connect ⇒ Object
Connect the server.
-
#disconnect ⇒ Object
Stops the server.
-
#initialize(host, port) ⇒ TcpServer
constructor
A new instance of TcpServer.
- #to_s ⇒ Object
Methods inherited from Base
#close, #config, #connection_finished, #empty?, #running?, #size, #ssl?, #start, #started_reactor?, #stop, #stop!, #threaded?
Constructor Details
#initialize(host, port) ⇒ TcpServer
Returns a new instance of TcpServer.
8 9 10 11 12 |
# File 'lib/thin/backends/tcp_server.rb', line 8 def initialize(host, port) @host = host @port = port super() end |
Instance Attribute Details
#host ⇒ Object
Address and port on which the server is listening for connections.
6 7 8 |
# File 'lib/thin/backends/tcp_server.rb', line 6 def host @host end |
#port ⇒ Object
Address and port on which the server is listening for connections.
6 7 8 |
# File 'lib/thin/backends/tcp_server.rb', line 6 def port @port end |
Instance Method Details
#connect ⇒ Object
Connect the server
15 16 17 18 19 20 21 22 |
# File 'lib/thin/backends/tcp_server.rb', line 15 def connect @signature = EventMachine.start_server(@host, @port, Connection, &method(:initialize_connection)) binary_name = EventMachine.get_sockname( @signature ) port_name = Socket.unpack_sockaddr_in( binary_name ) @port = port_name[0] @host = port_name[1] @signature end |
#disconnect ⇒ Object
Stops the server
25 26 27 |
# File 'lib/thin/backends/tcp_server.rb', line 25 def disconnect EventMachine.stop_server(@signature) end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/thin/backends/tcp_server.rb', line 29 def to_s "#{@host}:#{@port}" end |