Esempio n. 1
0
        public async Task RunAsync()
        {
            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
                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(RunAsync)}.");
            }
            finally
            {
                // Complete the output after disposing the socket
                Output.Complete();
            }
        }
Esempio n. 2
0
 public Task StopAsync()
 {
     _acceptAwaitable.Dispose();
     _connectAwaitable.Dispose();
     return(Task.CompletedTask);
 }