Exemple #1
0
        internal void Receive(Connection connection)
        {
            IncomingBuffer buffer;

            if (IncomingBufferPool.TryPop(out buffer))
            {
                buffer.Win32Connection = connection;

                var isDone = !connection.Socket.ReceiveAsync(buffer.AsyncArgs);
                if (isDone)
                {
                    OnReceiveComplete(buffer);
                }
            }
            else
            {
                //TODO: Error
            }
        }
Exemple #2
0
        internal void Receive(Connection connection)
        {
#if DEBUG
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
#endif
            IncomingBuffer buffer;

            if (IncomingBufferPool.TryPop(out buffer))
            {
                buffer.MonoConnection = connection;

                try
                {
                    connection.Socket.BeginReceive(
                        buffer.BufferHandle,
                        buffer.BufferOffset,
                        buffer.BufferSize,
                        System.Net.Sockets.SocketFlags.None,
                        ReceiveDone,
                        buffer
                        );
                }
                catch (SocketException)
                {
                    Disconnect(connection);
                    IncomingBufferPool.TryPush(buffer);
                }
                catch (NullReferenceException)
                {
                    // This means that socket was null (connection was already closed)
                    // We can just ignore this
                }
            }
            else
            {
                //TODO: Error
            }
        }