[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.13 and 1.18

version 1.13, 2000/12/03 21:46:52 version 1.18, 2002/04/11 19:53:40
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C; coding: euc-japan -*- */
 /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.12 2000/12/03 15:19:23 ohara Exp $ */  /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.17 2002/04/11 14:13:37 ohara Exp $ */
   
 /*  /*
    Copyright (C) Katsuyoshi OHARA, 2000.     Copyright (C) Katsuyoshi OHARA, 2000.
Line 18 
Line 18 
 #include <ox_toolkit.h>  #include <ox_toolkit.h>
 #include "sm.h"  #include "sm.h"
   
 static int send_ox_sync_ball();  
   
 extern OXFILE *stack_oxfp;  extern OXFILE *stack_oxfp;
   
 static int flag_sigusr1 = 0;  /* SM_control_reset_connection */
 static int flag_sigusr2 = 0;  static void handler()
   
 /* 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;          sigset_t newmask, oldmask;
           sigemptyset(&newmask);
           sigaddset(&newmask, SIGUSR1);
           sigprocmask(SIG_SETMASK, &newmask, &oldmask);
       fprintf(stderr, "signal received.\n");
       exchange_ox_sync_ball(stack_oxfp);
           sigprocmask(SIG_SETMASK, &oldmask, NULL); /* unmasked. */
 }  }
   
 static int unset_critical()  static int exchange_ox_sync_ball(OXFILE *oxfp)
 {  {
     in_critical = 0;      int tag;
 }      send_ox_tag(oxfp, OX_SYNC_BALL);
       while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) {
 static int critical_p() {          if (tag == OX_DATA) {
     return in_critical;              receive_cmo(oxfp);
 }          }else if (tag == OX_COMMAND) {
               receive_int32(oxfp);
 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();  
             already_send_ox_sync_ball = 1;  
         }          }
     }      }
 }  }
   
 static int handler_kill()  int shutdown()
 {  {
     oxf_close(stack_oxfp);      oxf_close(stack_oxfp);
     exit(1);      ml_exit();
       exit(0);
 }  }
   
 static int send_ox_sync_ball()  #define VERSION 0x11121400
 {  #define ID_STRING  "2000/11/29"
     fprintf(stderr, "sending a sync_ball.\n");  
     send_ox_tag(stack_oxfp, OX_SYNC_BALL);  
 }  
   
 static int exchange_ox_syncball()  int main()
 {  {
     int tag;      OXFILE* sv;
   
     while((tag = receive_ox_tag(stack_oxfp)) != OX_SYNC_BALL) {      ml_init();
         /* skipping a message. */      mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL);
         if (tag == OX_DATA) {  
             receive_cmo(stack_oxfp);      sv = oxf_open(3);
         }else {      oxf_determine_byteorder_server(sv);
             receive_int32(stack_oxfp);      sm(sv);
         }      shutdown();
     }  
     fprintf(stderr, "received a sync_ball.\n");  
 }  }
   
 /* a part of stack machine. */  /* a part of stack machine. */
Line 101  int sm_receive_ox()
Line 84  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(stderr, "illeagal message? ox_tag = (%d)\n", tag);
         return 0;  
         break;          break;
     }      }
     return 1;      return 1;
 }  }
   
 int shutdown()  
 {  
     oxf_close(stack_oxfp);  
     ml_exit();  
     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()  
 {  
     OXFILE* sv;  
   
     ml_init();  
     mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL);  
   
     signal(SIGUSR1, handler_reset1);  
     signal(SIGKILL, handler_kill);  
   
     sv = oxf_open(3);  
     oxf_determine_byteorder_server(sv);  
     sm(sv);  
     shutdown();  
 }  
   
 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_syncball();          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(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd);

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.18

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