#if !defined __ntp_iocompletionport_h
# define __ntp_iocompletionport_h
+#include "ntp_fp.h"
#include "ntp.h"
# if defined(HAVE_IO_COMPLETION_PORT)
extern HANDLE get_io_event (void);
+extern HANDLE get_exit_event(void); /* Handle of the exit event */
+
int GetReceivedBuffers(void);
# endif
static HANDLE hIoCompletionPort = NULL;
static HANDLE WaitableIoEventHandle = NULL;
+static HANDLE WaitableExitEventHandle = NULL;
#define MAXHANDLES 3
HANDLE WaitHandles[MAXHANDLES] = { NULL, NULL, NULL };
{
return( WaitableIoEventHandle );
}
+HANDLE
+get_exit_event()
+{
+ return( WaitableExitEventHandle );
+}
/* This function will add an entry to the I/O completion port
* that will signal the I/O thread to exit (gracefully)
"Can't create I/O event handle: %m - another process may be running - EXITING");
exit(1);
}
+ /* Create the event used to signal an exit event
+ */
+ WaitableExitEventHandle = CreateEvent(NULL, FALSE, FALSE, "WaitableExitEventHandle");
+ if (WaitableExitEventHandle == NULL) {
+ msyslog(LOG_ERR,
+ "Can't create exit event handle: %m - another process may be running - EXITING");
+ exit(1);
+ }
/* Create the IO completion port
*/
* Initialize the Wait Handles
*/
WaitHandles[0] = get_io_event();
- WaitHandles[1] = CreateEvent(NULL, FALSE, FALSE, "WaitHandles0"); /* exit request */
+ WaitHandles[1] = get_exit_event(); /* exit request */
WaitHandles[2] = get_timer_handle();
/* Have one thread servicing I/O - there were 4, but this would
#include "syslog.h"
#include "ntservice.h"
#include "clockstuff.h"
+#include "ntp_iocompletionport.h"
#ifdef DEBUG
#include <crtdbg.h>
#endif
static int glb_argc;
static char **glb_argv;
HANDLE hServDoneEvent = NULL;
-extern HANDLE WaitHandles[3];
extern volatile int debug;
extern char *progname;
void
ServiceControl(DWORD dwCtrlCode) {
/* Handle the requested control code */
+ HANDLE exitEvent = get_exit_event();
+
switch(dwCtrlCode) {
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
UpdateSCM(SERVICE_STOP_PENDING);
- if (WaitHandles[0] != NULL) {
- SetEvent(WaitHandles[0]);
+ if (exitEvent != NULL) {
+ SetEvent(exitEvent);
Sleep( 100 ); //##++
}
return;
DWORD dwCtrlType
)
{
+ HANDLE exitEvent = get_exit_event();
+
switch (dwCtrlType) {
#ifdef DEBUG
case CTRL_BREAK_EVENT :
case CTRL_C_EVENT :
case CTRL_CLOSE_EVENT :
case CTRL_SHUTDOWN_EVENT :
- if (WaitHandles[0] != NULL) {
- SetEvent(WaitHandles[0]);
+ if (exitEvent != NULL) {
+ SetEvent(exitEvent);
Sleep( 100 ); //##++
}
break;