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

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

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