static const long WRITE_EVENTS = FD_WRITE | FD_CONNECT;
static DWORD event_count = 0;
#endif
-static volatile bool running;
+static bool running;
static int io_compare(const io_t *a, const io_t *b) {
#ifndef HAVE_MINGW
return true;
}
+static io_t stop_io;
+
DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
switch(request) {
case SERVICE_CONTROL_INTERROGATE:
return ERROR_CALL_NOT_IMPLEMENTED;
}
- event_exit();
- status.dwWaitHint = 30000;
+ status.dwWaitHint = 1000;
status.dwCurrentState = SERVICE_STOP_PENDING;
SetServiceStatus(statushandle, &status);
+ if (WSASetEvent(stop_io.event) == FALSE)
+ abort();
return NO_ERROR;
}
+static void stop_handler(void *data, int flags) {
+ event_exit();
+}
+
VOID WINAPI run_service(DWORD argc, LPTSTR* argv) {
extern int main2(int argc, char **argv);
+ io_add_event(&stop_io, stop_handler, NULL, WSACreateEvent());
+ if (stop_io.event == FALSE)
+ abort();
+
status.dwServiceType = SERVICE_WIN32;
status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
status.dwWin32ExitCode = 0;
SetServiceStatus(statushandle, &status);
}
+ if (WSACloseEvent(stop_io.event) == FALSE)
+ abort();
+ io_del(&stop_io);
return;
}