protected virtual async Task SendToRemotePeerAsync(RemoteTcpPeerOutgoingMessage outgoingMessage) { try { await outgoingMessage.RemoteTcpPeer.TcpStream.WriteWithRealCancellationAsync( outgoingMessage.Buffer.Memory, outgoingMessage.Buffer.Offset, outgoingMessage.Buffer.Count, outgoingMessage.CancellationToken).ConfigureAwait(false); await outgoingMessage.RemoteTcpPeer.TcpStream.FlushAsync(outgoingMessage.CancellationToken).ConfigureAwait(false); outgoingMessage.SendTaskCompletionSource.TrySetResult(true); } #if NET45 catch (OperationCanceledException) { outgoingMessage.SendTaskCompletionSource.TrySetCanceled(); } #else catch (OperationCanceledException ex) { outgoingMessage.SendTaskCompletionSource.TrySetCanceled(ex.CancellationToken); } #endif catch (Exception ex) { var remoteTcpPeerErrorEventArgs = new RemoteTcpPeerExceptionEventArgs(outgoingMessage.RemoteTcpPeer, ex); this.OnRemoteTcpPeerExceptionOccured(remoteTcpPeerErrorEventArgs); } }
protected virtual void OnRemoteTcpPeerExceptionOccured(RemoteTcpPeerExceptionEventArgs e) { try { this.RemoteTcpPeerExceptionOccured?.Invoke(this, e); } catch (Exception ex) { var ue = new ExceptionEventArgs(ex); this.OnUnhandledException(ue); } }