Class: Foolio::Handler
- Inherits:
-
Object
- Object
- Foolio::Handler
- Includes:
- Listener
- Defined in:
- lib/foolio/stream.rb
Direct Known Subclasses
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(handle) ⇒ Handler
constructor
A new instance of Handler.
- #on_close ⇒ Object
- #on_connect ⇒ Object
- #on_recv(data) ⇒ Object
- #on_write_complete(err) ⇒ Object
- #start ⇒ Object
- #write(data) ⇒ Object
Methods included from Listener
Constructor Details
#initialize(handle) ⇒ Handler
Returns a new instance of Handler.
7 8 9 |
# File 'lib/foolio/stream.rb', line 7 def initialize(handle) @handle = handle end |
Instance Method Details
#close ⇒ Object
16 17 18 19 20 21 |
# File 'lib/foolio/stream.rb', line 16 def close $log.info "close #{@handle}" Foolio::UV.close(@handle, callback{ clear_callbacks }) end |
#on_close ⇒ Object
25 |
# File 'lib/foolio/stream.rb', line 25 def on_close; end |
#on_connect ⇒ Object
24 |
# File 'lib/foolio/stream.rb', line 24 def on_connect; end |
#on_recv(data) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/foolio/stream.rb', line 27 def on_recv(data) if data then on_read(data) else close end end |
#on_write_complete(err) ⇒ Object
23 |
# File 'lib/foolio/stream.rb', line 23 def on_write_complete(err); end |
#start ⇒ Object
35 36 37 |
# File 'lib/foolio/stream.rb', line 35 def start Foolio::UV.read_start(@handle, callback(&method(:on_recv))) end |
#write(data) ⇒ Object
11 12 13 14 |
# File 'lib/foolio/stream.rb', line 11 def write(data) Foolio::UV.write(nil, @handle, data, callback{|status| on_write_complete(status)}) end |