public async Task StartAsync() { Exception receiveError = null; Exception sendError = null; try { // Spawn send and receive logic var receiveTask = DoReceive(); var sendTask = DoSend(); // If the sending task completes then close the receive // We don't need to do this in the other direction because the kestrel // will trigger the output closing once the input is complete. if (await Task.WhenAny(receiveTask, sendTask) == sendTask) { // Tell the reader it's being aborted _socket.Dispose(); } // Now wait for both to complete receiveError = await receiveTask; sendError = await sendTask; // Dispose the socket(should noop if already called) _socket.Dispose(); _receiveAwaitable.Dispose(); _sendAwaitable.Dispose(); } catch (Exception ex) { _trace.LogError(0, ex, $"Unexpected exception in {nameof(Connection)}.{nameof(StartAsync)}."); } finally { // Complete the output after disposing the socket Completed(receiveError, sendError); } }
public Task StopAsync() { _acceptAwaitable.Dispose(); _connectAwaitable.Dispose(); return(Task.CompletedTask); }
public Task StopAsync() { _receiveFromAwaitable.Dispose(); _sendToAwaitable.Dispose(); return(Task.CompletedTask); }