Module: DatTCP::Server::TCPServer
- Defined in:
- lib/dat-tcp.rb
Class Method Summary collapse
- .build(*args) ⇒ Object
-
.configure(tcp_server) ⇒ Object
‘setsockopt` values: * SOL_SOCKET - specifies the protocol layer the option applies to.
- .for_fd(file_descriptor) ⇒ Object
- .new(ip, port) ⇒ Object
Class Method Details
.build(*args) ⇒ Object
200 201 202 203 204 205 206 207 |
# File 'lib/dat-tcp.rb', line 200 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.
227 228 229 230 |
# File 'lib/dat-tcp.rb', line 227 def self.configure(tcp_server) tcp_server.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) tcp_server end |
.for_fd(file_descriptor) ⇒ Object
213 214 215 |
# File 'lib/dat-tcp.rb', line 213 def self.for_fd(file_descriptor) configure(::TCPServer.for_fd(file_descriptor)) end |
.new(ip, port) ⇒ Object
209 210 211 |
# File 'lib/dat-tcp.rb', line 209 def self.new(ip, port) configure(::TCPServer.new(ip, port)) end |