From 9851ee0b334ad1159aa893a39e59e2813c8ccf44 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=A9=20van=20Geldorp?= Date: Fri, 23 Dec 2005 20:46:48 +0000 Subject: [PATCH] Send delayed ACKs after 200ms instead of 2500ms svn path=/trunk/; revision=20315 --- reactos/drivers/lib/ip/transport/tcp/tcp.c | 79 +++++++++++++++++-- .../drivers/lib/oskittcp/include/oskittcp.h | 2 +- .../drivers/lib/oskittcp/oskittcp/interface.c | 10 ++- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/reactos/drivers/lib/ip/transport/tcp/tcp.c b/reactos/drivers/lib/ip/transport/tcp/tcp.c index 324a0fdec5b..1f7961660e6 100644 --- a/reactos/drivers/lib/ip/transport/tcp/tcp.c +++ b/reactos/drivers/lib/ip/transport/tcp/tcp.c @@ -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 ) { diff --git a/reactos/drivers/lib/oskittcp/include/oskittcp.h b/reactos/drivers/lib/oskittcp/include/oskittcp.h index 50ca3282222..d00535ef1ab 100644 --- a/reactos/drivers/lib/oskittcp/include/oskittcp.h +++ b/reactos/drivers/lib/oskittcp/include/oskittcp.h @@ -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, diff --git a/reactos/drivers/lib/oskittcp/oskittcp/interface.c b/reactos/drivers/lib/oskittcp/oskittcp/interface.c index 2b0512ceb3d..5da5c2244ca 100644 --- a/reactos/drivers/lib/oskittcp/oskittcp/interface.c +++ b/reactos/drivers/lib/oskittcp/oskittcp/interface.c @@ -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 ) { -- 2.17.1