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

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.17    ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/serv1.c,v 1.16 2000/12/22 04:06:37 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.13      ohara      19: #include "sm.h"
1.1       ohara      20:
1.13      ohara      21: extern OXFILE *stack_oxfp;
1.1       ohara      22:
                     23: /* SM_control_reset_connection */
1.15      ohara      24: static void handler()
1.1       ohara      25: {
1.17    ! ohara      26:        sigset_t newmask, oldmask;
        !            27:        sigemptyset(&newmask);
        !            28:        sigaddset(&newmask, SIGUSR1);
        !            29:        sigprocmask(SIG_SETMASK, &newmask, &oldmask);
1.1       ohara      30:     fprintf(stderr, "signal received.\n");
1.16      ohara      31:     exchange_ox_sync_ball(stack_oxfp);
1.17    ! ohara      32:        sigprocmask(SIG_SETMASK, &oldmask, NULL); /* unmasked. */
1.1       ohara      33: }
                     34:
1.15      ohara      35: static int exchange_ox_sync_ball(OXFILE *oxfp)
1.1       ohara      36: {
                     37:     int tag;
1.15      ohara      38:     send_ox_tag(oxfp, OX_SYNC_BALL);
                     39:     while((tag = receive_ox_tag(oxfp)) != OX_SYNC_BALL) {
1.1       ohara      40:         if (tag == OX_DATA) {
1.15      ohara      41:             receive_cmo(oxfp);
                     42:         }else if (tag == OX_COMMAND) {
                     43:             receive_int32(oxfp);
1.1       ohara      44:         }
                     45:     }
                     46: }
                     47:
1.14      ohara      48: int shutdown()
                     49: {
                     50:     oxf_close(stack_oxfp);
                     51:     ml_exit();
                     52:     exit(0);
                     53: }
                     54:
                     55: #define VERSION 0x11121400
                     56: #define ID_STRING  "2000/11/29"
                     57:
                     58: int main()
                     59: {
                     60:     OXFILE* sv;
                     61:
                     62:     ml_init();
                     63:     mathcap_init(VERSION, ID_STRING, "ox_math", NULL, NULL);
                     64:
                     65:     sv = oxf_open(3);
                     66:     oxf_determine_byteorder_server(sv);
                     67:     sm(sv);
                     68:     shutdown();
                     69: }
                     70:
1.7       ohara      71: /* a part of stack machine. */
1.13      ohara      72: int sm_receive_ox()
1.1       ohara      73: {
                     74:     int tag;
                     75:     int code;
                     76:
1.13      ohara      77:     tag = receive_ox_tag(stack_oxfp);
                     78:     if (oxf_error(stack_oxfp)) {
                     79:         return 0;
                     80:     }
1.1       ohara      81:     switch(tag) {
                     82:     case OX_DATA:
1.13      ohara      83:         push(receive_cmo(stack_oxfp));
1.1       ohara      84:         break;
                     85:     case OX_COMMAND:
1.13      ohara      86:         code = receive_sm_command(stack_oxfp);
                     87:         sm_run(code);
1.1       ohara      88:         break;
                     89:     default:
                     90:         fprintf(stderr, "illeagal message? ox_tag = (%d)\n", tag);
                     91:         break;
                     92:     }
1.13      ohara      93:     return 1;
1.1       ohara      94: }
                     95:
1.13      ohara      96: int sm(OXFILE *oxfp)
                     97: {
1.16      ohara      98:     fd_set fdmask;
1.13      ohara      99:     stack_oxfp = oxfp;
                    100:     stack_extend();
1.16      ohara     101:     signal(SIGUSR1, handler);
                    102:
                    103:     FD_ZERO(&fdmask);
                    104:     FD_SET(oxf_fileno(oxfp), &fdmask);
1.15      ohara     105:
1.16      ohara     106:     while(1) {
                    107:         if (select(2, &fdmask, NULL, NULL, NULL) > 0) {
1.17    ! ohara     108:                        sigset_t newmask, oldmask;
        !           109:                        sigemptyset(&newmask);
        !           110:                        sigaddset(&newmask, SIGUSR1);
        !           111:                        sigprocmask(SIG_SETMASK, &newmask, &oldmask);
1.16      ohara     112:             sm_receive_ox();
1.17    ! ohara     113:                        sigprocmask(SIG_SETMASK, &oldmask, NULL); /* unmasked. */
1.1       ohara     114:         }
                    115:     }
1.13      ohara     116:     fprintf(stderr, "SM: socket(%d) is closed.\n", stack_oxfp->fd);
1.1       ohara     117: }

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