Class: Racoon::Worker
- Inherits:
-
Object
- Object
- Racoon::Worker
- Defined in:
- lib/racoon/worker.rb
Instance Method Summary collapse
-
#initialize(reactor, address) ⇒ Worker
constructor
A new instance of Worker.
- #on_attach(socket) ⇒ Object
- #on_writable(socket) ⇒ Object
- #send_message(message) ⇒ Object
Constructor Details
#initialize(reactor, address) ⇒ Worker
Returns a new instance of Worker.
12 13 14 15 16 |
# File 'lib/racoon/worker.rb', line 12 def initialize(reactor, address) @reactor = reactor @address = address @send_queue = [] end |
Instance Method Details
#on_attach(socket) ⇒ Object
18 19 20 21 22 |
# File 'lib/racoon/worker.rb', line 18 def on_attach(socket) @socket = socket socket.connect(@address.to_s) end |
#on_writable(socket) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/racoon/worker.rb', line 24 def on_writable(socket) unless @send_queue.empty? = @send_queue.shift socket.() else @reactor.deregister_writable(socket) end end |
#send_message(message) ⇒ Object
33 34 35 36 |
# File 'lib/racoon/worker.rb', line 33 def () @send_queue.push() @reactor.register_writable(@socket) end |