Module: IProto::EMConnection::FixedLengthProtocol

Included in:
IProto::EMConnection
Defined in:
lib/iproto/em.rb

Instance Method Summary collapse

Instance Method Details

#post_initObject



8
9
10
# File 'lib/iproto/em.rb', line 8

def post_init
  raise "you should set @_needed_size"  unless @_needed_size
end

#receive_chunk(chunk) ⇒ Object



26
27
28
# File 'lib/iproto/em.rb', line 26

def receive_chunk(chunk)
  # for override
end

#receive_data(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/iproto/em.rb', line 12

def receive_data(data)
  @buffer ||= ''
  offset = 0
  while (chunk = data[offset, _needed_size - @buffer.size]).size > 0
    @buffer << chunk
    offset += chunk.size
    if @buffer.size == _needed_size
      chunk = @buffer
      @buffer = ''
      receive_chunk chunk
    end
  end 
end