示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TdsContext"/> class.
        /// </summary>
        /// <param name="wr">The wr.</param>
        public TdsContext(TdsListenerContext wr)
        {
            _timeoutStartTimeUtcTicks = -1L;
            _timeoutTicks = -1L;
            _threadAbortOnTimeout = true;
            ThreadContextId = new object();
            _wr = wr;
            Init(new TdsRequest(wr, this));

        }
示例#2
0
 internal TdsRequest(TdsListenerContext wr, TdsContext context)
 {
     _wr = wr;
     _context = context;
 }
示例#3
0
 private bool CheckClientConnected(TdsListenerContext wr)
 {
     return ((DateTime.UtcNow - wr.GetStartTime()) > _clientConnectedTime ? wr.IsClientConnected() : true);
 }
示例#4
0
 private void QueueRequest(TdsListenerContext wr, bool isLocal)
 {
     lock (this)
     {
         if (isLocal)
             _localQueue.Enqueue(wr);
         else
             _externQueue.Enqueue(wr);
         _count++;
     }
 }
示例#5
0
 private static bool IsLocal(TdsListenerContext wr)
 {
     var remoteAddress = wr.GetRemoteAddress();
     switch (remoteAddress)
     {
         case "127.0.0.1":
         case "::1":
             return true;
     }
     if (string.IsNullOrEmpty(remoteAddress))
         return false;
     return (remoteAddress == wr.GetLocalAddress());
 }
示例#6
0
 internal TdsListenerContext GetRequestToExecute(TdsListenerContext wr)
 {
     int workerThreads;
     int completionPortThreads;
     ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
     var threads = (completionPortThreads > workerThreads ? workerThreads : completionPortThreads);
     if (threads < _minExternFreeThreads || _count != 0)
     {
         var isLocal = IsLocal(wr);
         if (isLocal && threads >= _minLocalFreeThreads && _count == 0)
             return wr;
         if (_count >= _queueLimit)
         {
             _runtime.RejectRequestNow(wr, false);
             return null;
         }
         QueueRequest(wr, isLocal);
         if (threads >= _minExternFreeThreads)
         {
             wr = DequeueRequest(false);
             return wr;
         }
         if (threads >= _minLocalFreeThreads)
         {
             wr = DequeueRequest(true);
             return wr;
         }
         wr = null;
         ScheduleMoreWorkIfNeeded();
     }
     return wr;
 }