Пример #1
0
        protected void Timeout(SSContext context, long timeout, TimeoutCallback callback)
        {
            long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            if (timeout <= 0)
            {
                callback(context, timestamp);
            }
            else
            {
                if (m_totalServiceSession >= Int32.MaxValue)
                {
                    m_totalServiceSession = 0;
                }

                SSTimerNode timerNode = new SSTimerNode();
                timerNode.Opaque           = m_serviceAddress;
                timerNode.Session          = ++m_totalServiceSession;
                timerNode.TimeoutTimestamp = timestamp + timeout;

                SSTimer.GetInstance().Add(timerNode);

                TimeoutContext timeoutContext = new TimeoutContext();
                timeoutContext.Callback = callback;
                timeoutContext.Context  = context;
                m_timeoutCallbacks.Add(timerNode.Session, timeoutContext);
            }
        }
Пример #2
0
        protected virtual void OnTimer(Message msg)
        {
            TimeoutContext context = null;
            bool           isExist = m_timeoutCallbacks.TryGetValue(msg.RPCSession, out context);

            if (isExist)
            {
                long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                context.Callback(context.Context, timestamp);

                m_timeoutCallbacks.Remove(msg.RPCSession);
            }
        }