コード例 #1
0
 internal void DeactivateCometWaitRequest(CometWaitRequest request)
 {
     lock (state)
     {
         request.DateDeactivated = DateTime.Now;
     }
 }
コード例 #2
0
 internal void QueueCometWaitRequest(CometWaitRequest request)
 {
     lock (state)
     {
         WaitRequests.Add(request);
     }
 }
コード例 #3
0
 private CometMessage[] CheckForServerPushMessages(CometWaitRequest request)
 {
     //
     //  ok, we we need to do is get the messages
     //  that are stored in the state provider
     return(StateManager.StateProvider.GetMessages(request.ClientPrivateToken, request.LastMessageId));
 }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="callback"></param>
        /// <param name="extraData"></param>
        /// <returns></returns>
        public IAsyncResult BeginSubscribe(HttpContext context, AsyncCallback callback, object extraData)
        {
            try
            {
                long   lastMessageId;
                string privateToken = string.Empty;

                if (!long.TryParse(context.Request["lastMessageId"] ?? "-1", out lastMessageId))
                {
                    throw CometException.CometHandlerParametersAreInvalidException();
                }

                privateToken = context.Request["privateToken"];
                if (string.IsNullOrEmpty(privateToken))
                {
                    throw CometException.CometHandlerParametersAreInvalidException();
                }


                this.DebugWriteThreadInfo("BeginSubscribe");

                lock (state)
                {
                    Debug.WriteLine("目前有几个客户端连接" + this.GetCometClients());

                    CometClient cometClient = this.GetCometClient(privateToken);
                    this.FireClientSubscribed(cometClient);
                    // 从所有线程的请求队列中找到该CometClient,将其排除
                    for (int i = 0; i < this.workerThreadCount; i++)
                    {
                        this.workerThreads[i].DequeueCometWaitRequest(privateToken);
                    }

                    CometWaitRequest request = new CometWaitRequest(privateToken, lastMessageId, context, callback, extraData);

                    this.workerThreads[this.currentThread].QueueCometWaitRequest(request);
                    this.currentThread++;

                    if (this.currentThread >= this.workerThreadCount)
                    {
                        this.currentThread = 0;
                    }

                    return(request.Result);
                }
            }
            catch (Exception ex)
            {
                this.WriteErrorToResponse(context, ex.Message);
                return(null);
            }
        }
コード例 #5
0
 private void CheckForIdleCometWaitRequest(CometWaitRequest request, CometClient cometClient)
 {
     lock (state)
     {
         if (DateTime.Now.Subtract(request.DateDeactivated.Value).TotalSeconds >= cometClient.ConnectionIdleSeconds)
         {
             //  ok, this dude has timed out, so we remove it
             StateManager.KillIdleCometClient(cometClient.PrivateToken);
             //  and deque the request
             WaitRequests.Remove(request);
         }
     }
 }
コード例 #6
0
        internal void DequeueCometWaitRequest(string privateToken)
        {
            lock (state)
            {
                for (int i = 0; i < WaitRequests.Count; i++)
                {
                    CometWaitRequest request = WaitRequests[i];

                    if (request.ClientPrivateToken == privateToken)
                    {
                        WaitRequests.Remove(request);
                        break;
                    }
                }
            }
        }
コード例 #7
0
        private void QueueCometWaitRequest_Finished(object target)
        {
            CometWaitRequest request = target as CometWaitRequest;

            request.Result.SetCompleted();
        }