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); outgoingMessage.SendTaskCompletionSource.TrySetResult(true); } catch (OperationCanceledException ex) { outgoingMessage.SendTaskCompletionSource.TrySetCanceled(ex.CancellationToken); } catch (Exception ex) { var remoteTcpPeerErrorEventArgs = new RemoteTcpPeerErrorEventArgs(new RemoteTcpPeerErrorData(outgoingMessage.RemoteTcpPeer, ex)); this.OnRemoteTcpPeerErrorOccured(remoteTcpPeerErrorEventArgs); } }
protected virtual void OnRemoteTcpPeerErrorOccured(RemoteTcpPeerErrorEventArgs e) { this.RemoteTcpPeerErrorOccured?.Invoke(this, e); }