Exemple #1
0
        void OnReceiveComplete(IncomingBuffer buffer)
        {
            if (buffer.AsyncArgs.BytesTransferred == 0)
            {
                IncomingBufferPool.TryPush(buffer);
                return;
            }

            var connection = buffer.Win32Connection;

            lock (IncomingBufferQueueSync)
            {
                IncomingBufferQueue.Enqueue(buffer);
            }

            ReceiverEvent.Set();
            Receive(connection);
        }
Exemple #2
0
        void ReceiveDone(IAsyncResult result)
        {
            var buffer     = (IncomingBuffer)result.AsyncState;
            var connection = buffer.MonoConnection;

            try
            {
                var bytesTransferred = connection.Socket.EndReceive(result);

#if DEBUG
                if (bytesTransferred == 0)
                {
                    Disconnect(connection);

                    if (!IncomingBufferPool.TryPush(buffer))
                    {
                        //TODO: Error
                    }

                    return;
                }
#endif

                buffer.BytesTransferred = bytesTransferred;

                lock (IncomingBufferQueueSync)
                {
                    IncomingBufferQueue.Enqueue(buffer);
                }

                ReceiverEvent.Set();
                Receive(connection);
            }
            catch (SocketException)
            {
                Disconnect(connection);

                if (!IncomingBufferPool.TryPush(buffer))
                {
                    //TODO: Error
                }
            }
        }