protected void BeginSendToServer(int length, AsyncSession session, AsyncCallback callback) { if (!_serverHeaderSent) { _serverHeaderSent = true; // Append socks5 header int len = Socks5Util.HeaderAddrLength(_destEndPoint); Array.Copy(ConnetionRecvBuffer, 0, ConnetionRecvBuffer, len, length); Socks5Util.FillHeaderAddr(ConnetionRecvBuffer, 0, _destEndPoint); length += len; } _totalWrite += length; int bytesToSend; lock (_encryptionLock) { _encryptor.Encrypt(ConnetionRecvBuffer, length, _connetionSendBuffer, out bytesToSend); } _tcprelay.UpdateOutboundCounter(_server, bytesToSend); _startSendingTime = DateTime.Now; session.Remote.BeginSend(_connetionSendBuffer, 0, bytesToSend, SocketFlags.None, callback, session); IStrategy strategy = _controller.GetCurrentStrategy(); strategy?.UpdateLastWrite(_server); }
private void SendToServer(int length, AsyncSession session) { _totalWrite += length; int bytesToSend; lock (_encryptionLock) { try { _encryptor.Encrypt(_connetionRecvBuffer, length, _connetionSendBuffer, out bytesToSend); } catch (CryptoErrorException) { Logging.Debug("encryption error"); Close(); return; } } _tcpRelay.UpdateOutboundCounter(_server, bytesToSend); _startSendingTime = DateTime.Now; session.Remote.BeginSend(_connetionSendBuffer, 0, bytesToSend, SocketFlags.None, PipeRemoteSendCallback, new object[] { session, bytesToSend }); IStrategy strategy = _controller.GetCurrentStrategy(); strategy?.UpdateLastWrite(_server); }