Class: GQTP::Backend::Coolio::Socket
- Inherits:
-
Coolio::TCPSocket
- Object
- Coolio::TCPSocket
- GQTP::Backend::Coolio::Socket
- Defined in:
- lib/gqtp/backend/coolio.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Socket
constructor
A new instance of Socket.
- #on_read(data) ⇒ Object
- #on_write_complete ⇒ Object
- #read(size, &block) ⇒ Object
- #write(*chunks, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Socket
Returns a new instance of Socket.
35 36 37 38 39 40 41 |
# File 'lib/gqtp/backend/coolio.rb', line 35 def initialize(*args) super @write_callbacks = [] @read_callbacks = [] @request = nil @buffer = "".force_encoding("ASCII-8BIT") end |
Instance Method Details
#on_read(data) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/gqtp/backend/coolio.rb', line 67 def on_read(data) @buffer << data until @read_callbacks.empty? size, callback = @read_callbacks.first break if @buffer.bytesize < size @read_callbacks.shift consume_data(size, callback) end end |
#on_write_complete ⇒ Object
51 52 53 54 55 56 |
# File 'lib/gqtp/backend/coolio.rb', line 51 def on_write_complete write_callbacks, @write_callbacks = @write_callbacks, [] write_callbacks.each do |callback| callback.call end end |