vere: mingw: pass Ctrl-C to serf

This commit is contained in:
~locpyl-tidnyd 2021-05-06 12:36:58 +03:00
parent 3a930d75a1
commit 6702dad5f0
5 changed files with 59 additions and 1 deletions

View File

@ -753,6 +753,18 @@ main(c3_i argc,
} }
} }
#if defined(U3_OS_mingw)
// Initialize event used to transmit Ctrl-C to worker process
//
{
SECURITY_ATTRIBUTES sa = {sizeof(sa), NULL, TRUE};
if ( NULL == (u3_Host.cev_u = CreateEvent(&sa, FALSE, FALSE, NULL)) ) {
u3l_log("boot: failed to create Ctrl-C event: %d\r\n", GetLastError());
exit(1);
}
}
#endif
// Initialize OpenSSL for client and server // Initialize OpenSSL for client and server
// //
{ {

View File

@ -319,6 +319,9 @@
c3_d now_d; // event tick c3_d now_d; // event tick
uv_loop_t* lup_u; // libuv event loop uv_loop_t* lup_u; // libuv event loop
u3_usig* sig_u; // signal list u3_usig* sig_u; // signal list
#if defined(U3_OS_mingw)
HANDLE cev_u; // Ctrl-C event handle
#endif
u3_utty* uty_u; // linked terminal list u3_utty* uty_u; // linked terminal list
u3_opts ops_u; // commandline options u3_opts ops_u; // commandline options
c3_i xit_i; // exit code for shutdown c3_i xit_i; // exit code for shutdown

View File

@ -590,6 +590,10 @@ _king_sign_cb(uv_signal_t* sil_u, c3_i num_i)
case SIGINT: { case SIGINT: {
u3l_log("\r\ninterrupt\r\n"); u3l_log("\r\ninterrupt\r\n");
u3_term_ef_ctlc(); u3_term_ef_ctlc();
#if defined(U3_OS_mingw)
PulseEvent(u3_Host.cev_u);
#endif
break; break;
} }

View File

@ -1145,6 +1145,7 @@ u3_lord_init(c3_c* pax_c, c3_w wag_w, c3_d key_d[4], u3_lord_cb cb_u)
c3_c key_c[256]; c3_c key_c[256];
c3_c wag_c[11]; c3_c wag_c[11];
c3_c hap_c[11]; c3_c hap_c[11];
c3_c cev_c[11];
c3_i err_i; c3_i err_i;
sprintf(key_c, "%" PRIx64 ":%" PRIx64 ":%" PRIx64 ":%" PRIx64 "", sprintf(key_c, "%" PRIx64 ":%" PRIx64 ":%" PRIx64 ":%" PRIx64 "",
@ -1173,7 +1174,13 @@ u3_lord_init(c3_c* pax_c, c3_w wag_w, c3_d key_d[4], u3_lord_cb cb_u)
arg_c[6] = "0"; arg_c[6] = "0";
} }
#if defined(U3_OS_mingw)
sprintf(cev_c, "%u", u3_Host.cev_u);
arg_c[7] = cev_c;
arg_c[8] = 0;
#else
arg_c[7] = 0; arg_c[7] = 0;
#endif
uv_pipe_init(u3L, &god_u->inn_u.pyp_u, 0); uv_pipe_init(u3L, &god_u->inn_u.pyp_u, 0);
uv_timer_init(u3L, &god_u->out_u.tim_u); uv_timer_init(u3L, &god_u->out_u.tim_u);

View File

@ -155,6 +155,18 @@ _cw_serf_exit(void)
u3t_trace_close(); u3t_trace_close();
} }
#if defined(U3_OS_mingw)
extern void rsignal_raise(int);
/* _mingw_ctrlc_cb(): invoked when the lord signals the Ctrl-C event
*/
static void
_mingw_ctrlc_cb(PVOID param, BOOLEAN timedOut)
{
rsignal_raise(SIGINT);
}
#endif
/* _cw_serf_commence(); initialize and run serf /* _cw_serf_commence(); initialize and run serf
*/ */
static void static void
@ -163,7 +175,23 @@ _cw_serf_commence(c3_i argc, c3_c* argv[])
c3_i inn_i, out_i; c3_i inn_i, out_i;
_cw_serf_stdio(&inn_i, &out_i); _cw_serf_stdio(&inn_i, &out_i);
#if defined(U3_OS_mingw)
c3_assert( 8 == argc );
// Initialize serf's end of Ctrl-C handling
//
{
HANDLE h;
if ( 1 != sscanf(argv[7], "%u", &h) ) {
fprintf(stderr, "serf: Ctrl-C event: bad handle %s: %s\r\n", argv[7], strerror(errno));
} else
if ( !RegisterWaitForSingleObject(&h, h, _mingw_ctrlc_cb, NULL, INFINITE, 0) ) {
fprintf(stderr, "serf: Ctrl-C event: RegisterWaitForSingleObject(%u) failed (%d)\r\n", h, GetLastError());
}
}
#else
c3_assert( 7 == argc ); c3_assert( 7 == argc );
#endif
uv_loop_t* lup_u = uv_default_loop(); uv_loop_t* lup_u = uv_default_loop();
c3_c* dir_c = argv[2]; c3_c* dir_c = argv[2];
@ -435,7 +463,11 @@ _cw_usage(c3_i argc, c3_c* argv[])
" cue persistent state:\n" " cue persistent state:\n"
" %s queu <pier> <at-event>\n\n" " %s queu <pier> <at-event>\n\n"
" run as a 'serf':\n" " run as a 'serf':\n"
" %s serf <pier> <key> <flags> <cache-size> <at-event>\n", " %s serf <pier> <key> <flags> <cache-size> <at-event>"
#if defined(U3_OS_mingw)
" <ctrlc-handle>"
#endif
"\n",
argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0]); argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0]);
} }