[BACK]Return to serv1.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_math

Diff for /OpenXM/src/ox_math/serv1.c between version 1.7 and 1.23

version 1.7, 2000/01/05 06:09:11 version 1.23, 2005/07/26 12:52:04
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C; coding: euc-japan -*- */
 /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.6 1999/11/29 12:09:58 ohara Exp $ */  /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.22 2003/02/13 01:29:38 ohara Exp $ */
   
   /*
      Copyright (C) Katsuyoshi OHARA, 2000.
      Portions copyright 1999 Wolfram Research, Inc.
   
      You must see OpenXM/Copyright/Copyright.generic.
      The MathLink Library is licensed from Wolfram Research Inc..
      See OpenXM/Copyright/Copyright.mathlink for detail.
   */
   
 #include <stdio.h>  #include <stdio.h>
 #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);  extern OXFILE *stack_oxfp;
   
 static int sv_read  = 3;  static int exchange_ox_sync_ball(OXFILE *oxfp)
 static int sv_write = 4;  
   
 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 set_critical()  
 {  {
     in_critical = 1;      int tag;
 }          ox_printf("exchanging OX_SYNC_BALL\n");
       send_ox_tag(oxfp, OX_SYNC_BALL);
 static int unset_critical()      while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) {
 {          if (tag == OX_DATA) {
     in_critical = 0;              receive_cmo(oxfp);
 }          }else if (tag == OX_COMMAND) {
               receive_int32(oxfp);
 static int critical_p() {  
     return in_critical;  
 }  
   
 static int already_send_ox_sync_ball = 0;  
   
 /* SM_control_reset_connection */  
 static int handler_reset1()  
 {  
     fprintf(stderr, "signal received.\n");  
     signal(SIGUSR1, handler_reset1);  
     if (!flag_sigusr1) {  
         flag_sigusr1 = 1;  
         if(critical_p()) {  
             send_ox_sync_ball(sv_write);  
             already_send_ox_sync_ball = 1;  
         }          }
     }      }
 }  }
   
 static int handler_kill()  int shutdown()
 {  {
     close(3);      oxf_close(stack_oxfp);
     close(4);      ml_exit();
     exit(1);      exit(0);
 }  }
   
 static int send_ox_sync_ball(int fd)  /* (Heisei)15/02/01 */
 {  #define VERSION  "2003/02/01"
     fprintf(stderr, "sending a sync_ball.\n");  
     send_ox_tag(fd, OX_SYNC_BALL);  
 }  
   
 static int exchange_ox_syncball(int fd)  int main()
 {  {
     int tag;      OXFILE* sv;
   
     while((tag = receive_ox_tag(fd)) != OX_SYNC_BALL) {      ox_stderr_init(stderr);
         /* skipping a message. */      ml_init();
         if (tag == OX_DATA) {      mathcap_init(VERSION, "ox_math");
             receive_cmo(fd);  
         }else {      sv = oxf_open(3);
             receive_int32(fd);      oxf_determine_byteorder_server(sv);
         }      sm(sv);
     }      shutdown();
     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();          sm_run(code);
         execute_sm_command(fd_write, code);  
         unset_critical();  
         break;          break;
     default:      default:
         fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag);          ox_printf("illeagal OX message(%d)\n", tag);
         return -1;  
         break;          break;
     }      }
     return 0;      return 1;
 }  }
   
 int shutdown()  int sm(OXFILE *oxfp)
 {  {
     close(sv_read);      int i=0;
     close(sv_write);      fd_set fdmask;
     ml_exit();      stack_oxfp = oxfp;
     exit(0);      stack_extend();
 }      sm_siginit();
   
 int main()      FD_ZERO(&fdmask);
 {      FD_SET(oxf_fileno(oxfp), &fdmask);
     ml_init();  
     initialize_stack();  
   
     signal(SIGUSR1, handler_reset1);      for (i=0; ; i++) {
     signal(SIGKILL, handler_kill);          sm_sigunmask();
           ox_printf("phase%d: select\n",i);
     decideByteOrderServer(sv_read, 0);          if (select(5, &fdmask, NULL, NULL, NULL) > 0) {
               sm_sigmask();
     while(1) {              ox_printf("phase%d: receiving\n",i);
         receive_ox(sv_read, sv_write);              sm_receive_ox();
         if(flag_sigusr1) {  
             if (!already_send_ox_sync_ball) {  
               send_ox_sync_ball(sv_write);  
                 already_send_ox_sync_ball = 1;  
             }  
             exchange_ox_syncball(sv_read);  
             flag_sigusr1 = 0;  
             already_send_ox_sync_ball = 0;  
         }          }
           sm_sigmask();
           ox_printf("phase%d: clearing(%d)\n",i,sm_state_interrupting());
           if (sm_state_interrupting()) {
               exchange_ox_sync_ball(stack_oxfp);
               sm_state_clear_interrupting();
           }
     }      }
     shutdown();      ox_printf("ox_math::socket(%d) is closed.\n", stack_oxfp->fd);
 }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.23

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>