--- trunk/reactos/drivers/lib/ip/transport/tcp/tcp.c 2005-12-23 20:44:39 UTC (rev 20314)
+++ trunk/reactos/drivers/lib/ip/transport/tcp/tcp.c 2005-12-23 20:46:48 UTC (rev 20315)
@@ -307,6 +307,68 @@
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 @@
TAG('T','C','P','S'), /* Tag */
0); /* Depth */
+ StartTimer();
+
TCPInitialized = TRUE;
return STATUS_SUCCESS;
@@ -349,9 +413,16 @@
* 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 @@
}
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 ) {
--- trunk/reactos/drivers/lib/oskittcp/include/oskittcp.h 2005-12-23 20:44:39 UTC (rev 20314)
+++ trunk/reactos/drivers/lib/oskittcp/include/oskittcp.h 2005-12-23 20:46:48 UTC (rev 20315)
@@ -105,7 +105,7 @@
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,
--- trunk/reactos/drivers/lib/oskittcp/oskittcp/interface.c 2005-12-23 20:44:39 UTC (rev 20314)
+++ trunk/reactos/drivers/lib/oskittcp/oskittcp/interface.c 2005-12-23 20:46:48 UTC (rev 20315)
@@ -66,9 +66,13 @@
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 ) {