コード例 #1
0
ファイル: Hub.cs プロジェクト: jaykang920/x2clr
 static Hub()
 {
     HeartbeatEvent = new HeartbeatEvent { _Transform = false };
     // Initialize the singleton instance.
     Instance = new Hub();
 }
コード例 #2
0
ファイル: AbstractTcpServer.cs プロジェクト: jaykang920/x2clr
        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();
                    }
                }
            }
        }
コード例 #3
0
ファイル: AbstractTcpClient.cs プロジェクト: jaykang920/x2clr
        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();
            }
        }