Class: EM::Nodes::Server
- Inherits:
-
Connection
- Object
- Connection
- EM::Nodes::Server
show all
- Includes:
- Commands, P::ObjectProtocol
- Defined in:
- lib/em-nodes/server/hello.rb,
lib/em-nodes/server/task.rb,
lib/em-nodes/server.rb
Defined Under Namespace
Modules: HelloFeature, TaskFeature
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#alive ⇒ Object
Returns the value of attribute alive.
11
12
13
|
# File 'lib/em-nodes/server.rb', line 11
def alive
@alive
end
|
#data ⇒ Object
Returns the value of attribute data.
23
24
25
|
# File 'lib/em-nodes/server.rb', line 23
def data
@data
end
|
Class Method Details
.alive_clients ⇒ Object
18
19
20
|
# File 'lib/em-nodes/server.rb', line 18
def alive_clients
clients.select &:alive
end
|
.clients ⇒ Object
14
15
16
|
# File 'lib/em-nodes/server.rb', line 14
def clients
@clients ||= []
end
|
.start(host, port = nil, *args) ⇒ Object
65
66
67
68
|
# 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
|
Instance Method Details
#accept?(host, port) ⇒ Boolean
25
26
27
|
# File 'lib/em-nodes/server.rb', line 25
def accept?(host, port)
true
end
|
#inactivity_timeout ⇒ Object
29
30
31
|
# File 'lib/em-nodes/server.rb', line 29
def inactivity_timeout
10 * 60 end
|
#post_init ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# 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 ⇒ Object
58
59
60
61
62
63
|
# 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
|