]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Add support for waiting on an IO event under Windows NT. This improves the responsiveness
authorWink Saville <wink@saville.com>
Sat, 20 Oct 2001 19:07:53 +0000 (12:07 -0700)
committerWink Saville <wink@saville.com>
Sat, 20 Oct 2001 19:07:53 +0000 (12:07 -0700)
of the system when running under NT.

bk: 3bd1cb8920OtypIF_HLw0aYriT2_Jg

ntpd/ntpd.c
ports/winnt/include/ntp_iocompletionport.h
ports/winnt/ntpd/ntp_iocompletionport.c

index b5f546bbf82a0a28ce74a1cdbbdb5b3b95c9cf64..1b80560c625d61b6c2048c4e6e7090c62d5927d3 100644 (file)
@@ -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 :
index 4cfdfa5c56294208c9ae8879046881d6259792ac..53345b32d7a336f4df446cc9ed6fe9cfa519fb5d 100644 (file)
@@ -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 * );
index 2627b7cccf37c6408c51b4dada17eaf2ad0831db..7ceda6ad2868747022ac840dda2e2271255f1457 100644 (file)
 
 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);