Exemplo n.º 1
0
 static Hub()
 {
     HeartbeatEvent = new HeartbeatEvent { _Transform = false };
     // Initialize the singleton instance.
     Instance = new Hub();
 }
Exemplo n.º 2
0
        private void OnHeartbeatEvent(HeartbeatEvent e)
        {
            if (!IncomingKeepaliveEnabled && !OutgoingKeepaliveEnabled)
            {
                return;
            }

            List<LinkSession> snapshot;
            using (new ReadLock(rwlock))
            {
                snapshot = new List<LinkSession>(sessions.Count);
                var list = sessions.Values;
                for (int i = 0, count = list.Count; i < count; ++i)
                {
                    snapshot.Add(list[i]);
                }
            }
            for (int i = 0, count = snapshot.Count; i < count; ++i)
            {
                var tcpSession = (AbstractTcpSession)snapshot[i];
                if (tcpSession.SocketConnected)
                {
                    int failureCount = tcpSession.Keepalive(
                        incomingKeepaliveEnabled, outgoingKeepaliveEnabled);

                    if (MaxKeepaliveFailureCount > 0 &&
                        failureCount > MaxKeepaliveFailureCount)
                    {
                        Log.Warn("{0} {1} closed due to the keepalive failure",
                            Name, tcpSession.Handle);

                        tcpSession.OnDisconnect();
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void OnHeartbeatEvent(HeartbeatEvent e)
        {
            if (!IncomingKeepaliveEnabled && !OutgoingKeepaliveEnabled)
            {
                return;
            }

            var tcpSession = (AbstractTcpSession)Session;
            if (tcpSession == null || !tcpSession.SocketConnected)
            {
                return;
            }

            int failureCount = tcpSession.Keepalive(
                incomingKeepaliveEnabled, outgoingKeepaliveEnabled);

            if (MaxKeepaliveFailureCount > 0 &&
                failureCount > MaxKeepaliveFailureCount)
            {
                Log.Warn("{0} {1} closed due to the keepalive failure",
                    Name, tcpSession.Handle);

                tcpSession.OnDisconnect();
            }
        }