=================================================================== RCS file: /home/cvs/OpenXM/src/ox_math/serv1.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -p -r1.14 -r1.15 --- OpenXM/src/ox_math/serv1.c 2000/12/03 22:09:34 1.14 +++ OpenXM/src/ox_math/serv1.c 2000/12/07 10:04:56 1.15 @@ -1,5 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.13 2000/12/03 21:46:52 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.14 2000/12/03 22:09:34 ohara Exp $ */ /* Copyright (C) Katsuyoshi OHARA, 2000. @@ -21,65 +21,27 @@ extern OXFILE *stack_oxfp; /* if in_critical equals to 1 then we do not permit an interrupt. */ -static int in_critical = 0; -static int already_send_ox_sync_ball = 0; static int flag_sigusr1 = 0; -static int send_ox_sync_ball(); - -static int set_critical() -{ - in_critical = 1; -} - -static int unset_critical() -{ - in_critical = 0; -} - -static int critical_p() { - return in_critical; -} - /* SM_control_reset_connection */ -static int handler_reset1() +static void handler() { fprintf(stderr, "signal received.\n"); - signal(SIGUSR1, handler_reset1); - if (!flag_sigusr1) { - flag_sigusr1 = 1; - if(critical_p()) { - send_ox_sync_ball(); - already_send_ox_sync_ball = 1; - } - } + signal(SIGUSR1, handler); + flag_sigusr1++; } -static int handler_kill() +static int exchange_ox_sync_ball(OXFILE *oxfp) { - oxf_close(stack_oxfp); - exit(1); -} - -static int send_ox_sync_ball() -{ - fprintf(stderr, "sending a sync_ball.\n"); - send_ox_tag(stack_oxfp, OX_SYNC_BALL); -} - -static int exchange_ox_sync_ball() -{ int tag; - - while((tag = receive_ox_tag(stack_oxfp)) != OX_SYNC_BALL) { - /* skipping a message. */ + send_ox_tag(oxfp, OX_SYNC_BALL); + while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) { if (tag == OX_DATA) { - receive_cmo(stack_oxfp); - }else { - receive_int32(stack_oxfp); + receive_cmo(oxfp); + }else if (tag == OX_COMMAND) { + receive_int32(oxfp); } } - fprintf(stderr, "received a sync_ball.\n"); } int shutdown() @@ -99,8 +61,7 @@ int main() ml_init(); mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); - signal(SIGUSR1, handler_reset1); - signal(SIGKILL, handler_kill); + signal(SIGUSR1, handler); sv = oxf_open(3); oxf_determine_byteorder_server(sv); @@ -124,13 +85,10 @@ int sm_receive_ox() break; case OX_COMMAND: code = receive_sm_command(stack_oxfp); - set_critical(); sm_run(code); - unset_critical(); break; default: fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag); - return 0; break; } return 1; @@ -138,17 +96,18 @@ int sm_receive_ox() int sm(OXFILE *oxfp) { + int mask; stack_oxfp = oxfp; stack_extend(); + + mask = sigsetmask(sigmask(SIGUSR1)); while(sm_receive_ox()) { + sigsetmask(mask); + usleep(1); + sigsetmask(sigmask(SIGUSR1)); if(flag_sigusr1) { - if (!already_send_ox_sync_ball) { - send_ox_sync_ball(); - already_send_ox_sync_ball = 1; - } - exchange_ox_sync_ball(); + exchange_ox_sync_ball(oxfp); flag_sigusr1 = 0; - already_send_ox_sync_ball = 0; } } fprintf(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd);