Exemple #1
0
        public TcpSocket(Socket acceptSocket, IBufferPool bufferPool, IContainer container)
        {
            UnderlyingSocket = acceptSocket;
            IPAddress        = acceptSocket.RemoteEndPoint as IPEndPoint;
            this.bufferPool  = bufferPool;

            ByteBuffer receiveBuffer;

            if (!bufferPool.TryGetByteBuffer(out receiveBuffer))
            {
                throw new Exception("No free buffers available to receive on the underlying socket.");
            }

            this.receiveEventArgs           = new SocketAsyncEventArgs();
            this.receiveEventArgs.UserToken = new ReceiveAsyncState()
            {
                byteBuffer = receiveBuffer,
            };
            this.receiveEventArgs.SetBuffer(receiveBuffer.Buffer, 0, 0); // initially assign the buffer
            this.receiveEventArgs.Completed += OnIOOperationCompleted;

            ByteBuffer sendBuffer;

            if (!bufferPool.TryGetByteBuffer(out sendBuffer))
            {
                throw new Exception("No free buffers available to send on the underlying socket.");
            }

            this.sendEventArgs           = new SocketAsyncEventArgs();
            this.sendEventArgs.UserToken = new SendAsyncState()
            {
                byteBuffer = sendBuffer,
            };
            this.sendEventArgs.SetBuffer(sendBuffer.Buffer, 0, 0); // initially assign the buffer
            this.sendEventArgs.Completed += OnIOOperationCompleted;

            socketWriterBuffer = new WriteBuffer(SendAsync);
            amqpConnection     = new AmqpConnection(this, container);
        }