Class: NetworkFacade::TCP::Server

Inherits:
Base::Server show all
Defined in:
lib/network-facade/tcp.rb

Direct Known Subclasses

SSL::Server

Instance Attribute Summary

Attributes inherited from Base::Server

#thread

Instance Method Summary collapse

Methods inherited from Base::Server

#add, #start

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



26
27
28
29
30
31
32
33
# File 'lib/network-facade/tcp.rb', line 26

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

#acceptObject



35
36
37
38
39
40
41
# File 'lib/network-facade/tcp.rb', line 35

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]
	client
end

#client_id(client) ⇒ Object



43
44
45
# File 'lib/network-facade/tcp.rb', line 43

def client_id(client)
	client.peeraddr[2]
end