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

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.8     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.7 2000/01/05 06:09:11 ohara Exp $ */
        !             3:
        !             4: /*
        !             5:    Copyright (C) Katsuyoshi OHARA, 2000.
        !             6:    Portions copyright 1999 Wolfram Research, Inc.
        !             7:
        !             8:    You must see OpenXM/Copyright/Copyright.generic.
        !             9:    The MathLink Library is licensed from Wolfram Research Inc..
        !            10:    See OpenXM/Copyright/Copyright.mathlink for detail.
        !            11: */
1.1       ohara      12:
                     13: #include <stdio.h>
                     14: #include <stdlib.h>
                     15: #include <unistd.h>
                     16: #include <signal.h>
                     17: #include <gmp.h>
                     18: #include <mathlink.h>
                     19: #include "ox.h"
                     20: #include "serv2.h"
                     21:
1.2       ohara      22: static int send_ox_sync_ball(int fd);
                     23:
1.1       ohara      24: static int sv_read  = 3;
                     25: static int sv_write = 4;
                     26:
                     27: static int flag_sigusr1 = 0;
                     28: static int flag_sigusr2 = 0;
                     29:
1.7       ohara      30: /* if in_critical equals to 1 then we do not permit an interrupt. */
1.1       ohara      31: static int in_critical = 0;
                     32:
                     33: static int set_critical()
                     34: {
                     35:     in_critical = 1;
                     36: }
                     37:
                     38: static int unset_critical()
                     39: {
                     40:     in_critical = 0;
                     41: }
                     42:
                     43: static int critical_p() {
                     44:     return in_critical;
                     45: }
                     46:
                     47: static int already_send_ox_sync_ball = 0;
                     48:
                     49: /* SM_control_reset_connection */
                     50: static int handler_reset1()
                     51: {
                     52:     fprintf(stderr, "signal received.\n");
                     53:     signal(SIGUSR1, handler_reset1);
                     54:     if (!flag_sigusr1) {
                     55:         flag_sigusr1 = 1;
                     56:         if(critical_p()) {
                     57:             send_ox_sync_ball(sv_write);
                     58:             already_send_ox_sync_ball = 1;
                     59:         }
                     60:     }
                     61: }
                     62:
                     63: static int handler_kill()
                     64: {
                     65:     close(3);
                     66:     close(4);
                     67:     exit(1);
                     68: }
                     69:
                     70: static int send_ox_sync_ball(int fd)
                     71: {
                     72:     fprintf(stderr, "sending a sync_ball.\n");
                     73:     send_ox_tag(fd, OX_SYNC_BALL);
                     74: }
                     75:
                     76: static int exchange_ox_syncball(int fd)
                     77: {
                     78:     int tag;
                     79:
                     80:     while((tag = receive_ox_tag(fd)) != OX_SYNC_BALL) {
                     81:         /* skipping a message. */
                     82:         if (tag == OX_DATA) {
                     83:             receive_cmo(fd);
                     84:         }else {
                     85:             receive_int32(fd);
                     86:         }
                     87:     }
                     88:     fprintf(stderr, "received a sync_ball.\n");
                     89: }
                     90:
1.7       ohara      91: /* a part of stack machine. */
1.1       ohara      92: int receive_ox(int fd_read, int fd_write)
                     93: {
                     94:     int tag;
                     95:     int code;
                     96:
                     97:     tag = receive_ox_tag(fd_read);
                     98:     switch(tag) {
                     99:     case OX_DATA:
                    100:         push(receive_cmo(fd_read));
                    101:         break;
                    102:     case OX_COMMAND:
                    103:         code = receive_sm_command(fd_read);
                    104:         set_critical();
                    105:         execute_sm_command(fd_write, code);
                    106:         unset_critical();
                    107:         break;
                    108:     default:
                    109:         fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag);
                    110:         return -1;
                    111:         break;
                    112:     }
                    113:     return 0;
                    114: }
                    115:
1.4       ohara     116: int shutdown()
                    117: {
1.6       ohara     118:     close(sv_read);
                    119:     close(sv_write);
                    120:     ml_exit();
                    121:     exit(0);
1.4       ohara     122: }
                    123:
1.1       ohara     124: int main()
                    125: {
1.6       ohara     126:     ml_init();
1.1       ohara     127:     initialize_stack();
                    128:
                    129:     signal(SIGUSR1, handler_reset1);
                    130:     signal(SIGKILL, handler_kill);
                    131:
1.3       ohara     132:     decideByteOrderServer(sv_read, 0);
1.1       ohara     133:
                    134:     while(1) {
                    135:         receive_ox(sv_read, sv_write);
                    136:         if(flag_sigusr1) {
                    137:             if (!already_send_ox_sync_ball) {
                    138:               send_ox_sync_ball(sv_write);
                    139:                 already_send_ox_sync_ball = 1;
                    140:             }
                    141:             exchange_ox_syncball(sv_read);
                    142:             flag_sigusr1 = 0;
                    143:             already_send_ox_sync_ball = 0;
                    144:         }
                    145:     }
1.4       ohara     146:     shutdown();
1.1       ohara     147: }

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