enhanced bin/t06.c

This commit is contained in:
hyung-hwan 2021-07-17 16:16:00 +00:00
parent 0d6dcf6572
commit 2c32604c75

View File

@ -511,6 +511,13 @@ static int add_listener (mio_t* mio, mio_bch_t* addrstr)
} }
static mio_t* g_mio = MIO_NULL;
static void handle_sigint (int sig)
{
if (g_mio) mio_stop (g_mio, MIO_STOPREQ_TERMINATION);
}
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
mio_t* mio = MIO_NULL; mio_t* mio = MIO_NULL;
@ -518,7 +525,6 @@ int main (int argc, char* argv[])
mio_oow_t i; mio_oow_t i;
struct sigaction sigact; struct sigaction sigact;
// TODO: use getopt() or something similar // TODO: use getopt() or something similar
for (i = 1; i < argc; ) for (i = 1; i < argc; )
{ {
@ -556,6 +562,11 @@ int main (int argc, char* argv[])
sigact.sa_handler = SIG_IGN; sigact.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sigact, MIO_NULL); sigaction (SIGPIPE, &sigact, MIO_NULL);
memset (&sigact, 0, MIO_SIZEOF(sigact));
sigact.sa_handler = handle_sigint;
sigaction (SIGINT, &sigact, MIO_NULL);
XX_MQ_INIT (&xx_mq); XX_MQ_INIT (&xx_mq);
xx_tmridx = MIO_TMRIDX_INVALID; xx_tmridx = MIO_TMRIDX_INVALID;
@ -566,6 +577,8 @@ int main (int argc, char* argv[])
goto oops; goto oops;
} }
g_mio = mio;
for (i = 0; i < g_num_thrs; i++) for (i = 0; i < g_num_thrs; i++)
pthread_create (&t[i], MIO_NULL, thr_func, mio); pthread_create (&t[i], MIO_NULL, thr_func, mio);
@ -580,11 +593,17 @@ printf ("starting the main loop\n");
/* close all threaded mios here */ /* close all threaded mios here */
printf ("TERMINATING..NORMALLY \n"); printf ("TERMINATING..NORMALLY \n");
memset (&sigact, 0, MIO_SIZEOF(sigact));
sigact.sa_handler = SIG_IGN;
sigaction (SIGINT, &sigact, MIO_NULL);
mio_close (mio); mio_close (mio);
return 0; return 0;
oops: oops:
printf ("TERMINATING..ABNORMALLY \n"); printf ("TERMINATING..ABNORMALLY \n");
memset (&sigact, 0, MIO_SIZEOF(sigact));
sigact.sa_handler = SIG_IGN;
sigaction (SIGINT, &sigact, MIO_NULL);
if (mio) mio_close (mio); if (mio) mio_close (mio);
return -1; return -1;
} }