Prajna


GenericBuf

A class capable of reading/writing a buffer asynchronously using an underlying connection

Constructors

ConstructorDescription
new(conn, maxBufferSize)
Signature: (conn:IConn * maxBufferSize:int) -> GenericBuf

Instance members

Instance memberDescription
AsyncRecvBuf(...)
Signature: (callback:(obj * byte [] * int * int -> unit) * state:obj * bufferOffset:int * bufferSize:int) -> unit

Asynchronously receive a buffer and execute a callback when receive finishes A callback which executes once receive completes Callback takes in (state, buffer, offset size)=(obj, byte[], int, int) tuple state - arbitrary state specified by "state" parameter buffer - the buffer which contains the data retrieved the callback must copy the data or appropriately control bufferOffset before starting another AsyncRecvBuf if needed as buffer is reused offset - the offfset in buffer where data has been written size - the amount of data which has been written to buffer The state to pass to the callback The bufferOffset where data is to be written within internal buffer The length of data to be read

AsyncRecvBufWithSize(...)
Signature: (callback:(obj * byte [] * int * int -> unit) * state:obj * bufferOffset:int) -> unit

Asynchronously receive a buffer along with its size and execute callback when receive finishes The length of the buffer is first read, then the buffer is read. Receive fails and underlying connection is closed if buffer size is larger than maximum allowed. A callback which executes once receive completes Callback takes in (state, buffer, offset size)=(obj, byte[], int, int) tuple state - arbitrary state specified by "state" parameter buffer - the buffer which contains the data retrieved the callback must copy the data or appropriately control bufferOffset before starting another AsyncRecvBuf if needed as buffer is reused offset - the offfset in buffer where data has been written size - the amount of data which has been written to buffer The state to pass to the callback The bufferOffset where data is to be written within internal buffer

AsyncSendBuf(...)
Signature: (callbackO:Option<(obj -> unit)> * state:obj * buf:byte [] * bufferOffset:int * bufferSize:int) -> unit

Asynchronously send buffer and execute callback upon completion Optional parameter to specify callback to execute If specified callback takes in state, i.e. callback(state) The state to pass into the callback The buffer to send The buffer offset in the buffer to send The amount of data to send starting at bufferOffset

AsyncSendBufWithSize(...)
Signature: (callbackO:Option<(obj -> unit)> * state:obj * buf:byte [] * bufferOffset:int * bufferSize:int) -> unit

Asynchronously send buffer along with size of buffer and execute callback upon completion The buffer size is sent first, followed by the buffer (so receiver does not need to know size a priori) Optional parameter to specify callback to execute If specified callback takes in state, i.e. callback(state) The state to pass into the callback The buffer to send The buffer offset in the buffer to send The amount of data to send starting at bufferOffset

Fork me on GitHub