=================================================================== RCS file: /home/cvs/OpenXM/src/ox_math/serv1.c,v retrieving revision 1.12 retrieving revision 1.14 diff -u -p -r1.12 -r1.14 --- OpenXM/src/ox_math/serv1.c 2000/12/03 15:19:23 1.12 +++ OpenXM/src/ox_math/serv1.c 2000/12/03 22:09:34 1.14 @@ -1,5 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.11 2000/11/28 20:16:03 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.13 2000/12/03 21:46:52 ohara Exp $ */ /* Copyright (C) Katsuyoshi OHARA, 2000. @@ -16,18 +16,17 @@ #include #include #include -#include "serv2.h" +#include "sm.h" -static int send_ox_sync_ball(); +extern OXFILE *stack_oxfp; -static OXFILE *sv; - -static int flag_sigusr1 = 0; -static int flag_sigusr2 = 0; - /* 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; @@ -42,8 +41,6 @@ static int critical_p() { return in_critical; } -static int already_send_ox_sync_ball = 0; - /* SM_control_reset_connection */ static int handler_reset1() { @@ -60,59 +57,34 @@ static int handler_reset1() static int handler_kill() { - oxf_close(sv); + oxf_close(stack_oxfp); exit(1); } static int send_ox_sync_ball() { fprintf(stderr, "sending a sync_ball.\n"); - send_ox_tag(sv, OX_SYNC_BALL); + send_ox_tag(stack_oxfp, OX_SYNC_BALL); } -static int exchange_ox_syncball() +static int exchange_ox_sync_ball() { int tag; - while((tag = receive_ox_tag(sv)) != OX_SYNC_BALL) { + while((tag = receive_ox_tag(stack_oxfp)) != OX_SYNC_BALL) { /* skipping a message. */ if (tag == OX_DATA) { - receive_cmo(sv); + receive_cmo(stack_oxfp); }else { - receive_int32(sv); + receive_int32(stack_oxfp); } } fprintf(stderr, "received a sync_ball.\n"); } -/* a part of stack machine. */ -int receive_ox(OXFILE *oxfp) -{ - int tag; - int code; - - tag = receive_ox_tag(oxfp); - switch(tag) { - case OX_DATA: - push(receive_cmo(oxfp)); - break; - case OX_COMMAND: - code = receive_sm_command(oxfp); - set_critical(); - execute_sm_command(oxfp, code); - unset_critical(); - break; - default: - fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag); - return -1; - break; - } - return 0; -} - int shutdown() { - oxf_close(sv); + oxf_close(stack_oxfp); ml_exit(); exit(0); } @@ -122,7 +94,7 @@ int shutdown() int main() { - sv = oxf_open(3); + OXFILE* sv; ml_init(); mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); @@ -130,19 +102,54 @@ int main() signal(SIGUSR1, handler_reset1); signal(SIGKILL, handler_kill); - oxf_determine_byteorder_server(sv); + sv = oxf_open(3); + oxf_determine_byteorder_server(sv); + sm(sv); + shutdown(); +} - while(1) { - receive_ox(sv); +/* a part of stack machine. */ +int sm_receive_ox() +{ + int tag; + int code; + + tag = receive_ox_tag(stack_oxfp); + if (oxf_error(stack_oxfp)) { + return 0; + } + switch(tag) { + case OX_DATA: + push(receive_cmo(stack_oxfp)); + 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; +} + +int sm(OXFILE *oxfp) +{ + stack_oxfp = oxfp; + stack_extend(); + while(sm_receive_ox()) { if(flag_sigusr1) { if (!already_send_ox_sync_ball) { send_ox_sync_ball(); already_send_ox_sync_ball = 1; } - exchange_ox_syncball(); + exchange_ox_sync_ball(); flag_sigusr1 = 0; already_send_ox_sync_ball = 0; } } - shutdown(); + fprintf(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd); }