Class: NetworkFacade::TCP::Server
Instance Method Summary
collapse
#add, #read, #start, #write
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
21
22
23
24
25
26
27
28
|
# File 'lib/network-facade/tcp.rb', line 21
def initialize(options = {})
options[:port] ||= PORT
options[:host] ||= '0.0.0.0'
options[:no_delay] ||= true
options[:close_exec] ||= true
options[:server] ||= TCPServer.new(options[:host], options[:port])
super(options)
end
|
Instance Method Details
#accept ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/network-facade/tcp.rb', line 30
def accept
client = @options[:server].accept
NetworkFacade.log(:info, "Accept", client.peeraddr[2])
client.setsockopt(Socket::SOL_TCP, Socket::TCP_NODELAY, 1) if @options[:no_delay]
client.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if @options[:close_exec]
@fd << client
end
|
#client_id(client) ⇒ Object
38
39
40
|
# File 'lib/network-facade/tcp.rb', line 38
def client_id(client)
client.peeraddr[2]
end
|