Class: Ione::Io::Acceptor
- Inherits:
-
Object
- Object
- Ione::Io::Acceptor
- Defined in:
- lib/ione/io/acceptor.rb
Overview
An acceptor wraps a server socket and accepts client connections.
Constant Summary collapse
- BINDING_STATE =
0
- CONNECTED_STATE =
1
- CLOSED_STATE =
2
Instance Attribute Summary collapse
- #backlog ⇒ Object readonly
Instance Method Summary collapse
-
#close ⇒ Object
Stop accepting connections.
-
#closed? ⇒ Boolean
Returns true if the acceptor has stopped accepting connections.
-
#connected? ⇒ Boolean
Returns true if the acceptor is accepting connections.
-
#on_accept {|the| ... } ⇒ Object
Register a listener to be notified when client connections are accepted.
Instance Attribute Details
#backlog ⇒ Object (readonly)
16 17 18 |
# File 'lib/ione/io/acceptor.rb', line 16 def backlog @backlog end |
Instance Method Details
#close ⇒ Object
Stop accepting connections
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ione/io/acceptor.rb', line 63 def close @lock.synchronize do return false if @state == CLOSED_STATE @state = CLOSED_STATE end if @io begin @io.close rescue SystemCallError, IOError # nothing to do, the socket was most likely already closed ensure @io = nil end end true end |
#closed? ⇒ Boolean
Returns true if the acceptor has stopped accepting connections
86 87 88 |
# File 'lib/ione/io/acceptor.rb', line 86 def closed? @state == CLOSED_STATE end |
#connected? ⇒ Boolean
Returns true if the acceptor is accepting connections
91 92 93 |
# File 'lib/ione/io/acceptor.rb', line 91 def connected? @state != CLOSED_STATE end |
#on_accept {|the| ... } ⇒ Object
Register a listener to be notified when client connections are accepted
35 36 37 38 39 |
# File 'lib/ione/io/acceptor.rb', line 35 def on_accept(&listener) @lock.synchronize do @accept_listeners << listener end end |