version 1.14, 2000/12/03 22:09:34 |
version 1.19, 2003/01/11 12:38:57 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- 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.18 2002/04/11 19:53:40 ohara Exp $ */ |
|
|
/* |
/* |
Copyright (C) Katsuyoshi OHARA, 2000. |
Copyright (C) Katsuyoshi OHARA, 2000. |
|
|
|
|
extern OXFILE *stack_oxfp; |
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 */ |
/* SM_control_reset_connection */ |
static int handler_reset1() |
static void handler() |
{ |
{ |
fprintf(stderr, "signal received.\n"); |
sigset_t newmask, oldmask; |
signal(SIGUSR1, handler_reset1); |
sigemptyset(&newmask); |
if (!flag_sigusr1) { |
sigaddset(&newmask, SIGUSR1); |
flag_sigusr1 = 1; |
sigprocmask(SIG_SETMASK, &newmask, &oldmask); |
if(critical_p()) { |
fprintf(ox_stderr, "signal received.\n"); |
send_ox_sync_ball(); |
exchange_ox_sync_ball(stack_oxfp); |
already_send_ox_sync_ball = 1; |
sigprocmask(SIG_SETMASK, &oldmask, NULL); /* unmasked. */ |
} |
|
} |
|
} |
} |
|
|
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; |
int tag; |
|
send_ox_tag(oxfp, OX_SYNC_BALL); |
while((tag = receive_ox_tag(stack_oxfp)) != OX_SYNC_BALL) { |
while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) { |
/* skipping a message. */ |
|
if (tag == OX_DATA) { |
if (tag == OX_DATA) { |
receive_cmo(stack_oxfp); |
receive_cmo(oxfp); |
}else { |
}else if (tag == OX_COMMAND) { |
receive_int32(stack_oxfp); |
receive_int32(oxfp); |
} |
} |
} |
} |
fprintf(stderr, "received a sync_ball.\n"); |
|
} |
} |
|
|
int shutdown() |
int shutdown() |
|
|
{ |
{ |
OXFILE* sv; |
OXFILE* sv; |
|
|
|
ox_stderr_init(NULL); |
ml_init(); |
ml_init(); |
mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); |
mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); |
|
|
signal(SIGUSR1, handler_reset1); |
|
signal(SIGKILL, handler_kill); |
|
|
|
sv = oxf_open(3); |
sv = oxf_open(3); |
oxf_determine_byteorder_server(sv); |
oxf_determine_byteorder_server(sv); |
sm(sv); |
sm(sv); |
Line 124 int sm_receive_ox() |
|
Line 85 int sm_receive_ox() |
|
break; |
break; |
case OX_COMMAND: |
case OX_COMMAND: |
code = receive_sm_command(stack_oxfp); |
code = receive_sm_command(stack_oxfp); |
set_critical(); |
|
sm_run(code); |
sm_run(code); |
unset_critical(); |
|
break; |
break; |
default: |
default: |
fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag); |
fprintf(ox_stderr, "illeagal message? ox_tag = (%d)\n", tag); |
return 0; |
|
break; |
break; |
} |
} |
return 1; |
return 1; |
Line 138 int sm_receive_ox() |
|
Line 96 int sm_receive_ox() |
|
|
|
int sm(OXFILE *oxfp) |
int sm(OXFILE *oxfp) |
{ |
{ |
|
fd_set fdmask; |
stack_oxfp = oxfp; |
stack_oxfp = oxfp; |
stack_extend(); |
stack_extend(); |
while(sm_receive_ox()) { |
signal(SIGUSR1, handler); |
if(flag_sigusr1) { |
|
if (!already_send_ox_sync_ball) { |
FD_ZERO(&fdmask); |
send_ox_sync_ball(); |
FD_SET(oxf_fileno(oxfp), &fdmask); |
already_send_ox_sync_ball = 1; |
|
} |
while(1) { |
exchange_ox_sync_ball(); |
if (select(5, &fdmask, NULL, NULL, NULL) > 0) { |
flag_sigusr1 = 0; |
sigset_t newmask, oldmask; |
already_send_ox_sync_ball = 0; |
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); |
fprintf(ox_stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd); |
} |
} |