public HttpBackend(IPAddress address, int port, int maxKeepAlives = 100, int backlog = 128, int sessionReadBufferSize = 4096, int sessionReadTimeoutMs = 5000, int sessionWriteTimeoutMs = 5000) { this.port = port; listener = new TcpListener(address, port); this.maxKeepAlives = maxKeepAlives; this.backlog = backlog; this.sessionReadBufferSize = sessionReadBufferSize; sessionReadTimeout = TimeSpan.FromMilliseconds(sessionReadTimeoutMs); sessionWriteTimeout = TimeSpan.FromMilliseconds(sessionWriteTimeoutMs); lifeCycleToken = new LifeCycleToken(); sessionTable = new ConcurrentDictionary <long, HttpSession>(); sessionReads = new ConcurrentDictionary <long, long>(); webSocketSessionTable = new ConcurrentDictionary <long, WebSocketSession>(); sessionExceptionCounters = new CountingDictionary <Type>(); name = $"{GetType().Name}({address}:{port})"; timer = new WaitableTimer(name, TimeSpan.FromSeconds(1), new [] { new WaitableTimer.Job(nameof(CheckSessionReadTimeouts), CheckSessionReadTimeouts) }); }
internal static extern bool SetWaitableTimerEx( [In] this WaitableTimer hTimer, [In] ref long lpDueTime, [In] int lPeriod, [In, Optional] IntPtr pfnCompletionRoutine, [In, Optional] IntPtr lpArgToCompletionRoutine, [In, Optional] IntPtr WakeContext, [In] uint TolerableDelay );
private void OnWaitCallback(object state) { WaitableTimer.WaitAny(waitableTimers); long now = Ticks.Now; lock (ThisLock) { waitScheduled = false; ScheduleElapsedTimers(now); ReactivateWaitableTimers(); ScheduleWaitIfAnyTimersLeft(); } }
static void UpdateWaitableTimer(TimerGroup timerGroup) { WaitableTimer waitableTimer = timerGroup.WaitableTimer; IOThreadTimer minTimer = timerGroup.TimerQueue.MinTimer; long timeDiff = waitableTimer.DueTime - minTimer.dueTime; if (timeDiff < 0) { timeDiff = -timeDiff; } if (timeDiff > minTimer.maxSkew) { waitableTimer.Set(minTimer.dueTime); } }
Router(RouteTable[] routeTables, int requestLogsSize, int timerPeriodMs) { this.routeTables = routeTables; rateLimitedEndpoints = routeTables.SelectMany(table => table.Where(ep => ep is RateLimitedEndpoint).Cast <RateLimitedEndpoint>()) .ToArray(); requestLogs = new RequestLogs(this, requestLogsSize); Metrics = new RouterMetrics(this); timer = new WaitableTimer("RouterTimer", TimeSpan.FromMilliseconds(timerPeriodMs), new [] { new WaitableTimer.Job("UpdateRateLimitBuckets", UpdateRateLimitBuckets), new WaitableTimer.Job("ProcessRequestLogs", ProcessRequestLogs) }); }
public Waiter(ElapsedTimeCounter counter, long intervalTicks, bool highResolution) { _counter = counter ?? throw new ArgumentNullException(nameof(counter)); if (intervalTicks < 0) { throw new ArgumentOutOfRangeException(nameof(intervalTicks)); } _intervalTicks = intervalTicks; _handle = NativeMethods.CreateWaitableTimerEx( IntPtr.Zero, IntPtr.Zero, WaitableTimer.FLAGS.MANUAL_RESET | (highResolution ? WaitableTimer.FLAGS.HIGH_RESOLUTION : 0), WaitableTimer.ACCESSES.SYNCHRONIZE | WaitableTimer.ACCESSES.TIMER_ALL_ACCESS ); if (_handle.IsInvalid) { throw new TimerException($"CreateWaitableTimerEx failed [{Marshal.GetLastWin32Error()}]"); } Reset(); }
public TimerGroup() { this.waitableTimer = new WaitableTimer(); this.waitableTimer.Set(long.MaxValue); this.timerQueue = new TimerQueue(); }
public TimerGroup() { waitableTimer = new WaitableTimer(); timerQueue = new TimerQueue(); }
public TimerGroup() { WaitableTimer = new WaitableTimer(); WaitableTimer.Set(long.MaxValue); TimerQueue = new TimerQueue(); }
internal static extern int WaitForSingleObject( [In] this WaitableTimer hTimer, [In] uint dwMilliseconds );