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

Annotation of OpenXM/src/ox_math/serv1.c, Revision 1.5

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.5     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.4 1999/11/18 21:56:43 ohara Exp $ */
1.1       ohara       3:
                      4: #include <stdio.h>
                      5: #include <stdlib.h>
                      6: #include <unistd.h>
                      7: #include <signal.h>
                      8: #include <gmp.h>
                      9: #include <mathlink.h>
                     10: #include "ox.h"
                     11: #include "serv2.h"
                     12:
1.2       ohara      13: static int send_ox_sync_ball(int fd);
                     14:
1.1       ohara      15: extern MLINK lp;
                     16: static int sv_read  = 3;
                     17: static int sv_write = 4;
                     18:
                     19: static int flag_sigusr1 = 0;
                     20: static int flag_sigusr2 = 0;
                     21:
                     22: /* 1 のとき割り込み禁止 */
                     23: static int in_critical = 0;
                     24:
                     25: static int set_critical()
                     26: {
                     27:     in_critical = 1;
                     28: }
                     29:
                     30: static int unset_critical()
                     31: {
                     32:     in_critical = 0;
                     33: }
                     34:
                     35: static int critical_p() {
                     36:     return in_critical;
                     37: }
                     38:
                     39: static int already_send_ox_sync_ball = 0;
                     40:
                     41: /* SM_control_reset_connection */
                     42: static int handler_reset1()
                     43: {
                     44:     fprintf(stderr, "signal received.\n");
                     45:     signal(SIGUSR1, handler_reset1);
                     46:     if (!flag_sigusr1) {
                     47:         flag_sigusr1 = 1;
                     48:         if(critical_p()) {
                     49:             send_ox_sync_ball(sv_write);
                     50:             already_send_ox_sync_ball = 1;
                     51:         }
                     52:     }
                     53: }
                     54:
                     55: static int handler_kill()
                     56: {
                     57:     close(3);
                     58:     close(4);
                     59:     exit(1);
                     60: }
                     61:
                     62: static int send_ox_sync_ball(int fd)
                     63: {
                     64:     fprintf(stderr, "sending a sync_ball.\n");
                     65:     send_ox_tag(fd, OX_SYNC_BALL);
                     66: }
                     67:
                     68: static int exchange_ox_syncball(int fd)
                     69: {
                     70:     int tag;
                     71:
                     72:     while((tag = receive_ox_tag(fd)) != OX_SYNC_BALL) {
                     73:         /* skipping a message. */
                     74:         if (tag == OX_DATA) {
                     75:             receive_cmo(fd);
                     76:         }else {
                     77:             receive_int32(fd);
                     78:         }
                     79:     }
                     80:     fprintf(stderr, "received a sync_ball.\n");
                     81: }
                     82:
                     83: /* スタックマシン部分 */
                     84: int receive_ox(int fd_read, int fd_write)
                     85: {
                     86:     int tag;
                     87:     int code;
                     88:
                     89:     tag = receive_ox_tag(fd_read);
                     90:     switch(tag) {
                     91:     case OX_DATA:
                     92:         push(receive_cmo(fd_read));
                     93:         break;
                     94:     case OX_COMMAND:
                     95:         code = receive_sm_command(fd_read);
                     96:         set_critical();
                     97:         execute_sm_command(fd_write, code);
                     98:         unset_critical();
                     99:         break;
                    100:     default:
                    101:         fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag);
                    102:         return -1;
                    103:         break;
                    104:     }
                    105:     return 0;
                    106: }
                    107:
1.4       ohara     108: int shutdown()
                    109: {
                    110:        close(sv_read);
1.5     ! ohara     111:        close(sv_write);
1.4       ohara     112:        MATH_exit();
                    113:        exit(0);
                    114: }
                    115:
1.1       ohara     116: int main()
                    117: {
                    118:     MATH_init();
                    119:     initialize_stack();
                    120:
                    121:     signal(SIGUSR1, handler_reset1);
                    122:     signal(SIGKILL, handler_kill);
                    123:
                    124:     /* バイトオーダの決定 */
1.3       ohara     125:     decideByteOrderServer(sv_read, 0);
1.1       ohara     126:
                    127:     while(1) {
                    128:         receive_ox(sv_read, sv_write);
                    129:         if(flag_sigusr1) {
                    130:             if (!already_send_ox_sync_ball) {
                    131:               send_ox_sync_ball(sv_write);
                    132:                 already_send_ox_sync_ball = 1;
                    133:             }
                    134:             exchange_ox_syncball(sv_read);
                    135:             flag_sigusr1 = 0;
                    136:             already_send_ox_sync_ball = 0;
                    137:         }
                    138:     }
1.4       ohara     139:     shutdown();
1.1       ohara     140: }

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