Example #1
0
        public bool TryDequeueRequest(ChannelDispatcher channel, TimeSpan timeout, out HttpContextInfo context)
        {
            DateTime start = DateTime.UtcNow;

            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.UtcNow - start), out context));                     // recurse, am lazy :/
                }
                context = q.Dequeue();
                return(true);
            }
        }
		internal static int CompareEntries (HttpChannelListenerEntry e1, HttpChannelListenerEntry e2)
		{
			if (e1.ChannelDispatcher.Endpoints.Count == 0)
				return 1;
			if (e2.ChannelDispatcher.Endpoints.Count == 0)
				return -1;
			// select the highest filter priority value in the Endpoints.
			int p1 = e1.ChannelDispatcher.Endpoints.OrderByDescending (e => e.FilterPriority).First ().FilterPriority;
			int p2 = e2.ChannelDispatcher.Endpoints.OrderByDescending (e => e.FilterPriority).First ().FilterPriority;
			// then return the channel dispatcher with higher priority first.
			return p2 - p1;
		}
        internal static int CompareEntries(HttpChannelListenerEntry e1, HttpChannelListenerEntry e2)
        {
            if (e1.ChannelDispatcher.Endpoints.Count == 0)
            {
                return(1);
            }
            if (e2.ChannelDispatcher.Endpoints.Count == 0)
            {
                return(-1);
            }
            // select the highest filter priority value in the Endpoints.
            int p1 = e1.ChannelDispatcher.Endpoints.OrderByDescending(e => e.FilterPriority).First().FilterPriority;
            int p2 = e2.ChannelDispatcher.Endpoints.OrderByDescending(e => e.FilterPriority).First().FilterPriority;

            // then return the channel dispatcher with higher priority first.
            return(p2 - p1);
        }