Class: Thin::Backends::TcpServer

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

Overview

Backend to act as a TCP 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, #threadpool_size, #timeout

Instance Method Summary collapse

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

#hostObject

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

#portObject

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

#connectObject

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

#disconnectObject

Stops the server



25
26
27
# File 'lib/thin/backends/tcp_server.rb', line 25

def disconnect
  EventMachine.stop_server(@signature)
end

#to_sObject



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

def to_s
  "#{@host}:#{@port}"
end