Ejemplo n.º 1
0
        public async Task <int> ReceiveAsync(ArraySegment <byte> buffer)
        {
            var awaitable = SocketAwaitablePool.Take();

            try
            {
                awaitable.EventArgs.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);
                await _socket.ReceiveAsync(awaitable);

                return(awaitable.EventArgs.BytesTransferred);
            }
            finally
            {
                SocketAwaitablePool.Add(awaitable);
            }
        }
Ejemplo n.º 2
0
        public async Task <int> ReceiveAsync(byte[] array, int offset, int count)
        {
            var awaitableSocket = AwaitableSocketPool.Take();

            awaitableSocket.EventArgs.SetBuffer(array, offset, count);

            try
            {
                await _socket.ReceiveAsync(awaitableSocket);

                int bytesRead = awaitableSocket.EventArgs.BytesTransferred;
                return(bytesRead);
            }
            finally
            {
                AwaitableSocketPool.Add(awaitableSocket);
            }
        }
Ejemplo n.º 3
0
 private static void ConnectCompleted(object sender, SocketAsyncEventArgs socketAsyncEventArgs)
 {
     try
     {
         var callback = (ConnectionConnectCallback)socketAsyncEventArgs.UserToken;
         var success  = socketAsyncEventArgs.SocketError == SocketError.Success;
         callback(success);
     }
     finally
     {
         ConnectSaeaPool.Add(socketAsyncEventArgs);
     }
 }
Ejemplo n.º 4
0
 private void IOCompleted(object sender, SocketAsyncEventArgs saea)
 {
     if (Listener != null)
     {
         Listen();
     }
     try
     {
         if (saea.SocketError == SocketError.Success)
         {
             Notify(saea);
         }
     }
     finally
     {
         saea.Completed -= IOCompleted;
         ConnectSaeaPool.Add(saea);
     }
 }
Ejemplo n.º 5
0
        private static void SendRecvCompleted(object sender, SocketAsyncEventArgs socketAsyncEventArgs)
        {
            try
            {
                var callback = (ConnectionIoCallback)socketAsyncEventArgs.UserToken;

                if (socketAsyncEventArgs.SocketError != SocketError.Success ||
                    socketAsyncEventArgs.BytesTransferred == 0)
                {
                    callback(0, false);
                    return;
                }

                callback(socketAsyncEventArgs.BytesTransferred, true);
            }
            finally
            {
                SendRecvSaeaPool.Add(socketAsyncEventArgs);
            }
        }