TCPWakeup /* Wakeup */
};
+static KEVENT TimerLoopEvent;
+static HANDLE TimerThreadHandle;
+
+/*
+ * We are running 2 timers here, one with a 200ms interval (fast) and the other
+ * with a 500ms interval (slow). So we need to time out at 200, 400, 500, 600,
+ * 800, 1000 and process the "fast" events at 200, 400, 600, 800, 1000 and the
+ * "slow" events at 500 and 1000.
+ */
+static VOID DDKAPI
+TimerThread(PVOID Context)
+{
+ LARGE_INTEGER Timeout;
+ NTSTATUS Status;
+ unsigned Current, NextFast, NextSlow, Next;
+
+ Current = 0;
+ Next = 0;
+ NextFast = 0;
+ NextSlow = 0;
+ while ( 1 ) {
+ if (Next == NextFast) {
+ NextFast += 2;
+ }
+ if (Next == NextSlow) {
+ NextSlow += 5;
+ }
+ Next = min(NextFast, NextSlow);
+ Timeout.QuadPart = (LONGLONG) (Next - Current) * -1000000; /* 100 ms */
+ Status = KeWaitForSingleObject(&TimerLoopEvent, Executive, KernelMode,
+ FALSE, &Timeout);
+ if (STATUS_SUCCESS == Status) {
+ PsTerminateSystemThread(STATUS_SUCCESS);
+ }
+ ASSERT(STATUS_TIMEOUT == Status);
+
+ TcpipRecursiveMutexEnter( &TCPLock, TRUE );
+ TimerOskitTCP( Next == NextFast, Next == NextSlow );
+ if (Next == NextSlow) {
+ DrainSignals();
+ }
+ TcpipRecursiveMutexLeave( &TCPLock );
+
+ Current = Next;
+ if (10 <= Current) {
+ Current = 0;
+ Next = 0;
+ NextFast = 0;
+ NextSlow = 0;
+ }
+ }
+}
+
+static VOID
+StartTimer(VOID)
+{
+ KeInitializeEvent(&TimerLoopEvent, NotificationEvent, FALSE);
+ PsCreateSystemThread(&TimerThreadHandle, THREAD_ALL_ACCESS, 0, 0, 0,
+ TimerThread, NULL);
+}
+
+
NTSTATUS TCPStartup(VOID)
/*
* FUNCTION: Initializes the TCP subsystem
TAG('T','C','P','S'), /* Tag */
0); /* Depth */
+ StartTimer();
+
TCPInitialized = TRUE;
return STATUS_SUCCESS;
* Status of operation
*/
{
+ LARGE_INTEGER WaitForThread;
+
if (!TCPInitialized)
return STATUS_SUCCESS;
+ WaitForThread.QuadPart = -2500000; /* 250 ms */
+ KeSetEvent(&TimerLoopEvent, IO_NO_INCREMENT, TRUE);
+ KeWaitForSingleObject(&TimerThreadHandle, Executive, KernelMode,
+ FALSE, &WaitForThread);
+
/* Deregister this protocol with IP layer */
IPRegisterProtocol(IPPROTO_TCP, NULL);
}
VOID TCPTimeout(VOID) {
- static int Times = 0;
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
- if( (Times++ % 5) == 0 ) {
- TimerOskitTCP();
- }
- DrainSignals();
- TcpipRecursiveMutexLeave( &TCPLock );
+ /* Now handled by TimerThread */
}
UINT TCPAllocatePort( UINT HintPort ) {
return STATUS_SUCCESS;
}
+VOID TCPRemoveIRP( PCONNECTION_ENDPOINT Endpoint, PIRP Irp ) {
+ PLIST_ENTRY Entry;
+ PLIST_ENTRY ListHead[4];
+ KIRQL OldIrql;
+ PTDI_BUCKET Bucket;
+ UINT i = 0;
+
+ ListHead[0] = &Endpoint->ReceiveRequest;
+ ListHead[1] = &Endpoint->ConnectRequest;
+ ListHead[2] = &Endpoint->ListenRequest;
+ ListHead[3] = 0;
+
+ TcpipAcquireSpinLock( &Endpoint->Lock, &OldIrql );
+
+ for( i = 0; ListHead[i]; i++ ) {
+ for( Entry = ListHead[i]->Flink;
+ Entry != ListHead[i];
+ Entry = Entry->Flink ) {
+ Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
+
+ if( Bucket->Request.RequestContext == Irp ) {
+ RemoveEntryList( &Bucket->Entry );
+ break;
+ }
+ }
+ }
+
+ TcpipReleaseSpinLock( &Endpoint->Lock, OldIrql );
+}
+
/* EOF */