|
@@ -18,6 +18,8 @@
|
|
|
#include <string.h>
|
|
|
#ifndef _WIN32
|
|
|
#include <unistd.h>
|
|
|
+#else
|
|
|
+#include <windows.h> // Console close event handling
|
|
|
#endif
|
|
|
|
|
|
|
|
@@ -68,6 +70,35 @@ sigfunc *compat_signal(int signo, sigfunc *func)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+/*======================================
|
|
|
+ * CORE : Console events for Windows
|
|
|
+ *--------------------------------------*/
|
|
|
+#ifdef _WIN32
|
|
|
+static BOOL WINAPI console_handler(DWORD c_event)
|
|
|
+{
|
|
|
+ switch(c_event)
|
|
|
+ {
|
|
|
+ case CTRL_CLOSE_EVENT:
|
|
|
+ case CTRL_LOGOFF_EVENT:
|
|
|
+ case CTRL_SHUTDOWN_EVENT:
|
|
|
+ if( shutdown_callback != NULL )
|
|
|
+ shutdown_callback();
|
|
|
+ else
|
|
|
+ runflag = CORE_ST_STOP;// auto-shutdown
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+static void cevents_init()
|
|
|
+{
|
|
|
+ if (SetConsoleCtrlHandler(console_handler,TRUE)==FALSE)
|
|
|
+ ShowWarning ("Unable to install the console handler!\n");
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
/*======================================
|
|
|
* CORE : Signal Sub Function
|
|
|
*--------------------------------------*/
|
|
@@ -251,6 +282,10 @@ int main (int argc, char **argv)
|
|
|
db_init();
|
|
|
signals_init();
|
|
|
|
|
|
+#ifdef _WIN32
|
|
|
+ cevents_init();
|
|
|
+#endif
|
|
|
+
|
|
|
timer_init();
|
|
|
socket_init();
|
|
|
plugins_init();
|