Send delayed ACKs after 200ms instead of 2500ms
authorGé van Geldorp <ge@gse.nl>
Fri, 23 Dec 2005 20:46:48 +0000 (20:46 +0000)
committerGé van Geldorp <ge@gse.nl>
Fri, 23 Dec 2005 20:46:48 +0000 (20:46 +0000)
svn path=/trunk/; revision=20315

reactos/drivers/lib/ip/transport/tcp/tcp.c
reactos/drivers/lib/oskittcp/include/oskittcp.h
reactos/drivers/lib/oskittcp/oskittcp/interface.c

index 324a0fd..1f79616 100644 (file)
@@ -307,6 +307,68 @@ OSKITTCP_EVENT_HANDLERS EventHandlers = {
     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
@@ -336,6 +398,8 @@ NTSTATUS TCPStartup(VOID)
        TAG('T','C','P','S'),           /* Tag */
        0);                             /* Depth */
 
+    StartTimer();
+
     TCPInitialized = TRUE;
 
     return STATUS_SUCCESS;
@@ -349,9 +413,16 @@ NTSTATUS TCPShutdown(VOID)
  *     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);
 
@@ -598,13 +669,7 @@ NTSTATUS TCPSendData
 }
 
 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 ) {
index 50ca328..d00535e 100644 (file)
@@ -105,7 +105,7 @@ extern OSKITTCP_EVENT_HANDLERS OtcpEvent;
 
 extern void InitOskitTCP();
 extern void DeinitOskitTCP();
-extern void TimerOskitTCP();
+extern void TimerOskitTCP( int FastTimer, int SlowTimer );
 extern void OskitDumpBuffer( OSK_PCHAR Data, OSK_UINT Len );
 extern int  OskitTCPShutdown( void *socket, int disconn_type );
 extern int  OskitTCPSocket( void *Connection, void **ConnectionContext,
index 2b0512c..5da5c22 100644 (file)
@@ -66,9 +66,13 @@ void InitOskitTCP() {
 void DeinitOskitTCP() {
 }
 
-void TimerOskitTCP() {
-    tcp_slowtimo();
-    tcp_fasttimo();
+void TimerOskitTCP( int FastTimer, int SlowTimer ) {
+    if ( SlowTimer ) {
+        tcp_slowtimo();
+    }
+    if ( FastTimer ) {
+        tcp_fasttimo();
+    }
 }
 
 void RegisterOskitTCPEventHandlers( POSKITTCP_EVENT_HANDLERS EventHandlers ) {