=================================================================== RCS file: /home/cvs/OpenXM/src/ox_ntl/oxserv.c,v retrieving revision 1.3 retrieving revision 1.7 diff -u -p -r1.3 -r1.7 --- OpenXM/src/ox_ntl/oxserv.c 2003/11/15 09:06:20 1.3 +++ OpenXM/src/ox_ntl/oxserv.c 2004/07/11 00:32:17 1.7 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/ox_ntl/oxserv.c,v 1.2 2003/11/08 12:34:00 iwane Exp $ */ +/* $OpenXM: OpenXM/src/ox_ntl/oxserv.c,v 1.6 2004/07/04 11:38:42 iwane Exp $ */ #include #include @@ -10,36 +10,15 @@ #include "oxserv.h" #include "oxstack.h" +#include "gmp.h" #include "gc/gc.h" -#define DPRINTF(x) printf x; fflush(stdout) +#define DPRINTF(x) printf x; (void)fflush(stdout) #define FP stdout -#define EPRINTF(x) fprintf x; fflush(FP) +#define EPRINTF(x) fprintf x; (void)fflush(FP) -#if 1 -/*===========================================================================* - * for DEBUG - *===========================================================================*/ -#include -void -dprintf(const char *fmt, ...) -{ - FILE *fp; - va_list ap; - va_start(ap, fmt); - - fp = fopen("error.txt", "a"); - vfprintf(fp, fmt, ap); - - fflush(fp); - fclose(fp); - - va_end(ap); -} -#endif - /*===========================================================================* * MACRO *===========================================================================*/ @@ -50,7 +29,7 @@ dprintf(const char *fmt, ...) do { \ if (c != NULL) { \ if (G_DeleteCmo != NULL) \ - G_DeleteCmo(c); \ + G_DeleteCmo((cmo *)c); \ else \ c = NULL; \ } \ @@ -65,7 +44,8 @@ static OXFILE *G_oxfilep = NULL; static cmo_mathcap *G_oxserv_mathcap = NULL; /* signal */ -sigset_t G_oxserv_sigusr1; +int G_oxserv_sigusr1flag = 0; +int G_oxserv_sigusr1cnt = 0; static jmp_buf G_jmpbuf; /* User Function */ @@ -149,9 +129,10 @@ oxserv_sm_popCMO(OXFILE *fd) m = new_cmo_null(); } else if (G_convertCmo) { n = G_convertCmo(m); - if (m != n) + if (m != n) { oxserv_delete_cmo(m); - m = n; + m = n; + } } send_ox_cmo(fd, m); @@ -186,7 +167,7 @@ oxserv_sm_popString(OXFILE *fd) send_ox_cmo(fd, (cmo *)m_str); oxserv_delete_cmo(m); - oxserv_delete_cmo((cmo *)m_str); + oxserv_delete_cmo(m_str); /* free(str); */ } @@ -221,7 +202,7 @@ oxserv_sm_pops() oxserv_delete_cmo(m); } - oxserv_delete_cmo((cmo *)c); + oxserv_delete_cmo(c); } @@ -322,7 +303,7 @@ oxserv_mathcap_init(int ver, char *vstr, char *sysname mathcap_init(ver, vstr, sysname, cmos, sms); - oxserv_delete_cmo((cmo *)G_oxserv_mathcap); + oxserv_delete_cmo(G_oxserv_mathcap); G_oxserv_mathcap = mathcap_get(new_mathcap()); } @@ -389,6 +370,8 @@ oxserv_sm_executeStringByLocalParser(void) * pop s as a function name, pop n as the number of arguments and to execute a * local function s with n arguments poped from the stack. * + * suppose G_userExecuteFunction not equal NULL + * * PARAM : NONE * RETURN: NONE *****************************************************************************/ @@ -400,17 +383,21 @@ oxserv_sm_executeFunction(void) cmo_int32 *cnt = (cmo_int32 *)oxstack_pop(); cmo **arg; - arg = (cmo **)malloc(cnt->i * sizeof(cmo *)); if (name == NULL || cnt == NULL) { oxserv_push_errormes("stack underflow in executeFunction"); return ; } + arg = (cmo **)malloc(cnt->i * sizeof(cmo *)); for (i = 0; i < cnt->i; i++) { arg[i] = oxstack_pop(); if (arg[i] == NULL) { oxserv_push_errormes("stack underflow in executeFunction"); + + for (i--; i >= 0; i--) + oxserv_delete_cmo(arg[i]); + free(arg); return ; } } @@ -423,8 +410,8 @@ oxserv_sm_executeFunction(void) oxserv_delete_cmo(arg[i]); } - oxserv_delete_cmo((cmo *)name); - oxserv_delete_cmo((cmo *)cnt); + oxserv_delete_cmo(name); + oxserv_delete_cmo(cnt); free(arg); } @@ -477,15 +464,25 @@ oxserv_sm_dupErrors() * -- SM_control_reset_connection -- signal handler for SIGUSR1 -- * * PARAM : NONE + * + * : if (sig == 0) called UNBLOCK_INPUT() * RETURN: NONE *****************************************************************************/ -static void +void oxserv_sm_control_reset_connection(int sig) { int tag; OXFILE *fd = G_oxfilep; + if (G_oxserv_sigusr1cnt > 0) { + G_oxserv_sigusr1flag = 1; + return ; + } + + DPRINTF(("reset -- start ==> ")); + G_oxserv_sigusr1flag = 0; + send_ox_tag(fd, OX_SYNC_BALL); oxstack_init_stack(); @@ -502,6 +499,7 @@ oxserv_sm_control_reset_connection(int sig) } DPRINTF((" <== end.\n")); + longjmp(G_jmpbuf, sig); } @@ -591,7 +589,9 @@ oxserv_ox_receive(OXFILE *fd) switch (tag) { case OX_DATA: + BLOCK_INPUT(); c = receive_cmo(fd); + UNBLOCK_INPUT(); DPRINTF(("[CMO:%d=0x%x]", c->tag, c->tag)); oxstack_push(c); break; @@ -655,9 +655,6 @@ oxserv_init(OXFILE *oxfp, int ver, char *vstr, char *s oxserv_mathcap_init(ver, vstr, sysname, cmos, sms); - /* signal */ - sigemptyset(&G_oxserv_sigusr1); - sigaddset(&G_oxserv_sigusr1, SIGUSR1); signal(SIGUSR1, oxserv_sm_control_reset_connection); /* initialize GMP memory functions. */ @@ -718,6 +715,8 @@ oxserv_set(int mode, void *ptr, void *rsv) void oxserv_dest() { + oxserv_delete_cmo(G_oxserv_mathcap); + oxstack_dest(); } @@ -728,7 +727,7 @@ oxserv_dest() *===========================================================================*/ -cmo * +void oxserv_executeFunction(const char *func, cmo **arg, int argc) { int i; @@ -739,7 +738,7 @@ oxserv_executeFunction(const char *func, cmo **arg, in printf("\t%2d: %s\n", i, new_string_set_cmo(arg[i])); } - return ((cmo *)new_cmo_int32(0)); + return ; } /***************************************************************************** @@ -759,18 +758,14 @@ main(int argc, char *argv[]) ox_stderr_init(stderr); - oxserv_init(oxfp, 0, "$Date: 2003/11/15 09:06:20 $", "oxserv", NULL, NULL); + oxserv_set(OXSERV_SET_EXECUTE_FUNCTION, oxserv_executeFunction, NULL); - DPRINTF(("main - start\n")); - for (i = 0;; i++) { - DPRINTF(("@")); - ret = oxserv_receive(oxfp); - if (ret != OXSERV_SUCCESS) - break; - } + oxserv_init(oxfp, 0, "$Date: 2004/07/11 00:32:17 $", "oxserv", NULL, NULL); + ret = oxserv_receive(oxfp); + + oxserv_dest(); oxf_close(oxfp); - oxserv_delete_cmo((cmo *)G_oxserv_mathcap); return (0); }