Esempio n. 1
0
        /// <summary>
        /// Creates block from copy of given data.
        /// </summary>
        /// <param name="data">Data that will be copied into the created block.</param>
        /// <returns>The created block.</returns>
        internal Block CreateConstantBlock(byte[] data)
        {
            if (_constantBytesAllocated + data.Length > _configuration.ConstantMemoryLimit)
                throw new NotSupportedException("Cannot allocate more data due to configuration limit for constant blocks");

            var block = new Block(data);
            _constantBlocks.Add(block);

            //register allocated memory
            _constantBytesAllocated += data.Length;

            return block;
        }
Esempio n. 2
0
        private void _dataReceived(DataReceivedController controller, Block block)
        {
            ReceivedBytesCount += controller.ReceivedBytes;

            _serverController.DataReceived(controller, block);
        }
Esempio n. 3
0
 /// <summary>
 /// Sends block to the controlled client.
 /// </summary>
 /// <param name="block">Block to send.</param>
 public void Send(Block block)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
 internal override void DataReceived(DataReceivedController controller, Block block)
 {
     var client = controller.ClientTag as ServerClient;
     client.ReportData(controller.ReceivedBytes);
 }
Esempio n. 5
0
 internal virtual void DataReceived(DataReceivedController controller, Block block)
 {
     //by default we do nothing
 }
Esempio n. 6
0
 /// <inheritdoc/>
 protected override void recycle()
 {
     Block = null;
     DataOffset = 0;
     DataSize = 0;
 }
Esempio n. 7
0
 /// <summary>
 /// Fires event that handles client sending.
 /// </summary>
 /// <param name="client">Client whom the data will be sent.</param>
 /// <param name="block">The data to send.</param>
 /// <param name="dataOffset">Offset where data in block starts.</param>
 /// <param name="dataSize">Size of data to send.</param>
 private void Fire_Send(Client client, Block block, int dataOffset, int dataSize)
 {
     var evt = _dataSendEvents.GetEvent();
     evt.Client = client;
     evt.Block = block;
     evt.DataOffset = dataOffset;
     evt.DataSize = dataSize;
     _iochannel.EnqueueEvent(evt);
 }
Esempio n. 8
0
 /// <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>
 public void Send(Client client, Block block, int dataOffset, int dataSize)
 {
     Fire_Send(client, block, dataOffset, dataSize);
 }
Esempio n. 9
0
        /// <summary>
        /// Chains given block.
        /// </summary>
        /// <param name="block">Block to chain.</param>
        /// <param name="previousChain">Previous chain, where created chain will be appended.</param>
        /// <returns>Chain with given block.</returns>
        private BlockChain chainBlock(Block block, int dataOffset, int dataSize, BlockChain previousChain = null)
        {
            BlockChain freeChain;
            if (_freeChains.Count == 0)
                freeChain = new BlockChain();
            else
                freeChain = _freeChains.Pop();

            freeChain.Block = block;
            freeChain.DataOffset = dataOffset;
            freeChain.DataSize = dataSize;

            if (previousChain != null)
                //chain with previous chain if available
                previousChain.Next = freeChain;

            return freeChain;
        }
Esempio n. 10
0
        /// <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);
        }
Esempio n. 11
0
        /// <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);
            }
        }