コード例 #1
0
        internal static int CompareEntries(HttpChannelListenerEntry e1, HttpChannelListenerEntry e2)
        {
            if (e1.ChannelDispatcher.Endpoints.Count == 0)
            {
                return(1);
            }
            if (e2.ChannelDispatcher.Endpoints.Count == 0)
            {
                return(-1);
            }
            int p1 = e1.ChannelDispatcher.Endpoints.OrderByDescending(e => e.FilterPriority).First().FilterPriority;
            int p2 = e2.ChannelDispatcher.Endpoints.OrderByDescending(e => e.FilterPriority).First().FilterPriority;

            return(p2 - p1);
        }
コード例 #2
0
        public bool TryDequeueRequest(ChannelDispatcher channel, TimeSpan timeout, out HttpContextInfo context)
        {
            DateTime start = DateTime.Now;

            context = null;
            HttpChannelListenerEntry ce = null;

            lock (entries_lock)
            {
                ce = Entries.FirstOrDefault(e => e.ChannelDispatcher == channel);
            }
            if (ce == null)
            {
                return(false);
            }
            lock (ce.RetrieverLock)
            {
                var q = ce.ContextQueue;
                if (q.Count == 0)
                {
                    if (timeout.TotalMilliseconds < 0)
                    {
                        return(false);
                    }
                    TimeSpan waitTimeout = timeout;
                    if (timeout == TimeSpan.MaxValue)
                    {
                        waitTimeout = TimeSpan.FromMilliseconds(int.MaxValue);
                    }
                    bool ret = ce.WaitHandle.WaitOne(waitTimeout);
                    return(ret && TryDequeueRequest(channel, waitTimeout - (DateTime.Now - start), out context));
                }
                context = q.Dequeue();
                return(true);
            }
        }