Ejemplo n.º 1
0
        private void SendHeartbeat(string remoteIp, int remotePort)
        {
            lock (_hbMutex)
            {
                if (_hbMutex.IsHeld())
                {
                    //Logger.Info(string.Format("TunnelId={0} TunnelName={1} Message=\"Heartbeat has already been sent to {2}:{3} in the last {4} seconds. Aborting.\"", GetId(), FriendlyName, remoteIp, remotePort, HeartbeatTimeout / 1000));
                    return;
                }
                Logger.Info(string.Format("TunnelId={0} TunnelName={1} Message=\"Locking available mutex to send heartbeat to remote client {2}:{3}\"", GetId(), FriendlyName, remoteIp, remotePort));
                _hbMutex.Hold();
            }

            var tmpBuffer = Buffer.New();

            Buffer.ClearBuffer(tmpBuffer);
            Buffer.FinalizeBuffer(tmpBuffer);
            SockLib.SendMessage(_socket, remoteIp, remotePort, tmpBuffer);
            Thread.Sleep(HeartbeatTimeout);

            lock (_hbMutex)
            {
                Logger.Info(string.Format("TunnelId={0} TunnelName={1} Message=\"Releasing mutex for heartbeat\"", GetId(), FriendlyName));
                _hbMutex.Release();
            }
        }
Ejemplo n.º 2
0
        private void TunnelSendThread(string remoteIp, int remotePort)
        {
            while (true)
            {
                var message = DequeueMessage();
                if (message == null)
                {
                    new Thread(() => SendHeartbeat(remoteIp, remotePort)).Run();
                    continue;
                }

                Buffer.ClearBuffer(_sendBuffer);
                Buffer.Add(_sendBuffer, message);
                Buffer.FinalizeBuffer(_sendBuffer);
                SockLib.SendMessage(_socket, remoteIp, remotePort, _sendBuffer);
            }
        }