Esempio n. 1
0
 private void PipeRemoteReceiveCallback(IAsyncResult ar)
 {
     if (_closed)
     {
         return;
     }
     try
     {
         if (remote == null)
         {
             return;
         }
         int bytesRead = remote.EndReceive(ar);
         _totalRead += bytesRead;
         _tcprelay.UpdateInboundCounter(server, bytesRead);
         if (bytesRead > 0)
         {
             lastActivity = DateTime.Now;
             int bytesToSend;
             lock (_decryptionLock)
             {
                 if (_closed)
                 {
                     return;
                 }
                 encryptor.Decrypt(_remoteRecvBuffer, bytesRead, _remoteSendBuffer, out bytesToSend);
             }
             connection.BeginSend(_remoteSendBuffer, 0, bytesToSend, SocketFlags.None, new AsyncCallback(PipeConnectionSendCallback), null);
             IStrategy strategy = controller.GetCurrentStrategy();
             strategy?.UpdateLastRead(server);
         }
         else
         {
             connection.Shutdown(SocketShutdown.Send);
             _connectionShutdown = true;
             CheckClose();
         }
     }
     catch (Exception e)
     {
         Logging.LogUsefulException(e);
         Close();
     }
 }