class EM::Nodes::Server
Attributes
alive[R]
data[R]
Public Class Methods
alive_clients()
click to toggle source
# File lib/em-nodes/server.rb, line 18 def alive_clients clients.select &:alive end
clients()
click to toggle source
# File lib/em-nodes/server.rb, line 14 def clients @clients ||= [] end
start(host, port = nil, *args)
click to toggle source
# File lib/em-nodes/server.rb, line 65 def self.start(host, port = nil, *args) EM::Nodes.logger.info { "Start server #{host}#{port ? ':' + port.to_s : nil}" } EM.start_server host, port, self, *args end
Public Instance Methods
accept?(host, port)
click to toggle source
# File lib/em-nodes/server.rb, line 25 def accept?(host, port) true end
inactivity_timeout()
click to toggle source
# File lib/em-nodes/server.rb, line 29 def inactivity_timeout 10 * 60 # 10 minutes default end
post_init()
click to toggle source
Calls superclass method
# File lib/em-nodes/server.rb, line 33 def post_init super @data = OpenStruct.new self.comm_inactivity_timeout = inactivity_timeout if EM.reactor_running? port, host = Socket.unpack_sockaddr_in(get_peername) rescue [] unless host host = Socket.unpack_sockaddr_un(get_sockname) rescue nil end unless accept?(host, port) unbind return end self.data.host = host self.data.port = port @alive = true self.class.clients << self EM::Nodes.logger.info { "Incomming connection from #{host}:#{port}" } end
unbind()
click to toggle source
Calls superclass method
# File lib/em-nodes/server.rb, line 58 def unbind super @alive = false self.class.clients.delete self EM::Nodes.logger.info { "Client #{self.data.inspect} has disconnected" } end