module IProto::EMConnection::FixedLengthProtocol

Public Instance Methods

buffer_reset() click to toggle source
# File lib/iproto/em.rb, line 30
def buffer_reset
  @buffer = ''.b
end
post_init() click to toggle source
# File lib/iproto/em.rb, line 8
def post_init
  raise "you should set @_needed_size"  unless @_needed_size
end
receive_chunk(chunk) click to toggle source
# File lib/iproto/em.rb, line 26
def receive_chunk(chunk)
  # for override
end
receive_data(data) click to toggle source
# File lib/iproto/em.rb, line 12
def receive_data(data)
  @buffer ||= ''.b
  offset = 0
  while (chunk = data.byteslice(offset, _needed_size - @buffer.bytesize)).size > 0
    @buffer << chunk
    offset += chunk.size
    if @buffer.size == _needed_size
      chunk = @buffer
      @buffer = ''.b
      receive_chunk chunk
    end
  end 
end