Class: Rev::IO
Overview
A buffered I/O class witch fits into the Rev Watcher framework. It provides both an observer which reads data as it’s received from the wire and a buffered write watcher which stores data and writes it out each time the socket becomes writable.
This class is primarily meant as a base class for other streams which need non-blocking writing, and is used to implement Rev’s Socket class and its associated subclasses.
Direct Known Subclasses
Defined Under Namespace
Classes: Watcher
Constant Summary collapse
- INPUT_SIZE =
Maximum number of bytes to consume at once
16384
Instance Method Summary collapse
-
#attach(loop) ⇒ Object
Attach to the event loop.
-
#attached? ⇒ Boolean
Is the watcher attached?.
-
#close ⇒ Object
Close the IO stream.
-
#closed? ⇒ Boolean
Is the IO object closed?.
-
#detach ⇒ Object
Detach from the event loop.
-
#disable ⇒ Object
Disable the watcher.
-
#enable ⇒ Object
Enable the watcher.
-
#enabled? ⇒ Boolean
Is the watcher enabled?.
-
#evloop ⇒ Object
Obtain the event loop associated with this object.
-
#initialize(io) ⇒ IO
constructor
A new instance of IO.
-
#on_close ⇒ Object
Called whenever the IO object hits EOF.
-
#on_read(data) ⇒ Object
Called whenever the IO object receives data.
-
#on_write_complete ⇒ Object
Called whenever a write completes and the output buffer is empty.
-
#output_buffer_size ⇒ Object
Number of bytes are currently in the output buffer.
-
#write(data) ⇒ Object
Write data in a buffered, non-blocking manner.
Methods included from Meta
event_callback, watcher_delegate
Constructor Details
Instance Method Details
#attach(loop) ⇒ Object
Attach to the event loop
34 |
# File 'lib/rev/io.rb', line 34 def attach(loop); @_read_watcher.attach loop; schedule_write if !@_write_buffer.empty?; self; end |
#attached? ⇒ Boolean
Is the watcher attached?
46 |
# File 'lib/rev/io.rb', line 46 def attached?; @_read_watcher.attached?; end |
#close ⇒ Object
Close the IO stream
87 88 89 90 91 92 93 94 |
# File 'lib/rev/io.rb', line 87 def close detach if attached? detach_write_watcher @_io.close unless @_io.closed? on_close nil end |
#closed? ⇒ Boolean
Is the IO object closed?
97 98 99 |
# File 'lib/rev/io.rb', line 97 def closed? @_io.nil? or @_io.closed? end |
#detach ⇒ Object
Detach from the event loop
37 |
# File 'lib/rev/io.rb', line 37 def detach; @_read_watcher.detach; self; end |
#disable ⇒ Object
Disable the watcher
43 |
# File 'lib/rev/io.rb', line 43 def disable; @_read_watcher.disable; self; end |
#enable ⇒ Object
Enable the watcher
40 |
# File 'lib/rev/io.rb', line 40 def enable; @_read_watcher.enable; self; end |
#enabled? ⇒ Boolean
Is the watcher enabled?
49 |
# File 'lib/rev/io.rb', line 49 def enabled?; @_read_watcher.enabled?; end |
#evloop ⇒ Object
Obtain the event loop associated with this object
52 |
# File 'lib/rev/io.rb', line 52 def evloop; @_read_watcher.evloop; end |
#on_close ⇒ Object
Called whenever the IO object hits EOF
67 |
# File 'lib/rev/io.rb', line 67 def on_close; end |
#on_read(data) ⇒ Object
Called whenever the IO object receives data
59 |
# File 'lib/rev/io.rb', line 59 def on_read(data); end |
#on_write_complete ⇒ Object
Called whenever a write completes and the output buffer is empty
63 |
# File 'lib/rev/io.rb', line 63 def on_write_complete; end |
#output_buffer_size ⇒ Object
Number of bytes are currently in the output buffer
82 83 84 |
# File 'lib/rev/io.rb', line 82 def output_buffer_size @_write_buffer.size end |
#write(data) ⇒ Object
Write data in a buffered, non-blocking manner
75 76 77 78 79 |
# File 'lib/rev/io.rb', line 75 def write(data) @_write_buffer << data schedule_write data.size end |