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); } }
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); } }
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); } }
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); } }
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); } }