=================================================================== RCS file: /home/cvs/OpenXM/src/ox_math/serv1.c,v retrieving revision 1.15 retrieving revision 1.23 diff -u -p -r1.15 -r1.23 --- OpenXM/src/ox_math/serv1.c 2000/12/07 10:04:56 1.15 +++ OpenXM/src/ox_math/serv1.c 2005/07/26 12:52:04 1.23 @@ -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.22 2003/02/13 01:29:38 ohara Exp $ */ /* Copyright (C) Katsuyoshi OHARA, 2000. @@ -20,20 +20,10 @@ 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() -{ - fprintf(stderr, "signal received.\n"); - signal(SIGUSR1, handler); - flag_sigusr1++; -} - static int exchange_ox_sync_ball(OXFILE *oxfp) { int tag; + ox_printf("exchanging OX_SYNC_BALL\n"); send_ox_tag(oxfp, OX_SYNC_BALL); while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) { if (tag == OX_DATA) { @@ -51,18 +41,17 @@ int shutdown() exit(0); } -#define VERSION 0x11121400 -#define ID_STRING "2000/11/29" +/* (Heisei)15/02/01 */ +#define VERSION "2003/02/01" int main() { OXFILE* sv; + ox_stderr_init(stderr); ml_init(); - mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); + mathcap_init(VERSION, "ox_math"); - signal(SIGUSR1, handler); - sv = oxf_open(3); oxf_determine_byteorder_server(sv); sm(sv); @@ -88,7 +77,7 @@ int sm_receive_ox() sm_run(code); break; default: - fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag); + ox_printf("illeagal OX message(%d)\n", tag); break; } return 1; @@ -96,19 +85,29 @@ int sm_receive_ox() int sm(OXFILE *oxfp) { - int mask; + int i=0; + fd_set fdmask; stack_oxfp = oxfp; stack_extend(); + sm_siginit(); - 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); + + for (i=0; ; i++) { + sm_sigunmask(); + ox_printf("phase%d: select\n",i); + if (select(5, &fdmask, NULL, NULL, NULL) > 0) { + sm_sigmask(); + ox_printf("phase%d: receiving\n",i); + sm_receive_ox(); } + sm_sigmask(); + ox_printf("phase%d: clearing(%d)\n",i,sm_state_interrupting()); + if (sm_state_interrupting()) { + exchange_ox_sync_ball(stack_oxfp); + sm_state_clear_interrupting(); + } } - fprintf(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd); + ox_printf("ox_math::socket(%d) is closed.\n", stack_oxfp->fd); }