Class: Dalli::Protocol::ResponseBuffer
- Inherits:
-
Object
- Object
- Dalli::Protocol::ResponseBuffer
- Defined in:
- lib/dalli/protocol/response_buffer.rb
Overview
Manages the buffer for responses from memcached.
Instance Method Summary collapse
-
#advance(bytes_to_advance) ⇒ Object
Advances the internal response buffer by bytes_to_advance bytes.
-
#clear ⇒ Object
Clear the internal response buffer.
- #in_progress? ⇒ Boolean
-
#initialize(io_source, response_processor) ⇒ ResponseBuffer
constructor
A new instance of ResponseBuffer.
-
#process_single_getk_response ⇒ Object
Attempts to process a single response from the buffer.
- #read ⇒ Object
-
#reset ⇒ Object
Resets the internal buffer to an empty state, so that we’re ready to read pipelined responses.
Constructor Details
#initialize(io_source, response_processor) ⇒ ResponseBuffer
Returns a new instance of ResponseBuffer.
12 13 14 15 |
# File 'lib/dalli/protocol/response_buffer.rb', line 12 def initialize(io_source, response_processor) @io_source = io_source @response_processor = response_processor end |
Instance Method Details
#advance(bytes_to_advance) ⇒ Object
Advances the internal response buffer by bytes_to_advance bytes. The
31 32 33 34 35 |
# File 'lib/dalli/protocol/response_buffer.rb', line 31 def advance(bytes_to_advance) return unless bytes_to_advance.positive? @buffer = @buffer[bytes_to_advance..-1] end |
#clear ⇒ Object
Clear the internal response buffer
44 45 46 |
# File 'lib/dalli/protocol/response_buffer.rb', line 44 def clear @buffer = nil end |
#in_progress? ⇒ Boolean
48 49 50 |
# File 'lib/dalli/protocol/response_buffer.rb', line 48 def in_progress? !@buffer.nil? end |
#process_single_getk_response ⇒ Object
Attempts to process a single response from the buffer. Starts by advancing the buffer to the specified start position
23 24 25 26 27 |
# File 'lib/dalli/protocol/response_buffer.rb', line 23 def process_single_getk_response bytes, resp_header, key, value = @response_processor.getk_response_from_buffer(@buffer) advance(bytes) [resp_header, key, value] end |
#read ⇒ Object
17 18 19 |
# File 'lib/dalli/protocol/response_buffer.rb', line 17 def read @buffer << @io_source.read_nonblock end |
#reset ⇒ Object
Resets the internal buffer to an empty state, so that we’re ready to read pipelined responses
39 40 41 |
# File 'lib/dalli/protocol/response_buffer.rb', line 39 def reset @buffer = +'' end |