Class: Racoon::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/racoon/worker.rb

Instance Method Summary collapse

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?
    message = @send_queue.shift
    socket.send_message_string(message)
  else
    @reactor.deregister_writable(socket)
  end
end

#send_message(message) ⇒ Object



33
34
35
36
# File 'lib/racoon/worker.rb', line 33

def send_message(message)
  @send_queue.push(message)
  @reactor.register_writable(@socket)
end