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

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

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