[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.3

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.3     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.2 1999/11/02 06:11:58 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:
                    108: int main()
                    109: {
                    110:     MATH_init();
                    111:     initialize_stack();
                    112:
                    113:     signal(SIGUSR1, handler_reset1);
                    114:     signal(SIGKILL, handler_kill);
                    115:
                    116:     /* バイトオーダの決定 */
1.3     ! ohara     117:     decideByteOrderServer(sv_read, 0);
1.1       ohara     118:
                    119:     while(1) {
                    120:         receive_ox(sv_read, sv_write);
                    121:         if(flag_sigusr1) {
                    122:             if (!already_send_ox_sync_ball) {
                    123:               send_ox_sync_ball(sv_write);
                    124:                 already_send_ox_sync_ball = 1;
                    125:             }
                    126:             exchange_ox_syncball(sv_read);
                    127:             flag_sigusr1 = 0;
                    128:             already_send_ox_sync_ball = 0;
                    129:         }
                    130:     }
                    131:     MATH_exit();
                    132: }

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