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