Class: Zerg::Support::Sockets::ProtocolAdapter::StateBase

Inherits:
Object
  • Object
show all
Defined in:
lib/zerg_support/sockets/protocol_adapter.rb

Overview

Base class for the adapter state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ StateBase

Returns a new instance of StateBase.



52
53
54
55
# File 'lib/zerg_support/sockets/protocol_adapter.rb', line 52

def initialize(target)
  @recv_object_buffer = []
  @target = target
end

Instance Attribute Details

#recv_object_bufferObject (readonly)

Returns the value of attribute recv_object_buffer.



51
52
53
# File 'lib/zerg_support/sockets/protocol_adapter.rb', line 51

def recv_object_buffer
  @recv_object_buffer
end

Instance Method Details

#send_bytes(data) ⇒ Object

Called by the protocol when an entire object is available.



58
59
60
61
62
63
64
65
66
67
# File 'lib/zerg_support/sockets/protocol_adapter.rb', line 58

def send_bytes(data)
  # NOTE: need to chunk the data so kernel buffers don't overflow.
  #       Found out about this the hard way -- sending 150k in one call
  #       drops data.      
  i = 0
  while i < data.length      
    @target.send data[i, 65536], 0
    i += 65536
  end
end