[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 169/264: tests/server: add CTRL event handler for Win32 consoles
From: |
gnunet |
Subject: |
[gnurl] 169/264: tests/server: add CTRL event handler for Win32 consoles |
Date: |
Thu, 30 Apr 2020 16:07:52 +0200 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit 30c8ef7d636ea060e690b4959280d05f2587d882
Author: Marc Hoersken <address@hidden>
AuthorDate: Sat Apr 11 23:31:55 2020 +0200
tests/server: add CTRL event handler for Win32 consoles
Forward CTRL events as signals to existing signal event handler.
---
tests/server/util.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/tests/server/util.c b/tests/server/util.c
index 5dd4e0a7f..c8bc32945 100644
--- a/tests/server/util.c
+++ b/tests/server/util.c
@@ -567,6 +567,47 @@ static RETSIGTYPE exit_signal_handler(int signum)
errno = old_errno;
}
+#ifdef WIN32
+/* CTRL event handler for Windows Console applications to simulate
+ * SIGINT, SIGTERM and SIGBREAK on CTRL events and trigger signal handler.
+ *
+ * Background information from MSDN:
+ * SIGINT is not supported for any Win32 application. When a CTRL+C
+ * interrupt occurs, Win32 operating systems generate a new thread
+ * to specifically handle that interrupt. This can cause a single-thread
+ * application, such as one in UNIX, to become multithreaded and cause
+ * unexpected behavior.
+ * [...]
+ * The SIGILL and SIGTERM signals are not generated under Windows.
+ * They are included for ANSI compatibility. Therefore, you can set
+ * signal handlers for these signals by using signal, and you can also
+ * explicitly generate these signals by calling raise. Source:
+ * https://docs.microsoft.com/de-de/cpp/c-runtime-library/reference/signal
+ */
+static BOOL WINAPI ctrl_event_handler(DWORD dwCtrlType)
+{
+ int signum = 0;
+ logmsg("ctrl_event_handler: %d", dwCtrlType);
+ switch(dwCtrlType) {
+#ifdef SIGINT
+ case CTRL_C_EVENT: signum = SIGINT; break;
+#endif
+#ifdef SIGTERM
+ case CTRL_CLOSE_EVENT: signum = SIGTERM; break;
+#endif
+#ifdef SIGBREAK
+ case CTRL_BREAK_EVENT: signum = SIGBREAK; break;
+#endif
+ default: return FALSE;
+ }
+ if(signum) {
+ logmsg("ctrl_event_handler: %d -> %d", dwCtrlType, signum);
+ exit_signal_handler(signum);
+ }
+ return TRUE;
+}
+#endif
+
void install_signal_handlers(bool keep_sigalrm)
{
#ifdef SIGHUP
@@ -615,6 +656,10 @@ void install_signal_handlers(bool keep_sigalrm)
else
siginterrupt(SIGBREAK, 1);
#endif
+#ifdef WIN32
+ if(!SetConsoleCtrlHandler(ctrl_event_handler, TRUE))
+ logmsg("cannot install CTRL event handler");
+#endif
}
void restore_signal_handlers(bool keep_sigalrm)
@@ -647,4 +692,7 @@ void restore_signal_handlers(bool keep_sigalrm)
if(SIG_ERR != old_sigbreak_handler)
(void)signal(SIGBREAK, old_sigbreak_handler);
#endif
+#ifdef WIN32
+ (void)SetConsoleCtrlHandler(ctrl_event_handler, FALSE);
+#endif
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [gnurl] 175/264: test1908: avoid using fixed port number in test data, (continued)
- [gnurl] 175/264: test1908: avoid using fixed port number in test data, gnunet, 2020/04/30
- [gnurl] 183/264: tests: support hex encoded data and mqtt server, gnunet, 2020/04/30
- [gnurl] 156/264: appveyor: partially revert 3413a110 to keep build without proxy, gnunet, 2020/04/30
- [gnurl] 173/264: socks: Fix blocking timeout logic, gnunet, 2020/04/30
- [gnurl] 190/264: RELEASE-NOTES: synced, gnunet, 2020/04/30
- [gnurl] 188/264: github/workflow: enable MQTT in the macOS debug build, gnunet, 2020/04/30
- [gnurl] 186/264: travis: add mqtt job on Linux, gnunet, 2020/04/30
- [gnurl] 230/264: server/tftpd: fix compiler warning, gnunet, 2020/04/30
- [gnurl] 263/264: Merge tag 'curl-7_70_0', gnunet, 2020/04/30
- [gnurl] 196/264: scripts/release-notes.pl: accept colon after the Fixes/Closes keywords, gnunet, 2020/04/30
- [gnurl] 169/264: tests/server: add CTRL event handler for Win32 consoles,
gnunet <=
- [gnurl] 243/264: libcurl-multi.3: added missing full stop, gnunet, 2020/04/30
- [gnurl] 209/264: tests: move pingpong server to dynamic listening port, gnunet, 2020/04/30
- [gnurl] 184/264: tests: add the mqtt test server mqttd, gnunet, 2020/04/30
- [gnurl] 210/264: test1028: make it run on dynamic FTP server port, gnunet, 2020/04/30
- [gnurl] 211/264: test1055: make it work with dynamic FTP port, gnunet, 2020/04/30
- [gnurl] 176/264: appveyor: completely disable tests that fail to timeout early, gnunet, 2020/04/30
- [gnurl] 139/264: release-notes: output trailing references sorted numerically, gnunet, 2020/04/30
- [gnurl] 244/264: select: make Curl_socket_check take timediff_t timeout, gnunet, 2020/04/30
- [gnurl] 150/264: release-notes: fix the initial reference list output, gnunet, 2020/04/30
- [gnurl] 144/264: http: allow Curl_add_buffer_send() to do a short first send by force, gnunet, 2020/04/30