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

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

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