From: Wink Saville Date: Sat, 20 Oct 2001 19:07:53 +0000 (-0700) Subject: Add support for waiting on an IO event under Windows NT. This improves the responsiveness X-Git-Tag: NTP_4_1_0B_RC1~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8bc0295d43ee57eb54fe53bf571426f332ac0f97;p=thirdparty%2Fntp.git Add support for waiting on an IO event under Windows NT. This improves the responsiveness of the system when running under NT. bk: 3bd1cb8920OtypIF_HLw0aYriT2_Jg --- diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index b5f546bbf8..1b80560c62 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -125,7 +125,7 @@ HANDLE ResolverThreadHandle = NULL; /* variables used to inform the Service Control Manager of our current state */ SERVICE_STATUS ssStatus; SERVICE_STATUS_HANDLE sshStatusHandle; -HANDLE WaitHandles[2] = { NULL, NULL }; +HANDLE WaitHandles[3] = { NULL, NULL, NULL }; char szMsgPath[255]; static BOOL WINAPI OnConsoleEvent(DWORD dwCtrlType); #endif /* SYS_WINNT */ @@ -797,6 +797,7 @@ service_main( #if defined(HAVE_IO_COMPLETION_PORT) WaitHandles[0] = CreateEvent(NULL, FALSE, FALSE, NULL); /* exit reques */ WaitHandles[1] = get_timer_handle(); + WaitHandles[2] = get_io_event(); for (;;) { DWORD Index = WaitForMultipleObjectsEx(sizeof(WaitHandles)/sizeof(WaitHandles[0]), WaitHandles, FALSE, 1000, MWMO_ALERTABLE); @@ -808,16 +809,36 @@ service_main( case WAIT_OBJECT_0 + 1 : /* timer */ timer(); break; - case WAIT_OBJECT_0 + 2 : { /* Windows message */ + + case WAIT_OBJECT_0 + 2 : /* Io event */ +# ifdef DEBUG + if ( debug > 3 ) + { + printf( "IoEvent occurred\n" ); + } +# endif + break; + +# if 1 + /* + * FIXME: According to the documentation for WaitForMultipleObjectsEx + * this is not possible. This may be a vestigial from when this was + * MsgWaitForMultipleObjects, maybe it should be removed? + */ + case WAIT_OBJECT_0 + 3 : /* windows message */ + { MSG msg; - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - if (msg.message == WM_QUIT) { - exit(0); + while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) + { + if ( msg.message == WM_QUIT ) + { + exit( 0 ); } - DispatchMessage(&msg); + DispatchMessage( &msg ); } } break; +# endif case WAIT_IO_COMPLETION : /* loop */ case WAIT_TIMEOUT : diff --git a/ports/winnt/include/ntp_iocompletionport.h b/ports/winnt/include/ntp_iocompletionport.h index 4cfdfa5c56..53345b32d7 100644 --- a/ports/winnt/include/ntp_iocompletionport.h +++ b/ports/winnt/include/ntp_iocompletionport.h @@ -24,6 +24,8 @@ extern void io_completion_port_add_socket (struct interface *); extern DWORD io_completion_port_sendto (struct interface *, struct pkt *, int, struct sockaddr_in*); +extern HANDLE get_io_event (void); + static int OnSocketRecv(DWORD, struct IoCompletionInfo *, DWORD); static int QueueIORead( struct refclockio * ); diff --git a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c index 2627b7cccf..7ceda6ad28 100644 --- a/ports/winnt/ntpd/ntp_iocompletionport.c +++ b/ports/winnt/ntpd/ntp_iocompletionport.c @@ -20,6 +20,15 @@ static HANDLE hIoCompletionPort = NULL; +static HANDLE WaitableIoEventHandle = NULL; + +HANDLE +get_io_event() +{ + return( WaitableIoEventHandle ); +} + + static int OnExitRequest(DWORD Key, struct IoCompletionInfo *Info, DWORD Bytes) { @@ -82,6 +91,16 @@ init_io_completion_port( void ) { + /* Create the event used to signal an IO event + */ + WaitableIoEventHandle = CreateEvent(NULL, FALSE, FALSE, NULL); + if (WaitableIoEventHandle == NULL) { + msyslog(LOG_ERR, "Can't create I/O event handle: %m"); + exit(1); + } + + /* Create the IO completion port + */ hIoCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); if (hIoCompletionPort == NULL) { msyslog(LOG_ERR, "Can't create I/O completion port: %m"); @@ -156,6 +175,13 @@ OnIoReadComplete(DWORD i, struct IoCompletionInfo *Info, DWORD Bytes) buff->dstadr = NULL; buff->recv_srcclock = rio->srcclock; add_full_recv_buffer(buff); + if( !SetEvent( WaitableIoEventHandle ) ) { +#ifdef DEBUG + if (debug > 3) { + printf( "Error %d setting IoEventHandle\n", GetLastError() ); + } +#endif + } buff = NULL; } else @@ -256,6 +282,13 @@ OnSocketRecv(DWORD i, struct IoCompletionInfo *Info, DWORD Bytes) } #endif add_full_recv_buffer(buff); + if( !SetEvent( WaitableIoEventHandle ) ) { +#ifdef DEBUG + if (debug > 3) { + printf( "Error %d setting IoEventHandle\n", GetLastError() ); + } +#endif + } } else { freerecvbuf(buff);