Exemple #1
0
        internal NetworkManager(IOPool pool)
        {
            _pool = pool;
            _clientSlots = new ClientInternal[pool.Configuration.MaxClientCount];
            _freeSlots = new Stack<int>(_clientSlots.Length);

            for (var i = 0; i < _clientSlots.Length; ++i)
            {
                var clientInternal = new ClientInternal(this, i);
                _clientSlots[i] = clientInternal;
                _freeSlots.Push(i);
            }
        }
Exemple #2
0
 /// <inheritdoc/>
 protected override void recycle()
 {
     ClientInternal = null;
 }
Exemple #3
0
 /// <summary>
 /// Sets client that is controlled by current controller.
 /// </summary>
 /// <param name="client">The client.</param>
 internal void SetClient(ClientInternal client)
 {
     ClientInternal = client;
 }
Exemple #4
0
 /// <summary>
 /// Fires event that handles data sent event.
 /// </summary>
 /// <param name="clientInternal">Client which data was sent.</param>
 internal void Fire_DataSent(ClientInternal clientInternal)
 {
     var evt = _dataSentEvents.GetEvent();
     evt.ClientInternal = clientInternal;
     _iochannel.EnqueueEvent(evt);
 }
Exemple #5
0
 /// <summary>
 /// Event args callback for data receiving.
 /// </summary>
 /// <param name="client">Client which received data.</param>
 internal void Callback_Receive(ClientInternal client)
 {
     _pool.Fire_DataReceive(client);
 }
Exemple #6
0
 /// <summary>
 /// Event args callback for data sent event.
 /// </summary>
 /// <param name="client">Client which data was sent.</param>
 internal void Callback_DataSent(ClientInternal client)
 {
     _pool.Fire_DataSent(client);
 }
Exemple #7
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);
        }
Exemple #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>
        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);
            }
        }
Exemple #9
0
        /// <summary>
        /// Expect that <see cref="ClientInternal.ReceiveBuffer"/> and <see cref="ClientInternal.ReceiveEventArgs"/> buffers are properly set.
        /// </summary>
        /// <param name="client">Client which receiving is requested.</param>
        internal void RequestReceiving(ClientInternal client)
        {
            if (!client.AllowReceiving)
                throw new NotSupportedException("Cannot continue receiving, when client doesn't allow receiving");

            if (!client.Socket.ReceiveAsync(client.ReceiveEventArgs))
            {
                //receive was handled synchronously
                Callback_Receive(client);
            }
        }