=================================================================== RCS file: /home/cvs/OpenXM/src/ox_math/serv1.c,v retrieving revision 1.15 retrieving revision 1.18 diff -u -p -r1.15 -r1.18 --- OpenXM/src/ox_math/serv1.c 2000/12/07 10:04:56 1.15 +++ OpenXM/src/ox_math/serv1.c 2002/04/11 19:53:40 1.18 @@ -1,5 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.14 2000/12/03 22:09:34 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.17 2002/04/11 14:13:37 ohara Exp $ */ /* Copyright (C) Katsuyoshi OHARA, 2000. @@ -20,15 +20,16 @@ extern OXFILE *stack_oxfp; -/* if in_critical equals to 1 then we do not permit an interrupt. */ -static int flag_sigusr1 = 0; - /* SM_control_reset_connection */ static void handler() { + sigset_t newmask, oldmask; + sigemptyset(&newmask); + sigaddset(&newmask, SIGUSR1); + sigprocmask(SIG_SETMASK, &newmask, &oldmask); fprintf(stderr, "signal received.\n"); - signal(SIGUSR1, handler); - flag_sigusr1++; + exchange_ox_sync_ball(stack_oxfp); + sigprocmask(SIG_SETMASK, &oldmask, NULL); /* unmasked. */ } static int exchange_ox_sync_ball(OXFILE *oxfp) @@ -61,8 +62,6 @@ int main() ml_init(); mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); - signal(SIGUSR1, handler); - sv = oxf_open(3); oxf_determine_byteorder_server(sv); sm(sv); @@ -96,18 +95,22 @@ int sm_receive_ox() int sm(OXFILE *oxfp) { - int mask; + fd_set fdmask; stack_oxfp = oxfp; stack_extend(); + signal(SIGUSR1, handler); - mask = sigsetmask(sigmask(SIGUSR1)); - while(sm_receive_ox()) { - sigsetmask(mask); - usleep(1); - sigsetmask(sigmask(SIGUSR1)); - if(flag_sigusr1) { - exchange_ox_sync_ball(oxfp); - flag_sigusr1 = 0; + FD_ZERO(&fdmask); + FD_SET(oxf_fileno(oxfp), &fdmask); + + while(1) { + if (select(5, &fdmask, NULL, NULL, NULL) > 0) { + sigset_t newmask, oldmask; + sigemptyset(&newmask); + sigaddset(&newmask, SIGUSR1); + sigprocmask(SIG_SETMASK, &newmask, &oldmask); + sm_receive_ox(); + sigprocmask(SIG_SETMASK, &oldmask, NULL); /* unmasked. */ } } fprintf(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd);