version 1.2, 2003/08/22 16:08:20 |
version 1.12, 2020/10/07 23:53:25 |
|
|
/* $OpenXM: OpenXM/src/k097/ox_k0.c,v 1.1 2003/05/14 07:09:47 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/k097/ox_k0.c,v 1.11 2016/03/31 05:27:34 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
|
|
#include <netdb.h> |
#include <netdb.h> |
#include <signal.h> |
#include <signal.h> |
#include <setjmp.h> |
#include <setjmp.h> |
|
#include <string.h> |
|
#include <stdlib.h> |
/* -lnsl -lsocket /usr/ucblib/libucb.a */ |
/* -lnsl -lsocket /usr/ucblib/libucb.a */ |
#include "../kxx/ox_kan.h" |
#include "../kxx/ox_kan.h" |
#include "../kxx/serversm.h" |
#include "../kxx/serversm.h" |
|
#include "ox_k0.h" |
|
#include "ki.h" |
|
|
|
|
int OxCritical = 0; |
int OxCritical = 0; |
int OxInterruptFlag = 0; |
int OxInterruptFlag = 0; |
int PacketMonitor = 0; |
int PacketMonitor = 0; |
Line 18 int PacketMonitor = 0; |
|
Line 23 int PacketMonitor = 0; |
|
extern int SerialOX; /* Serial number of the packets sent. */ |
extern int SerialOX; /* Serial number of the packets sent. */ |
extern int SerialCurrent; /* Current Serial number of the recieved packet. */ |
extern int SerialCurrent; /* Current Serial number of the recieved packet. */ |
extern int OXprintMessage; /* print oxmessages? */ |
extern int OXprintMessage; /* print oxmessages? */ |
|
extern int Calling_ctrlC_hook; |
|
|
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
sigjmp_buf EnvOfChildServer; |
sigjmp_buf EnvOfChildServer; |
Line 28 jmp_buf EnvOfChildServer; |
|
Line 34 jmp_buf EnvOfChildServer; |
|
int JmpMessage = 0; |
int JmpMessage = 0; |
|
|
static char *getSuffix(char *s); |
static char *getSuffix(char *s); |
main(int argc, char *argv[]) { |
void main(int argc, char *argv[]) { |
char *s; |
char *s; |
|
|
if (argc > 1) { |
if (argc > 1) { |
Line 43 main(int argc, char *argv[]) { |
|
Line 49 main(int argc, char *argv[]) { |
|
/* Sm1_start(0, NULL, "ox_sm1"); */ |
/* Sm1_start(0, NULL, "ox_sm1"); */ |
K0_start(); |
K0_start(); |
|
|
nullserver(3); |
nullserver(3,4); |
} |
} |
|
|
static char *getSuffix(char *s) { |
static char *getSuffix(char *s) { |
Line 62 static char *getSuffix(char *s) { |
|
Line 68 static char *getSuffix(char *s) { |
|
} |
} |
return(s); |
return(s); |
} |
} |
nullserver(int fdStream) { |
void nullserver(int fdStreamIn,int fdStreamOut) { |
int mtag; |
int mtag; |
int message = 1; |
int message = 1; |
ox_stream ostream; |
ox_stream ostreamIn; |
|
ox_stream ostreamOut; |
char sreason[1024]; |
char sreason[1024]; |
|
extern int RestrictedMode, RestrictedMode_saved; |
extern void controlResetHandler(); |
extern void controlResetHandler(); |
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
extern sigjmp_buf EnvOfStackMachine; |
extern sigjmp_buf EnvOfStackMachine; |
Line 74 nullserver(int fdStream) { |
|
Line 82 nullserver(int fdStream) { |
|
extern jmp_buf EnvOfStackMachine; |
extern jmp_buf EnvOfStackMachine; |
#endif |
#endif |
int engineByteOrder; |
int engineByteOrder; |
|
extern int InSendmsg2; |
|
|
fflush(NULL); |
fflush(NULL); |
engineByteOrder = oxTellMyByteOrder(fdStream); |
engineByteOrder = oxTellMyByteOrder(fdStreamOut,fdStreamIn); |
/* Set the network byte order. */ |
/* Set the network byte order. */ |
fprintf(stderr,"engineByteOrder=%x\n",engineByteOrder); |
fprintf(stderr,"engineByteOrder=%x\n",engineByteOrder); |
|
|
if (fdStream != -1) { |
if (fdStreamIn != -1) { |
ostream = fp2open(fdStream); |
ostreamIn = fp2open(fdStreamIn); |
if (ostream == NULL) { |
if (ostreamIn == NULL) { |
fprintf(stderr,"fp2open(fdStream) failed.\n"); |
fprintf(stderr,"fp2open(fdStreamIn) failed.\n"); |
fdStream = -1; |
fdStreamIn = -1; |
} |
} |
if (PacketMonitor) fp2watch(ostream,stdout); |
if (PacketMonitor) fp2watch(ostreamIn,stdout); |
} |
} |
|
if (fdStreamOut != -1) { |
|
ostreamOut = fp2open(fdStreamOut); |
|
if (ostreamOut == NULL) { |
|
fprintf(stderr,"fp2open(fdStreamOut) failed.\n"); |
|
fdStreamOut = -1; |
|
} |
|
if (PacketMonitor) fp2watch(ostreamOut,stdout); |
|
} |
aaa : ; |
aaa : ; |
clearInop(); |
clearInop(); |
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
Line 108 nullserver(int fdStream) { |
|
Line 125 nullserver(int fdStream) { |
|
if (OxInterruptFlag == 0) { |
if (OxInterruptFlag == 0) { |
fprintf(stderr," ?! \n"); fflush(NULL); |
fprintf(stderr," ?! \n"); fflush(NULL); |
} |
} |
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
if (!Calling_ctrlC_hook) { |
|
Calling_ctrlC_hook = 1; RestrictedMode = 0; |
|
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
|
RestrictedMode = RestrictedMode_saved; |
|
} |
|
Calling_ctrlC_hook = 0; |
KSexecuteString(" (Computation is interrupted.) "); |
KSexecuteString(" (Computation is interrupted.) "); |
signal(SIGUSR1,controlResetHandler); goto aaa; |
InSendmsg2 = 0; |
|
mysignal(SIGUSR1,controlResetHandler); goto aaa; |
} else { |
} else { |
if (JmpMessage) fprintf(stderr,"Set EnvOfChildServer.\n"); |
if (JmpMessage) fprintf(stderr,"Set EnvOfChildServer.\n"); |
signal(SIGUSR1,controlResetHandler); |
mysignal(SIGUSR1,controlResetHandler); |
} |
} |
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
if (sigsetjmp(EnvOfStackMachine,1)) { |
if (sigsetjmp(EnvOfStackMachine,1)) { |
Line 141 nullserver(int fdStream) { |
|
Line 164 nullserver(int fdStream) { |
|
*/ |
*/ |
Sm1_pushError2(SerialCurrent,-1,"Global jump by sm1 error"); |
Sm1_pushError2(SerialCurrent,-1,"Global jump by sm1 error"); |
|
|
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
if (!Calling_ctrlC_hook) { |
signal(SIGUSR1,controlResetHandler); goto aaa ; |
Calling_ctrlC_hook = 1; RestrictedMode = 0; |
|
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
|
RestrictedMode = RestrictedMode_saved; |
|
} |
|
Calling_ctrlC_hook = 0; |
|
InSendmsg2=0; |
|
mysignal(SIGUSR1,controlResetHandler); goto aaa ; |
} else { |
} else { |
if (JmpMessage) fprintf(stderr,"Set EnvOfStackMachine.\n"); |
if (JmpMessage) fprintf(stderr,"Set EnvOfStackMachine.\n"); |
if (signal(SIGUSR1,SIG_IGN) != SIG_IGN) { |
if (mysignal(SIGUSR1,SIG_IGN) != SIG_IGN) { |
signal(SIGUSR1,controlResetHandler); |
mysignal(SIGUSR1,controlResetHandler); |
} |
} |
} |
} |
|
|
Line 155 nullserver(int fdStream) { |
|
Line 184 nullserver(int fdStream) { |
|
if (OxInterruptFlag) { |
if (OxInterruptFlag) { |
OxCritical = 1; |
OxCritical = 1; |
if (message) {fprintf(stderr,"Clearing the read buffer.\n");fflush(NULL); } |
if (message) {fprintf(stderr,"Clearing the read buffer.\n");fflush(NULL); } |
fp2clearReadBuf(ostream); /* clear the read buffer */ |
fp2clearReadBuf(ostreamIn); /* clear the read buffer */ |
if (message) {fprintf(stderr,"Throwing OX_SYNC_BALL\n"); fflush(NULL);} |
if (message) {fprintf(stderr,"Throwing OX_SYNC_BALL\n"); fflush(NULL);} |
oxSendSyncBall(ostream); |
oxSendSyncBall(ostreamOut); |
if (message) {fprintf(stderr,"Waiting for OX_SYNC_BALL\n");fflush(NULL);} |
if (message) {fprintf(stderr,"Waiting for OX_SYNC_BALL\n");fflush(NULL);} |
oxWaitSyncBall(ostream); |
oxWaitSyncBall(ostreamIn); |
if (message) {fprintf(stderr,"Done changing OX_SYNC_BALL\n"); fflush(NULL);} |
if (message) {fprintf(stderr,"Done changing OX_SYNC_BALL\n"); fflush(NULL);} |
OxInterruptFlag = 0; |
OxInterruptFlag = 0; |
OxCritical = 0; |
OxCritical = 0; |
goto aaa ; |
goto aaa ; |
} |
} |
OxCritical = 0; |
OxCritical = 0; |
if (fp2select(ostream,-1)) { |
if (fp2select(ostreamIn,-1)) { |
/* If there is an data in the ostream, then read data in the buffer and |
/* If there is an data in the ostream, then read data in the buffer and |
read data in the communication stream. */ |
read data in the communication stream. */ |
OxCritical = 1; |
OxCritical = 1; |
Line 175 nullserver(int fdStream) { |
|
Line 204 nullserver(int fdStream) { |
|
/* This part is never reached. */ |
/* This part is never reached. */ |
} |
} |
OxCritical = 1; |
OxCritical = 1; |
mtag = oxGetOXheader(ostream,&SerialCurrent); /* get the message_tag */ |
mtag = oxGetOXheader(ostreamIn,&SerialCurrent); /* get the message_tag */ |
if (message) { |
if (message) { |
fprintf(stderr,"\nmtag is %d (serial=%d) : ",mtag,SerialCurrent); |
fprintf(stderr,"\nmtag is %d (serial=%d) : ",mtag,SerialCurrent); |
switch(mtag) { |
switch(mtag) { |
Line 190 nullserver(int fdStream) { |
|
Line 219 nullserver(int fdStream) { |
|
/*sleep(2); /* for dubug OX_SYNC_BALL */ |
/*sleep(2); /* for dubug OX_SYNC_BALL */ |
switch(mtag) { |
switch(mtag) { |
case OX_COMMAND: |
case OX_COMMAND: |
nullserverCommand(ostream); |
nullserverCommand(ostreamIn,ostreamOut); |
goto aaa ; /* We always reset the jump vector. cf. memo1.txt 1998 2/13*/ |
goto aaa ; /* We always reset the jump vector. cf. memo1.txt 1998 2/13*/ |
break; |
break; |
case OX_DATA: |
case OX_DATA: |
Sm1_pushCMO(ostream); |
Sm1_pushCMO(ostreamIn); |
break; |
break; |
case OX_SYNC_BALL: |
case OX_SYNC_BALL: |
/* if (OxInterruptFlag) think about it later. */ |
/* if (OxInterruptFlag) think about it later. */ |
Line 206 nullserver(int fdStream) { |
|
Line 235 nullserver(int fdStream) { |
|
} |
} |
} |
} |
|
|
nullserverCommand(ox_stream ostream) { |
int nullserverCommand(ox_stream ostreamIn,ox_stream ostreamOut) { |
int id; |
int id; |
int mtag; |
int mtag; |
int n; |
int n; |
Line 220 nullserverCommand(ox_stream ostream) { |
|
Line 249 nullserverCommand(ox_stream ostream) { |
|
|
|
message = OXprintMessage; |
message = OXprintMessage; |
/* message_body */ |
/* message_body */ |
id = oxGetInt32(ostream); /* get the function_id */ |
id = oxGetInt32(ostreamIn); /* get the function_id */ |
if (message) {fprintf(stderr,"\nfunction_id is %d\n",id);} |
if (message) {fprintf(stderr,"\nfunction_id is %d\n",id);} |
switch( id ) { |
switch( id ) { |
case SM_mathcap: |
case SM_mathcap: |
Line 230 nullserverCommand(ox_stream ostream) { |
|
Line 259 nullserverCommand(ox_stream ostream) { |
|
break; |
break; |
case SM_setMathCap: |
case SM_setMathCap: |
if (message) fprintf(stderr," setMathCap\n"); |
if (message) fprintf(stderr," setMathCap\n"); |
Sm1_setMathCap(ostream); |
Sm1_setMathCap(ostreamOut); |
break; |
break; |
case SM_pops: |
case SM_pops: |
if (message) fprintf(stderr," pops \n"); |
if (message) fprintf(stderr," pops \n"); |
Line 266 nullserverCommand(ox_stream ostream) { |
|
Line 295 nullserverCommand(ox_stream ostream) { |
|
if (message) fprintf(stderr," executeStringByLocalParser\n"); |
if (message) fprintf(stderr," executeStringByLocalParser\n"); |
OxCritical = 0; |
OxCritical = 0; |
iresult = K0_executeStringByLocalParser(); |
iresult = K0_executeStringByLocalParser(); |
OxCritical = 1; signal(SIGUSR1,controlResetHandler); |
OxCritical = 1; mysignal(SIGUSR1,controlResetHandler); |
if (iresult < 0) { |
if (iresult < 0) { |
emsg = Sm1_popErrorMessage("executeString: "); |
emsg = Sm1_popErrorMessage("executeString: "); |
Sm1_pushError2(SerialCurrent,-1,emsg); |
Sm1_pushError2(SerialCurrent,-1,emsg); |
Line 277 nullserverCommand(ox_stream ostream) { |
|
Line 306 nullserverCommand(ox_stream ostream) { |
|
if (message) fprintf(stderr," executeFunction\n"); |
if (message) fprintf(stderr," executeFunction\n"); |
OxCritical = 0; |
OxCritical = 0; |
iresult = K0_executeStringByLocalParser(); |
iresult = K0_executeStringByLocalParser(); |
OxCritical = 1; signal(SIGUSR1,controlResetHandler); |
OxCritical = 1; mysignal(SIGUSR1,controlResetHandler); |
if (iresult < 0) { |
if (iresult < 0) { |
emsg = Sm1_popErrorMessage("executeFunction: "); |
emsg = Sm1_popErrorMessage("executeFunction: "); |
Sm1_pushError2(SerialCurrent,-1,emsg); |
Sm1_pushError2(SerialCurrent,-1,emsg); |
Line 285 nullserverCommand(ox_stream ostream) { |
|
Line 314 nullserverCommand(ox_stream ostream) { |
|
} |
} |
break; |
break; |
case SM_popCMO: |
case SM_popCMO: |
if (message) fprintf(stderr,"popCMO. Start to sending data.\n",n); |
if (message) fprintf(stderr,"popCMO. Start to sending data %d\n",n); |
oxSendOXheader(ostream,OX_DATA,SerialOX++); |
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
n=Sm1_popCMO(ostream,SerialCurrent); |
n=Sm1_popCMO(ostreamOut,SerialCurrent); |
if (message) fprintf(stderr,"Done.\n"); |
if (message) fprintf(stderr,"Done.\n"); |
break; |
break; |
case SM_popString: |
case SM_popString: |
if (message) fprintf(stderr,"popString. send data from the stack.\n",n); |
if (message) fprintf(stderr,"popString. send data from the stack %d\n",n); |
oxSendOXheader(ostream,OX_DATA,SerialOX++); |
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
oxSendCmoString(ostream,Sm1_popString()); |
oxSendCmoString(ostreamOut,Sm1_popString()); |
if (message) fprintf(stderr,"Done.\n"); |
if (message) fprintf(stderr,"Done.\n"); |
break; |
break; |
case SM_shutdown: |
case SM_shutdown: |
Line 314 nullserverCommand(ox_stream ostream) { |
|
Line 343 nullserverCommand(ox_stream ostream) { |
|
} |
} |
|
|
|
|
nullserver_simplest(int fd) { |
int nullserver_simplest(int fd) { |
int c; |
int c; |
while(1) { |
while(1) { |
c = readOneByte(fd); |
c = readOneByte(fd); |
if (c == '@') { return; } |
if (c == '@') { return 0; } |
} |
} |
} |
} |
|
|
Line 326 nullserver_simplest(int fd) { |
|
Line 355 nullserver_simplest(int fd) { |
|
void controlResetHandler(sig) |
void controlResetHandler(sig) |
int sig; |
int sig; |
{ |
{ |
signal(sig,SIG_IGN); |
mysignal(sig,SIG_IGN); |
cancelAlarm(); |
cancelAlarm(); |
fprintf(stderr,"From controlResetHandler. OxCritical = %d\n",OxCritical); |
fprintf(stderr,"From controlResetHandler. OxCritical = %d\n",OxCritical); |
OxInterruptFlag = 1; |
OxInterruptFlag = 1; |
if (OxCritical) { |
if (OxCritical) { |
return; |
return; |
}else{ |
}else{ |
|
(void) traceShowStack(); traceClearStack(); |
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
siglongjmp(EnvOfChildServer,2); /* returns 2 for ctrl-C */ |
siglongjmp(EnvOfChildServer,2); /* returns 2 for ctrl-C */ |
#else |
#else |
Line 356 extern int K00_verbose; |
|
Line 386 extern int K00_verbose; |
|
int Startupk2 = 1; |
int Startupk2 = 1; |
|
|
|
|
K0_start() { |
void K0_start() { |
extern int Saki; |
extern int Saki; |
extern int Interactive; |
extern int Interactive; |
int i; |
int i; |
|
|
KSstop(); closing |
KSstop(); closing |
*/ |
*/ |
|
|
K0_executeStringByLocalParser() { |
int K0_executeStringByLocalParser() { |
extern int Interactive; |
extern int Interactive; |
char *s; |
char *s; |
s = Sm1_popString(); |
s = Sm1_popString(); |