private void PipeRemoteReceiveCallback(IAsyncResult ar) { if (_closed) { return; } try { int bytesRead = _remote.EndReceive(ar); if (bytesRead > 0) { var e = new RelayEventArgs(_remote, RelaySockType.Remote, RelaySockAction.Recv, remoteRecvBuffer, 0, bytesRead); _relay.onRelay(e); _local.BeginSend(e.Buffer, e.Offset, e.Length, 0, new AsyncCallback(PipeConnectionSendCallback), e); } else { this.Close(); } } catch (Exception e) { _relay.onError(new RelayErrorEventArgs(e)); this.Close(); } }
private void remoteSendCallback(IAsyncResult ar) { if (_closed) { return; } try { byte[] bytes = (byte[])ar.AsyncState; _remote.EndSend(ar); var e = new RelayEventArgs(_remote, RelaySockType.Remote, RelaySockAction.Send, _remoteEP, bytes, 0, bytes.Length); _relay.onRelay(e); lock (_packages) _sending = false; StartSend(); } catch (Exception e) { _relay.onError(new RelayErrorEventArgs(e)); this.Close(); } }