]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/server/util.[ch]: add exit event to stop waiting on Windows
authorMarc Hoersken <info@marc-hoersken.de>
Sat, 18 Apr 2020 19:51:19 +0000 (21:51 +0200)
committerMarc Hoersken <info@marc-hoersken.de>
Sat, 2 May 2020 15:29:52 +0000 (17:29 +0200)
This commit adds a global exit event to the test servers that
Windows-specific wait routines can use to get triggered if the
program was signaled to be terminated, eg. select_ws in sockfilt.c

The exit event will be managed by the signal handling code and is
set to not reset automatically to support multiple wait routines.

Reviewed-by: Jay Satiro
Closes #5260

tests/server/util.c
tests/server/util.h

index 68889c0dc81522b46e24415cca23cc3c5c07111c..75f3cb1b66339a3cb1fa123c9c049bdffc69ff1a 100644 (file)
@@ -580,6 +580,11 @@ volatile int got_exit_signal = 0;
 /* if next is set indicates the first signal handled in exit_signal_handler */
 volatile int exit_signal = 0;
 
+#ifdef WIN32
+/* event which if set indicates that the program should finish */
+HANDLE exit_event = NULL;
+#endif
+
 /* signal handler that will be triggered to indicate that the program
  * should finish its execution in a controlled manner as soon as possible.
  * The first time this is called it will set got_exit_signal to one and
@@ -592,6 +597,10 @@ static RETSIGTYPE exit_signal_handler(int signum)
   if(got_exit_signal == 0) {
     got_exit_signal = 1;
     exit_signal = signum;
+#ifdef WIN32
+    if(exit_event)
+      (void)SetEvent(exit_event);
+#endif
   }
   (void)signal(signum, exit_signal_handler);
   errno = old_errno;
@@ -712,6 +721,12 @@ static DWORD WINAPI main_window_loop(LPVOID lpParameter)
 
 void install_signal_handlers(bool keep_sigalrm)
 {
+#ifdef WIN32
+  /* setup windows exit event before any signal can trigger */
+  exit_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+  if(!exit_event)
+    logmsg("cannot create exit event");
+#endif
 #ifdef SIGHUP
   /* ignore SIGHUP signal */
   old_sighup_handler = signal(SIGHUP, SIG_IGN);
@@ -812,6 +827,10 @@ void restore_signal_handlers(bool keep_sigalrm)
       }
     }
   }
+  if(exit_event) {
+    if(CloseHandle(exit_event)) {
+      exit_event = NULL;
+    }
   }
 #endif
 }
index 73f5f45f6a5b2937d8dfa63b72fb82028055ae62..b64c1d5a7bdf9eb62db03fcd13765eb1471d6d20 100644 (file)
@@ -70,6 +70,11 @@ extern volatile int got_exit_signal;
 /* global variable which if set indicates the first signal handled */
 extern volatile int exit_signal;
 
+#ifdef WIN32
+/* global event which if set indicates that the program should finish */
+extern HANDLE exit_event;
+#endif
+
 void install_signal_handlers(bool keep_sigalrm);
 void restore_signal_handlers(bool keep_sigalrm);