Annotation of OpenXM/src/ox_math/serv1.c, Revision 1.1.1.1
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
2: /* $OpenXM$ */
3: /* $Id: serv1.c,v 1.2 1999/10/14 06:38:16 ohara Exp ohara $ */
4:
5: #include <stdio.h>
6: #include <stdlib.h>
7: #include <unistd.h>
8: #include <signal.h>
9: #include <gmp.h>
10: #include <mathlink.h>
11: #include "ox.h"
12: #include "serv2.h"
13:
14: extern MLINK lp;
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:
107: int main()
108: {
109: MATH_init();
110: initialize_stack();
111:
112: signal(SIGUSR1, handler_reset1);
113: signal(SIGKILL, handler_kill);
114:
115: /* バイトオーダの決定 */
116: decideByteOrder2(sv_read, sv_write, 0);
117:
118: while(1) {
119: receive_ox(sv_read, sv_write);
120: if(flag_sigusr1) {
121: if (!already_send_ox_sync_ball) {
122: send_ox_sync_ball(sv_write);
123: already_send_ox_sync_ball = 1;
124: }
125: exchange_ox_syncball(sv_read);
126: flag_sigusr1 = 0;
127: already_send_ox_sync_ball = 0;
128: }
129: }
130: MATH_exit();
131: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>