]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sockfilt: make select_ws stop waiting on exit signal event
authorMarc Hoersken <info@marc-hoersken.de>
Sat, 18 Apr 2020 19:54:40 +0000 (21:54 +0200)
committerMarc Hoersken <info@marc-hoersken.de>
Sat, 2 May 2020 15:30:54 +0000 (17:30 +0200)
This makes sure that select_ws behaves similar to real select
which stops waiting on a signal handler being triggered.

This makes it possible to gracefully stop sockfilt.exe on
Windows with taskkill /IM sockfilt.exe (without /F force flag).

Reviewed-by: Jay Satiro
Part of #5260

tests/server/sockfilt.c

index 84c72f96023b1b879bd5f1a4258e8d0581341bbe..7f0db92b462cbebc7bcb3f2193d6cfe41994f598 100644 (file)
@@ -676,7 +676,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
   }
 
   /* allocate internal array for the internal event handles */
-  handles = calloc(nfds, sizeof(HANDLE));
+  handles = calloc(nfds + 1, sizeof(HANDLE));
   if(handles == NULL) {
     CloseHandle(abort);
     CloseHandle(mutex);
@@ -785,8 +785,18 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
     }
   }
 
+  /* wait on the number of handles */
+  wait = nfd;
+
+  /* make sure we stop waiting on exit signal event */
+  if(exit_event) {
+    /* we allocated handles nfds + 1 for this */
+    handles[nfd] = exit_event;
+    wait += 1;
+  }
+
   /* wait for one of the internal handles to trigger */
-  wait = WaitForMultipleObjectsEx(nfd, handles, FALSE, timeout_ms, FALSE);
+  wait = WaitForMultipleObjectsEx(wait, handles, FALSE, timeout_ms, FALSE);
 
   /* wait for internal mutex to lock event handling in threads */
   WaitForSingleObjectEx(mutex, INFINITE, FALSE);