Class: Staccato::Proxy::Listener
- Inherits:
-
Object
- Object
- Staccato::Proxy::Listener
- Includes:
- Celluloid::IO
- Defined in:
- lib/staccato/proxy/listener.rb
Constant Summary collapse
- FRAME_SIZE =
4096
Instance Method Summary collapse
- #debug(msg) ⇒ Object
- #finalize ⇒ Object
-
#initialize(host, port, debug = false) ⇒ Listener
constructor
A new instance of Listener.
- #log(msg) ⇒ Object
- #receive(data) ⇒ Object
- #run ⇒ Object
- #sender ⇒ Object
Constructor Details
#initialize(host, port, debug = false) ⇒ Listener
Returns a new instance of Listener.
7 8 9 10 11 12 |
# File 'lib/staccato/proxy/listener.rb', line 7 def initialize(host, port, debug = false) @socket = UDPSocket.new.tap {|s| s.bind(host, port)} @debug = debug async.run end |
Instance Method Details
#debug(msg) ⇒ Object
35 36 37 |
# File 'lib/staccato/proxy/listener.rb', line 35 def debug(msg) log(msg) if @debug end |
#finalize ⇒ Object
14 15 16 |
# File 'lib/staccato/proxy/listener.rb', line 14 def finalize @socket.close if @socket end |
#log(msg) ⇒ Object
31 32 33 |
# File 'lib/staccato/proxy/listener.rb', line 31 def log(msg) Celluloid.logger.info(msg) end |
#receive(data) ⇒ Object
22 23 24 25 |
# File 'lib/staccato/proxy/listener.rb', line 22 def receive(data) debug data sender.async.submit(data[0]) end |
#run ⇒ Object
18 19 20 |
# File 'lib/staccato/proxy/listener.rb', line 18 def run loop {async.receive(@socket.recvfrom(FRAME_SIZE))} end |
#sender ⇒ Object
27 28 29 |
# File 'lib/staccato/proxy/listener.rb', line 27 def sender Celluloid::Actor[:staccato_proxy_sender] end |