Class: Dalli::Protocol::ResponseBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/protocol/response_buffer.rb

Overview

Manages the buffer for responses from memcached.

Instance Method Summary collapse

Constructor Details

#initialize(io_source, response_processor) ⇒ ResponseBuffer

Returns a new instance of ResponseBuffer.



12
13
14
15
16
# File 'lib/dalli/protocol/response_buffer.rb', line 12

def initialize(io_source, response_processor)
  @io_source = io_source
  @response_processor = response_processor
  @buffer = nil
end

Instance Method Details

#advance(bytes_to_advance) ⇒ Object

Advances the internal response buffer by bytes_to_advance bytes. The



32
33
34
35
36
# File 'lib/dalli/protocol/response_buffer.rb', line 32

def advance(bytes_to_advance)
  return unless bytes_to_advance.positive?

  @buffer = @buffer.byteslice(bytes_to_advance..-1)
end

#clearObject

Clear the internal response buffer



45
46
47
# File 'lib/dalli/protocol/response_buffer.rb', line 45

def clear
  @buffer = nil
end

#in_progress?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/dalli/protocol/response_buffer.rb', line 49

def in_progress?
  !@buffer.nil?
end

#process_single_getk_responseObject

Attempts to process a single response from the buffer. Starts by advancing the buffer to the specified start position



24
25
26
27
28
# File 'lib/dalli/protocol/response_buffer.rb', line 24

def process_single_getk_response
  bytes, status, cas, key, value = @response_processor.getk_response_from_buffer(@buffer)
  advance(bytes)
  [status, cas, key, value]
end

#readObject



18
19
20
# File 'lib/dalli/protocol/response_buffer.rb', line 18

def read
  @buffer << @io_source.read_nonblock
end

#resetObject

Resets the internal buffer to an empty state, so that we’re ready to read pipelined responses



40
41
42
# File 'lib/dalli/protocol/response_buffer.rb', line 40

def reset
  @buffer = ''.b
end