コード例 #1
0
 private void StartSend()
 {
     if (_closed)
     {
         return;
     }
     try
     {
         lock (_packages)
         {
             if (_sending || !_connected)
             {
                 return;
             }
             if (_packages.Count > 0)
             {
                 _sending = true;
                 byte[] bytes = _packages.First.Value;
                 _packages.RemoveFirst();
                 var e = new RelayEventArgs(bytes, 0, bytes.Length);
                 _relay.onInbound(e);
                 _remote.BeginSend(e.Buffer, e.Offset, e.Length, 0, new AsyncCallback(remoteSendCallback), null);
                 Delay();
             }
         }
     }
     catch (Exception e)
     {
         _relay.onError(new RelayErrorEventArgs(e));
         this.Close();
     }
 }
コード例 #2
0
            private void PipeConnectionReceiveCallback(IAsyncResult ar)
            {
                if (_closed)
                {
                    return;
                }
                try
                {
                    int bytesRead = _local.EndReceive(ar);

                    if (bytesRead > 0)
                    {
                        var e = new RelayEventArgs(connetionRecvBuffer, 0, bytesRead);
                        _relay.onInbound(e);
                        _remote.BeginSend(e.Buffer, e.Offset, e.Length, 0, new AsyncCallback(PipeRemoteSendCallback), null);
                    }
                    else
                    {
                        this.Close();
                    }
                }
                catch (Exception e)
                {
                    _relay.onError(new RelayErrorEventArgs(e));
                    this.Close();
                }
            }
コード例 #3
0
            private void PipeRemoteReceiveCallback(IAsyncResult ar)
            {
                if (_closed)
                {
                    return;
                }
                try
                {
                    int bytesRead = _remote.EndReceive(ar);

                    if (bytesRead > 0)
                    {
                        _relay.onInbound(bytesRead);
                        _local.BeginSend(remoteRecvBuffer, 0, bytesRead, 0, new AsyncCallback(PipeConnectionSendCallback), null);
                    }
                    else
                    {
                        this.Close();
                    }
                }
                catch (Exception e)
                {
                    Logging.LogUsefulException(e);
                    this.Close();
                }
            }
コード例 #4
0
            private void PipeConnectionReceiveCallback(IAsyncResult ar)
            {
                if (_closed)
                {
                    return;
                }
                try
                {
                    int bytesRead = _local.EndReceive(ar);

                    if (bytesRead > 0)
                    {
                        var e = new RelayEventArgs(connetionRecvBuffer, 0, bytesRead);
                        _relay.onInbound(e);
                        _relay.onWriteLog(new WriteLogEventArgs($"{_id}: 发送 {bytesRead} 字节到 {_remoteEP} ...\r\n"));
                        _remoteTime = Environment.TickCount;
                        _remote.BeginSend(e.Buffer, e.Offset, e.Length, 0, new AsyncCallback(PipeRemoteSendCallback), null);
                    }
                    else
                    {
                        this.Close();
                    }
                }
                catch (Exception e)
                {
                    _relay.onError(new RelayErrorEventArgs(e));
                    this.Close();
                }
            }
コード例 #5
0
 private void remoteReceiveCallback(IAsyncResult ar)
 {
     if (_closed)
     {
         return;
     }
     try
     {
         int bytesRead = _remote.EndReceive(ar);
         resetExpireTime();
         Logging.Debug($"recv {bytesRead} bytes from {_remoteEP}");
         if (bytesRead > 0)
         {
             _relay.onInbound(bytesRead);
             Logging.Debug($"send {bytesRead} bytes to {_localEP}");
             _local.BeginSendTo(remoteRecvBuffer, 0, bytesRead, 0, _localEP, new AsyncCallback(localSendCallback), null);
         }
         else
         {
             this.Close();
         }
     }
     catch (Exception e)
     {
         Logging.LogUsefulException(e);
         this.Close();
     }
 }
コード例 #6
0
 private void remoteReceiveCallback(IAsyncResult ar)
 {
     if (_closed)
     {
         return;
     }
     try
     {
         int bytesRead = _remote.EndReceive(ar);
         if (bytesRead > 0)
         {
             _relay.onInbound(bytesRead);
             _local.BeginSendTo(remoteRecvBuffer, 0, bytesRead, 0, _localEP, new AsyncCallback(localSendCallback), null);
             Delay();
         }
         else
         {
             this.Close();
         }
         Delay();
     }
     catch (Exception e)
     {
         _relay.onError(e);
         this.Close();
     }
 }