Module: DatTCP::Server::TCPServer

Defined in:
lib/dat-tcp.rb

Class Method Summary collapse

Class Method Details

.build(*args) ⇒ Object



199
200
201
202
203
204
205
206
# File 'lib/dat-tcp.rb', line 199

def self.build(*args)
  case args.size
  when 2
    self.new(*args)
  when 1
    self.for_fd(*args)
  end
end

.configure(tcp_server) ⇒ Object

‘setsockopt` values:

  • SOL_SOCKET - specifies the protocol layer the option applies to.

    SOL_SOCKET is basic socket options (as opposed to
    something like IPPROTO_TCP for TCP socket options).
    
  • SO_REUSEADDR - indicates that the rules used in validating addresses

    supplied in a bind(2) call should allow reuse of local
    addresses. This will allow us to re-bind to a port if
    we were shutdown and started right away. This will
    still throw an "address in use" if a socket is active
    on the port.
    


226
227
228
229
# File 'lib/dat-tcp.rb', line 226

def self.configure(tcp_server)
  tcp_server.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
  tcp_server
end

.for_fd(file_descriptor) ⇒ Object



212
213
214
# File 'lib/dat-tcp.rb', line 212

def self.for_fd(file_descriptor)
  configure(::TCPServer.for_fd(file_descriptor))
end

.new(ip, port) ⇒ Object



208
209
210
# File 'lib/dat-tcp.rb', line 208

def self.new(ip, port)
  configure(::TCPServer.new(ip, port))
end