/// <summary> /// Starts receiving for given client and block. If timeout is specified, receiving will /// stop after that time. /// </summary> /// <param name="client">Client which receiving is set.</param> /// <param name="timeout">Timeout for receiving.</param> /// <param name="block">Block where received data will be stored.</param> internal void StartReceiving(ClientInternal client, int timeout, Block block) { if (client.AllowReceiving) throw new NotSupportedException("Cannot start receiving twice"); if (timeout != 0) throw new NotImplementedException("Handle timeout by calendar"); client.AllowReceiving = true; client.ReceiveBuffer = block; client.ReceiveEventArgs.SetBuffer(block.GetNativeBuffer(), 0, block.Size); RequestReceiving(client); }
/// <summary> /// Sends given block to given client. /// </summary> /// <param name="client">Client whom the data will be sent.</param> /// <param name="block">Block that will be sent.</param> /// <param name="dataOffset">Offset where data in block starts.</param> /// <param name="dataSize">Size of data to send.</param> internal void Send(ClientInternal client, Block blockToSend, int dataOffset, int dataSize) { client.LastSendBlock = chainBlock(blockToSend, dataOffset, dataSize, client.LastSendBlock); if (client.ActualSendBlock != null) //there is nothing to do now - another block is sent right now. return; //there is only one block client.ActualSendBlock = client.LastSendBlock; //send buffer client.SendEventArgs.SetBuffer(blockToSend.GetNativeBuffer(), dataOffset, dataSize); if (!client.Socket.SendAsync(client.SendEventArgs)) { //send was handled synchronously Callback_DataSent(client); } }