Class: Baykit::BayServer::Agent::AcceptHandler
- Inherits:
-
Object
- Object
- Baykit::BayServer::Agent::AcceptHandler
- Includes:
- Baykit::BayServer::Agent, Util
- Defined in:
- lib/baykit/bayserver/agent/accept_handler.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#ch_count ⇒ Object
readonly
Returns the value of attribute ch_count.
-
#is_shutdown ⇒ Object
readonly
Returns the value of attribute is_shutdown.
-
#port_map ⇒ Object
readonly
Returns the value of attribute port_map.
Instance Method Summary collapse
- #close_all ⇒ Object
-
#initialize(agent, port_map) ⇒ AcceptHandler
constructor
A new instance of AcceptHandler.
- #on_acceptable(server_skt) ⇒ Object
- #on_busy ⇒ Object
- #on_closed ⇒ Object
- #on_free ⇒ Object
- #server_socket?(skt) ⇒ Boolean
- #shutdown ⇒ Object
Constructor Details
#initialize(agent, port_map) ⇒ AcceptHandler
Returns a new instance of AcceptHandler.
18 19 20 21 22 23 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 18 def initialize(agent, port_map) @agent = agent @port_map = port_map @ch_count = 0 @is_shutdown = false end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
12 13 14 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 12 def agent @agent end |
#ch_count ⇒ Object (readonly)
Returns the value of attribute ch_count.
16 17 18 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 16 def ch_count @ch_count end |
#is_shutdown ⇒ Object (readonly)
Returns the value of attribute is_shutdown.
15 16 17 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 15 def is_shutdown @is_shutdown end |
#port_map ⇒ Object (readonly)
Returns the value of attribute port_map.
13 14 15 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 13 def port_map @port_map end |
Instance Method Details
#close_all ⇒ Object
80 81 82 83 84 85 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 80 def close_all() @port_map.keys.each do |skt| BayLog.debug("%s Close server Socket: %s", @agent, skt) skt.close() end end |
#on_acceptable(server_skt) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 25 def on_acceptable(server_skt) port_dkr = @port_map[server_skt] begin client_skt, = server_skt.accept_nonblock rescue IO::WaitReadable # Maybe another agent get socket BayLog.debug("Accept failed (must wait readable)") return end BayLog.debug("Accepted: skt=%d", client_skt.fileno) begin port_dkr.check_admitted(client_skt) rescue => e BayLog.error_e(e) client_skt.close() return end client_skt.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK) tp = port_dkr.new_transporter(@agent, client_skt) @agent.non_blocking_handler.ask_to_start(client_skt) @agent.non_blocking_handler.ask_to_read(client_skt) @ch_count += 1 end |
#on_busy ⇒ Object
58 59 60 61 62 63 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 58 def on_busy() BayLog.debug("%s AcceptHandler:onBusy", @agent) @port_map.keys().each do |ch| @agent.selector.unregister(ch) end end |
#on_closed ⇒ Object
54 55 56 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 54 def on_closed() @ch_count -= 1 end |
#on_free ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 65 def on_free() BayLog.debug("%s AcceptHandler:onFree isShutdown=%s", @agent, @is_shutdown) if @is_shutdown return end @port_map.keys().each do |ch| @agent.selector.register(ch, Selector::OP_READ) end end |
#server_socket?(skt) ⇒ Boolean
76 77 78 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 76 def server_socket?(skt) return @port_map.key?(skt) end |
#shutdown ⇒ Object
87 88 89 90 91 |
# File 'lib/baykit/bayserver/agent/accept_handler.rb', line 87 def shutdown() @is_shutdown = true on_busy() @agent.wakeup() end |