version 1.8, 2000/01/22 06:29:18 |
version 1.13, 2000/12/03 21:46:52 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.7 2000/01/05 06:09:11 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.12 2000/12/03 15:19:23 ohara Exp $ */ |
|
|
/* |
/* |
Copyright (C) Katsuyoshi OHARA, 2000. |
Copyright (C) Katsuyoshi OHARA, 2000. |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <signal.h> |
#include <signal.h> |
#include <gmp.h> |
|
#include <mathlink.h> |
#include <mathlink.h> |
#include "ox.h" |
#include <ox_toolkit.h> |
#include "serv2.h" |
#include "sm.h" |
|
|
static int send_ox_sync_ball(int fd); |
static int send_ox_sync_ball(); |
|
|
static int sv_read = 3; |
extern OXFILE *stack_oxfp; |
static int sv_write = 4; |
|
|
|
static int flag_sigusr1 = 0; |
static int flag_sigusr1 = 0; |
static int flag_sigusr2 = 0; |
static int flag_sigusr2 = 0; |
Line 54 static int handler_reset1() |
|
Line 52 static int handler_reset1() |
|
if (!flag_sigusr1) { |
if (!flag_sigusr1) { |
flag_sigusr1 = 1; |
flag_sigusr1 = 1; |
if(critical_p()) { |
if(critical_p()) { |
send_ox_sync_ball(sv_write); |
send_ox_sync_ball(); |
already_send_ox_sync_ball = 1; |
already_send_ox_sync_ball = 1; |
} |
} |
} |
} |
Line 62 static int handler_reset1() |
|
Line 60 static int handler_reset1() |
|
|
|
static int handler_kill() |
static int handler_kill() |
{ |
{ |
close(3); |
oxf_close(stack_oxfp); |
close(4); |
|
exit(1); |
exit(1); |
} |
} |
|
|
static int send_ox_sync_ball(int fd) |
static int send_ox_sync_ball() |
{ |
{ |
fprintf(stderr, "sending a sync_ball.\n"); |
fprintf(stderr, "sending a sync_ball.\n"); |
send_ox_tag(fd, OX_SYNC_BALL); |
send_ox_tag(stack_oxfp, OX_SYNC_BALL); |
} |
} |
|
|
static int exchange_ox_syncball(int fd) |
static int exchange_ox_syncball() |
{ |
{ |
int tag; |
int tag; |
|
|
while((tag = receive_ox_tag(fd)) != OX_SYNC_BALL) { |
while((tag = receive_ox_tag(stack_oxfp)) != OX_SYNC_BALL) { |
/* skipping a message. */ |
/* skipping a message. */ |
if (tag == OX_DATA) { |
if (tag == OX_DATA) { |
receive_cmo(fd); |
receive_cmo(stack_oxfp); |
}else { |
}else { |
receive_int32(fd); |
receive_int32(stack_oxfp); |
} |
} |
} |
} |
fprintf(stderr, "received a sync_ball.\n"); |
fprintf(stderr, "received a sync_ball.\n"); |
} |
} |
|
|
/* a part of stack machine. */ |
/* a part of stack machine. */ |
int receive_ox(int fd_read, int fd_write) |
int sm_receive_ox() |
{ |
{ |
int tag; |
int tag; |
int code; |
int code; |
|
|
tag = receive_ox_tag(fd_read); |
tag = receive_ox_tag(stack_oxfp); |
|
if (oxf_error(stack_oxfp)) { |
|
return 0; |
|
} |
switch(tag) { |
switch(tag) { |
case OX_DATA: |
case OX_DATA: |
push(receive_cmo(fd_read)); |
push(receive_cmo(stack_oxfp)); |
break; |
break; |
case OX_COMMAND: |
case OX_COMMAND: |
code = receive_sm_command(fd_read); |
code = receive_sm_command(stack_oxfp); |
set_critical(); |
set_critical(); |
execute_sm_command(fd_write, code); |
sm_run(code); |
unset_critical(); |
unset_critical(); |
break; |
break; |
default: |
default: |
fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag); |
fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag); |
return -1; |
return 0; |
break; |
break; |
} |
} |
return 0; |
return 1; |
} |
} |
|
|
int shutdown() |
int shutdown() |
{ |
{ |
close(sv_read); |
oxf_close(stack_oxfp); |
close(sv_write); |
|
ml_exit(); |
ml_exit(); |
exit(0); |
exit(0); |
} |
} |
|
|
|
#define VERSION 0x11121400 |
|
#define ID_STRING "2000/11/29" |
|
|
|
int oxf_error(OXFILE *oxfp) |
|
{ |
|
int e = oxfp->error; |
|
if (e != 0) { |
|
oxfp->error = 0; |
|
} |
|
return e; |
|
} |
|
|
int main() |
int main() |
{ |
{ |
|
OXFILE* sv; |
|
|
ml_init(); |
ml_init(); |
initialize_stack(); |
mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL); |
|
|
signal(SIGUSR1, handler_reset1); |
signal(SIGUSR1, handler_reset1); |
signal(SIGKILL, handler_kill); |
signal(SIGKILL, handler_kill); |
|
|
decideByteOrderServer(sv_read, 0); |
sv = oxf_open(3); |
|
oxf_determine_byteorder_server(sv); |
|
sm(sv); |
|
shutdown(); |
|
} |
|
|
while(1) { |
int sm(OXFILE *oxfp) |
receive_ox(sv_read, sv_write); |
{ |
|
stack_oxfp = oxfp; |
|
stack_extend(); |
|
while(sm_receive_ox()) { |
if(flag_sigusr1) { |
if(flag_sigusr1) { |
if (!already_send_ox_sync_ball) { |
if (!already_send_ox_sync_ball) { |
send_ox_sync_ball(sv_write); |
send_ox_sync_ball(); |
already_send_ox_sync_ball = 1; |
already_send_ox_sync_ball = 1; |
} |
} |
exchange_ox_syncball(sv_read); |
exchange_ox_syncball(); |
flag_sigusr1 = 0; |
flag_sigusr1 = 0; |
already_send_ox_sync_ball = 0; |
already_send_ox_sync_ball = 0; |
} |
} |
} |
} |
shutdown(); |
fprintf(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd); |
} |
} |