/// <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)); }
internal TdsRequest(TdsListenerContext wr, TdsContext context) { _wr = wr; _context = context; }
private bool CheckClientConnected(TdsListenerContext wr) { return ((DateTime.UtcNow - wr.GetStartTime()) > _clientConnectedTime ? wr.IsClientConnected() : true); }
private void QueueRequest(TdsListenerContext wr, bool isLocal) { lock (this) { if (isLocal) _localQueue.Enqueue(wr); else _externQueue.Enqueue(wr); _count++; } }
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()); }
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; }