Annotation of OpenXM_contrib2/asir2000/io/tcpf.c, Revision 1.42
1.10 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.11 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.10 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
1.42 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.41 2003/05/23 00:11:58 noro Exp $
1.10 noro 48: */
1.1 noro 49: #include "ca.h"
50: #include "parse.h"
51: #include "com.h"
52: #include <signal.h>
1.27 noro 53: #include <string.h>
1.1 noro 54: #if !defined(VISUAL)
1.28 noro 55: #include <unistd.h>
1.1 noro 56: #include <sys/types.h>
57: #include <pwd.h>
58: #endif
59: #include "ox.h"
60:
61: #if defined(VISUAL)
1.15 noro 62: #include <stdlib.h>
1.19 noro 63: #include <winsock2.h>
1.15 noro 64: #include <process.h>
1.1 noro 65: #endif
66:
67: #define OX_XTERM "ox_xterm"
68:
69: #if !defined(_PA_RISC1_1)
70: #define RSH "rsh"
71: #else
72: #define RSH "remsh"
73: #endif
74:
75: static struct m_c {
76: int m,c,af_unix;
77: } *m_c_tab;
78:
79: static int m_c_i,m_c_s;
1.16 noro 80: int I_am_server;
1.1 noro 81:
1.39 noro 82: #if defined(MPI)
1.1 noro 83: extern int mpi_nprocs;
84: #define valid_mctab_index(ind)\
1.8 noro 85: if((ind)<0||(ind)>=mpi_nprocs){error("invalid server id");}
1.16 noro 86: #define check_valid_mctab_index(ind)\
87: if((ind)<0||(ind)>=mpi_nprocs){(ind)=-1;}
1.1 noro 88: #else
89: #define valid_mctab_index(ind)\
90: if((ind)<0||(ind)>=m_c_i||\
1.8 noro 91: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){error("invalid server id");}
1.16 noro 92: #define check_valid_mctab_index(ind)\
93: if((ind)<0||(ind)>=m_c_i||\
94: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){(ind)=-1;}
1.1 noro 95: #endif
96:
97: int register_server();
98: int get_mcindex(int);
99:
1.8 noro 100: void Pox_send_raw_cmo(), Pox_recv_raw_cmo();
101:
1.26 noro 102: void Pox_launch(),Pox_launch_nox();
1.1 noro 103: void Pox_launch_generic();
104: void Pox_shutdown();
105:
1.5 noro 106: void Pox_rpc(),Pox_cmo_rpc(),Pox_reset(),Pox_intr(),Pox_sync(),Pox_select();
1.1 noro 107:
108: void Pox_push_local(),Pox_push_cmo(),Pox_push_vl(),Pox_push_cmd();
109:
110: void Pox_pop_local(),Pox_pop_cmo();
111: void Pox_pop0_local(),Pox_pop0_cmo();
112: void Pox_pop_string(),Pox_pop0_string();
113: void Pox_get(),Pox_pops();
114:
115: void Pox_execute_function(),Pox_execute_string();
116: void Pox_setname(), Pox_evalname();
117: void Pox_flush();
118: void Pgenerate_port(),Ptry_bind_listen(),Ptry_connect(),Ptry_accept();
119: void Pregister_server();
120: void Pox_get_serverinfo();
1.8 noro 121: void Pox_mpi_myid(), Pox_mpi_nprocs();
1.42 ! noro 122: void Pnd_exec_f4_red();
1.1 noro 123:
124: void ox_launch_generic();
125:
126: pointer bevalf();
127:
128: struct ftab tcp_tab[] = {
1.8 noro 129: {"ox_send_raw_cmo",Pox_send_raw_cmo,2},
130: {"ox_recv_raw_cmo",Pox_recv_raw_cmo,1},
1.1 noro 131: {"ox_get_serverinfo",Pox_get_serverinfo,-1},
132: {"generate_port",Pgenerate_port,-1},
133: {"try_bind_listen",Ptry_bind_listen,1},
134: {"try_connect",Ptry_connect,2},
135: {"try_accept",Ptry_accept,2},
136: {"register_server",Pregister_server,4},
137: {"ox_flush",Pox_flush,1},
138: {"ox_launch",Pox_launch,-3},
139: {"ox_launch_nox",Pox_launch_nox,-3},
140: {"ox_launch_generic",Pox_launch_generic,7},
141: {"ox_shutdown",Pox_shutdown,1},
142:
143: {"ox_rpc",Pox_rpc,-99999999},
144: {"ox_cmo_rpc",Pox_cmo_rpc,-99999999},
145:
146: {"ox_sync",Pox_sync,1},
1.39 noro 147: #if defined(MPI)
1.8 noro 148: {"ox_mpi_myid",Pox_mpi_myid,0},
149: {"ox_mpi_nprocs",Pox_mpi_nprocs,0},
150: #endif
1.39 noro 151: #if !defined(MPI)
1.1 noro 152: {"ox_reset",Pox_reset,-2},
1.5 noro 153: {"ox_intr",Pox_intr,1},
1.1 noro 154: {"ox_select",Pox_select,-2},
155: #endif
156:
157: {"ox_pop_string",Pox_pop_string,1},
158: {"ox_pop0_string",Pox_pop0_string,1},
159: {"ox_pop_local",Pox_pop_local,1},
160: {"ox_pop0_local",Pox_pop0_local,1},
161: {"ox_pop_cmo",Pox_pop_cmo,1},
162: {"ox_pop0_cmo",Pox_pop0_cmo,1},
1.3 noro 163: {"ox_get",Pox_get,-1},
1.1 noro 164: {"ox_pops",Pox_pops,-2},
165:
166: {"ox_push_vl",Pox_push_vl,1},
167: {"ox_push_local",Pox_push_local,-99999999},
168: {"ox_push_cmo",Pox_push_cmo,-99999999},
169: {"ox_push_cmd",Pox_push_cmd,2},
170:
171: {"ox_setname",Pox_setname,2},
172: {"ox_evalname",Pox_evalname,2},
173:
174: {"ox_execute_string",Pox_execute_string,2},
175: {"ox_execute_function",Pox_execute_function,3},
176:
1.42 ! noro 177: {"nd_exec_f4_red",Pnd_exec_f4_red,0},
! 178:
1.1 noro 179:
180: {0,0,0},
181: };
182:
183: extern struct IOFP iofp[];
184: extern MATHCAP my_mathcap;
1.6 noro 185: extern int ox_exchange_mathcap;
1.1 noro 186:
187: char *getenv();
188:
1.42 ! noro 189: void Pnd_exec_f4_red(Q *rp)
! 190: {
! 191: nd_exec_f4_red_dist();
! 192: *rp = 0;
! 193: }
! 194:
1.39 noro 195: #if defined(MPI)
1.8 noro 196: extern int mpi_myid, mpi_nprocs;
197:
1.26 noro 198: void Pox_mpi_myid(Q *rp)
1.8 noro 199: {
200: STOQ(mpi_myid,*rp);
201: }
202:
1.26 noro 203: void Pox_mpi_nprocs(Q *rp)
1.8 noro 204: {
205: STOQ(mpi_nprocs,*rp);
206: }
207: #endif
208:
1.26 noro 209: void Pox_get_serverinfo(NODE arg,LIST *rp)
1.1 noro 210: {
211: int i,c;
1.24 noro 212: Q s_id;
1.1 noro 213: NODE t,n0,n;
214: LIST list,l;
215:
216: if ( !arg ) {
1.35 noro 217: for ( i = I_am_server?1:0, n0 = 0; i < m_c_i; i++ )
1.8 noro 218: if ( (m_c_tab[i].m>=0) || (m_c_tab[i].c>=0) ) {
1.1 noro 219: c = m_c_tab[i].c;
220: ox_get_serverinfo(c,&list);
1.24 noro 221: STOQ(i,s_id);
222: t = mknode(2,s_id,list);
1.1 noro 223: MKLIST(l,t);
224: NEXTNODE(n0,n);
225: BDY(n) = (pointer)l;
226: }
227: if ( n0 )
228: NEXT(n) = 0;
229: MKLIST(*rp,n0);
230: } else {
231: i = QTOS((Q)ARG0(arg));
1.8 noro 232: if ( i >= 0 && i < m_c_i && ((m_c_tab[i].m>=0) || (m_c_tab[i].c>=0)) )
1.1 noro 233: ox_get_serverinfo(m_c_tab[i].c,rp);
234: else {
235: MKLIST(*rp,0);
236: }
237: }
238: }
239:
240: /*
241: if noarg or arg[0]==0 then use IP socket and return a port number
242: else use UNIX socket and return a string which represents a path name
243: */
244:
1.26 noro 245: void Pgenerate_port(NODE arg,Obj *rp)
1.1 noro 246: {
247: char port_str[BUFSIZ];
248: int port;
249: char *s;
250: STRING str;
251: Q q;
252:
253: if ( !arg || !ARG0(arg) ) {
254: generate_port(0,port_str);
255: port = atoi(port_str);
256: STOQ(port,q);
257: *rp = (Obj)q;
258: } else {
259: generate_port(1,port_str);
1.26 noro 260: s = (char *)MALLOC(strlen((char *)port_str)+1);
1.1 noro 261: strcpy(s,port_str);
262: MKSTR(str,s);
263: *rp = (Obj)str;
264: }
265: }
266:
267: /*
268: try_bind_listen(port)
269: */
270:
1.26 noro 271: void Ptry_bind_listen(NODE arg,Q *rp)
1.1 noro 272: {
273: char port_str[BUFSIZ];
274: int port,s,use_unix;
275:
1.28 noro 276: if ( IS_CYGWIN || !ARG0(arg) || NUM(ARG0(arg)) ) {
1.1 noro 277: port = QTOS((Q)ARG0(arg));
278: sprintf(port_str,"%d",port);
279: use_unix = 0;
280: } else {
281: strcpy(port_str,BDY((STRING)ARG0(arg)));
282: use_unix = 1;
283: }
284: s = try_bind_listen(use_unix,port_str);
285: STOQ(s,*rp);
286: }
287:
288: /*
289: try_connect(host,port)
290: */
291:
1.26 noro 292: void Ptry_connect(NODE arg,Q *rp)
1.1 noro 293: {
294: char port_str[BUFSIZ];
295: char *host;
296: int port,s,use_unix;
297:
1.28 noro 298: if ( IS_CYGWIN || !ARG1(arg) || NUM(ARG1(arg)) ) {
1.1 noro 299: port = QTOS((Q)ARG1(arg));
300: sprintf(port_str,"%d",port);
301: use_unix = 0;
302: } else {
303: strcpy(port_str,BDY((STRING)ARG1(arg)));
304: use_unix = 1;
305: }
306: host = BDY((STRING)ARG0(arg));
307: s = try_connect(use_unix,host,port_str);
308: STOQ(s,*rp);
309: }
310:
311: /*
312: try_accept(sock,port)
313: */
314:
1.26 noro 315: void Ptry_accept(NODE arg,Q *rp)
1.1 noro 316: {
317: int use_unix,s;
318:
1.28 noro 319: if ( IS_CYGWIN || !ARG1(arg) || NUM(ARG1(arg)) )
1.1 noro 320: use_unix = 0;
321: else
322: use_unix = 1;
323: s = try_accept(use_unix,QTOS((Q)ARG0(arg)));
324: STOQ(s,*rp);
325: }
326:
327: /*
328: register_server(cs,cport,ss,sport)
329: */
330:
1.26 noro 331: void Pregister_server(NODE arg,Q *rp)
1.1 noro 332: {
333: int cs,ss,cn,sn,ind,use_unix,id;
334: char cport_str[BUFSIZ],sport_str[BUFSIZ];
1.26 noro 335: Obj obj;
1.1 noro 336: MATHCAP server_mathcap;
337:
338: cs = QTOS((Q)ARG0(arg));
339: ss = QTOS((Q)ARG2(arg));
1.28 noro 340: if ( IS_CYGWIN || !ARG1(arg) || NUM(ARG1(arg)) ) {
1.1 noro 341: sprintf(cport_str,"%d",QTOS((Q)ARG1(arg)));
342: use_unix = 0;
343: } else {
344: strcpy(cport_str,BDY((STRING)ARG1(arg)));
345: use_unix = 1;
346: }
347: if ( !ARG3(arg) || NUM(ARG3(arg)) ) {
348: if ( use_unix )
349: error("register_server : the protocol should conincide for two sockets");
350: sprintf(sport_str,"%d",QTOS((Q)ARG3(arg)));
351: } else {
352: if ( !use_unix )
353: error("register_server : the protocol should conincide for two sockets");
354: strcpy(sport_str,BDY((STRING)ARG3(arg)));
355: }
356:
357: /* client mode */
358: cn = get_iofp(cs,cport_str,0);
359: sn = get_iofp(ss,sport_str,0);
1.12 noro 360: /* get_iofp returns -1 if the laucher could not spawn the server */
361: if ( sn < 0 ) {
362: /* we should terminate the launcher */
363: ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
364: STOQ(-1,*rp);
365: return;
366: }
1.1 noro 367:
368: /* register server to the server list */
369: ind = register_server(use_unix,cn,sn);
370:
1.6 noro 371: if ( ox_exchange_mathcap ) {
372: /* request remote mathcap */
373: ox_send_cmd(sn,SM_mathcap);
374: ox_send_cmd(sn,SM_popCMO);
375: ox_flush_stream_force(sn);
1.26 noro 376: ox_recv(sn,&id,&obj); server_mathcap = (MATHCAP)obj;
1.6 noro 377: store_remote_mathcap(sn,server_mathcap);
378:
379: /* send my mathcap */
380: create_my_mathcap("asir");
381: ox_send_data(sn,my_mathcap);
382: ox_send_cmd(sn,SM_setMathcap);
383: }
1.1 noro 384: /* return the server id */
385: STOQ(ind,*rp);
386: }
387:
388: /*
389: ox_launch_generic(host,launcher,server,use_unix,use_ssh,use_x,conn_to_serv)
390:
391: Input
392: host: hostname on which servers run
393: launcher: path name of the launcher
394: server: path name of the server
395: use_unix: use UNIX domain socket if 1
396: use_ssh: use ssh if 1
397: use_x: use X11 facilities if 1
398: conn_to_serv: connect to server if 1
399: */
400:
1.26 noro 401: void Pox_launch_generic(NODE arg,Q *rp)
1.1 noro 402: {
403: int use_unix,use_ssh,use_x,conn_to_serv;
404: char *host,*launcher,*server;
1.26 noro 405: Q ret;
1.1 noro 406:
407: host = (arg&&ARG0(arg))?BDY((STRING)ARG0(arg)):0;
408: launcher = BDY((STRING)ARG1(arg));
409: server = BDY((STRING)ARG2(arg));
1.28 noro 410: use_unix = !IS_CYGWIN && ARG3(arg) ? 1 : 0;
1.1 noro 411: use_ssh = ARG4(arg) ? 1 : 0;
412: use_x = ARG5(arg) ? 1 : 0;
413: conn_to_serv = QTOS((Q)ARG6(arg));
1.28 noro 414: if ( !IS_CYGWIN && !host )
1.1 noro 415: use_unix = 1;
416: ox_launch_generic(host,launcher,server,
1.26 noro 417: use_unix,use_ssh,use_x,conn_to_serv,&ret);
418: *rp = ret;
1.1 noro 419: }
420:
1.26 noro 421: void ox_launch_generic(char *host,char *launcher,char *server,
422: int use_unix,int use_ssh,int use_x,int conn_to_serv,Q *rp)
1.1 noro 423: {
424: int cs,ss,cn,sn,ind,id;
425: char control_port_str[BUFSIZ];
426: char server_port_str[BUFSIZ];
1.26 noro 427: Obj obj;
1.1 noro 428: MATHCAP server_mathcap;
429:
430: control_port_str[0] = 0;
431: server_port_str[0] = 0;
432: do {
433: generate_port(use_unix,control_port_str);
434: generate_port(use_unix,server_port_str);
435: if ( !conn_to_serv ) {
436: cs = try_bind_listen(use_unix,control_port_str);
1.40 noro 437: if ( cs < 0 ) continue;
1.1 noro 438: ss = try_bind_listen(use_unix,server_port_str);
1.40 noro 439: if ( ss < 0 ) continue;
1.1 noro 440: }
441: spawn_server(host,launcher,server,
442: use_unix,use_ssh,use_x,conn_to_serv,
443: control_port_str,server_port_str);
444: if ( conn_to_serv ) {
445: cs = try_connect(use_unix,host,control_port_str);
1.40 noro 446: if ( cs < 0 ) continue;
1.1 noro 447: ss = try_connect(use_unix,host,server_port_str);
1.40 noro 448: if ( ss < 0 ) continue;
1.1 noro 449: } else {
450: cs = try_accept(use_unix,cs);
1.40 noro 451: if ( cs < 0 ) continue;
1.1 noro 452: ss = try_accept(use_unix,ss);
1.40 noro 453: if ( ss < 0 ) continue;
1.1 noro 454: }
455: } while ( cs < 0 || ss < 0 );
456:
457: /* client mode */
458: cn = get_iofp(cs,control_port_str,0);
459: sn = get_iofp(ss,server_port_str,0);
1.12 noro 460: /* get_iofp returns -1 if the laucher could not spawn the server */
461: if ( sn < 0 ) {
462: /* we should terminate the launcher */
463: ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
464: STOQ(-1,*rp);
465: return;
466: }
1.1 noro 467:
468: /* register server to the server list */
469: ind = register_server(use_unix,cn,sn);
470:
1.6 noro 471: if ( ox_exchange_mathcap ) {
472: /* request remote mathcap */
473: ox_send_cmd(sn,SM_mathcap);
474: ox_send_cmd(sn,SM_popCMO);
475: ox_flush_stream_force(sn);
1.26 noro 476: ox_recv(sn,&id,&obj); server_mathcap = (MATHCAP)obj;
1.6 noro 477: store_remote_mathcap(sn,server_mathcap);
478:
479: /* send my mathcap */
480: create_my_mathcap("asir");
481: ox_send_data(sn,my_mathcap);
482: ox_send_cmd(sn,SM_setMathcap);
483: }
1.1 noro 484: /* return the server id */
485: STOQ(ind,*rp);
486: }
487:
1.28 noro 488: #if defined(__CYGWIN__)
1.29 noro 489: static void bslash2slash(char *buf)
490: {
491: char *p;
492:
493: for ( p = buf; *p; p++ )
494: if ( *p == '\\' )
495: *p = '/';
496: }
497:
1.28 noro 498: static int get_start_path(char *buf)
499: {
500: static char start_path[BUFSIZ];
501: static int start_initialized = 0;
502: char name[BUFSIZ];
503:
504: if ( start_initialized ) {
505: strcpy(buf,start_path);
506: return 1;
507: }
508:
1.32 noro 509: /* Windows98 */
510: strcpy(buf,"c:\\windows\\command\\start.exe");
511: cygwin_conv_to_full_posix_path(buf,name);
512: if ( !access(name,X_OK) ) {
513: bslash2slash(buf);
514: strcpy(start_path,buf);
515: start_initialized = 1;
516: return 1;
517: }
518:
1.28 noro 519: /* Windows2000 */
520: strcpy(buf,"c:\\winnt\\system32\\start.exe");
521: cygwin_conv_to_full_posix_path(buf,name);
522: if ( !access(name,X_OK) ) {
1.29 noro 523: bslash2slash(buf);
1.28 noro 524: strcpy(start_path,buf);
1.32 noro 525: start_initialized = 1;
526: return 1;
527: }
528:
529: strcpy(buf,"c:\\winnt\\system32\\cmd.exe");
530: cygwin_conv_to_full_posix_path(buf,name);
531: if ( !access(name,X_OK) ) {
532: bslash2slash(buf);
533: sprintf(start_path,"%s /c start",buf);
534: strcpy(buf,start_path);
535: start_initialized = 1;
1.28 noro 536: return 1;
537: }
538:
1.32 noro 539: strcpy(buf,"c:\\windows\\system32\\cmd.exe");
1.28 noro 540: cygwin_conv_to_full_posix_path(buf,name);
541: if ( !access(name,X_OK) ) {
1.29 noro 542: bslash2slash(buf);
1.32 noro 543: sprintf(start_path,"%s /c start",buf);
544: strcpy(buf,start_path);
545: start_initialized = 1;
1.28 noro 546: return 1;
547: }
548:
549: return 0;
550: }
551:
552: static void get_launcher_path(char *buf)
553: {
554: static char rootname[BUFSIZ];
555: static char launcher_path[BUFSIZ];
556: static int launcher_initialized = 0;
557: char name[BUFSIZ];
558:
559: if ( launcher_initialized ) {
560: strcpy(buf,launcher_path);
561: return;
562: }
563:
564: get_rootdir(rootname,sizeof(rootname));
565: sprintf(name,"%s/ox_launch.exe",rootname);
566: cygwin_conv_to_full_win32_path(name,launcher_path);
1.29 noro 567: bslash2slash(launcher_path);
1.28 noro 568: launcher_initialized = 1;
569: strcpy(buf,launcher_path);
570: }
571: #endif
572:
1.26 noro 573: void spawn_server(char *host,char *launcher,char *server,
574: int use_unix,int use_ssh,int use_x,int conn_to_serv,
575: char *control_port_str,char *server_port_str)
1.1 noro 576: {
577: char localhost[BUFSIZ];
1.31 noro 578: char *dname,*conn_str,*rsh,*dname0,*asirhost;
1.15 noro 579: char AsirExe[BUFSIZ];
580: STRING rootdir;
581: char prog[BUFSIZ];
582: char *av[BUFSIZ];
1.26 noro 583: #if !defined(VISUAL)
584: char cmd[BUFSIZ];
585: #endif
1.28 noro 586: #if defined(__CYGWIN__)
587: char win_start[BUFSIZ],win_launcher[BUFSIZ];
588: #endif
1.26 noro 589: void Pget_rootdir();
1.1 noro 590:
1.17 noro 591: dname0 = (char *)getenv("DISPLAY");
1.23 noro 592: if ( !dname0 )
593: dname0 = "0";
1.17 noro 594: dname = use_x ? dname0 : 0;
1.1 noro 595: conn_str = conn_to_serv ? "1" : "0";
1.13 noro 596: rsh = getenv("ASIR_RSH");
597: if ( !rsh )
598: rsh = use_ssh ? "ssh" : RSH;
1.25 noro 599: if ( !use_unix && strstr(rsh,"ssh") ) {
1.13 noro 600: /*
601: * if "ssh" is used to invoke a remote server,
602: * we should not specify "-display".
603: */
604: use_ssh = 1;
605: }
1.31 noro 606: asirhost = (char *)getenv("ASIRHOSTNAME");
607: if ( asirhost )
608: strcpy(localhost,asirhost);
609: else
610: gethostname(localhost,BUFSIZ);
1.15 noro 611: #if defined(VISUAL)
612: if ( !use_unix )
613: error("spawn_server : not implemented on Windows");
614: Pget_rootdir(&rootdir);
615: sprintf(AsirExe,"%s\\bin\\engine.exe",BDY(rootdir));
616: strcpy(prog,server);
617: server = strrchr(prog,'/')+1;
618: av[0] = "ox_launch";
619: av[1] = "127.0.0.1";
620: av[2] = conn_str;
621: av[3] = control_port_str;
622: av[4] = server_port_str;
623: av[5] = server;
624: av[6] = use_x ? "1" : "0";
625: av[7] = 0;
626:
627: _spawnv(_P_NOWAIT,AsirExe,av);
628: // _spawnv(_P_NOWAIT,"d:\\home\\noro\\engine2000\\debug\\engine.exe",av);
629: // printf("ox_launch 127.0.0.1 %s %s %s %s 0\n",conn_str,control_port_str,server_port_str,server);
630: #else
1.28 noro 631: if ( use_unix || !host ) {
1.27 noro 632: #if defined(__CYGWIN__)
1.29 noro 633: get_launcher_path(win_launcher);
1.30 noro 634: if ( dname && strchr(dname,':') ) {
635: if ( !fork() ) {
636: setpgid(0,getpid());
637: execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname,
638: "-geometry","60x10","-e",launcher,use_unix?".":"127.1",conn_str,
639: control_port_str,server_port_str,server,dname,0);
640: }
641: } else if ( dname && get_start_path(win_start) ) {
642: sprintf(cmd,"%s %s %s %s %s %s %s 1",
1.29 noro 643: win_start,win_launcher,use_unix?".":"127.1",conn_str,
644: control_port_str,server_port_str,server);
645: system(cmd);
646: } else {
647: if ( !fork() ) {
648: setpgid(0,getpid());
649: execlp(launcher,launcher,use_unix?".":"127.1",conn_str,
650: control_port_str,server_port_str,server,dname0,"-nolog",0);
1.27 noro 651: }
1.29 noro 652: }
1.27 noro 653: #else
1.29 noro 654: if ( !fork() ) {
655: setpgid(0,getpid());
1.28 noro 656: if ( dname )
1.13 noro 657: execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname,
1.28 noro 658: "-geometry","60x10","-e",launcher,use_unix?".":"127.1",conn_str,
1.1 noro 659: control_port_str,server_port_str,server,dname,0);
1.27 noro 660: else
1.28 noro 661: execlp(launcher,launcher,use_unix?".":"127.1",conn_str,
1.17 noro 662: control_port_str,server_port_str,server,dname0,"-nolog",0);
1.1 noro 663: }
1.29 noro 664: #endif
1.1 noro 665: } else if ( conn_to_serv == 2 ) {
666: /* special support for java */
667: if ( dname )
668: sprintf(cmd,
1.13 noro 669: "%s -n %s \"(cd %s; xterm -name %s %s -geometry 60x10 -e java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
1.1 noro 670: rsh,host,launcher,OX_XTERM,dname,server,localhost,control_port_str,server_port_str);
671: else
672: sprintf(cmd,
673: "%s -n %s \"(cd %s; java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
674: rsh,host,launcher,server,localhost,
675: control_port_str,server_port_str,server);
676: fprintf(stderr,"%s\n",cmd);
677: sleep(20);
678: /* system(cmd); */
1.15 noro 679: } else {
1.1 noro 680: if ( dname )
1.13 noro 681: if ( use_ssh )
1.25 noro 682: sprintf(cmd,
1.14 noro 683: "%s -f -n %s \"xterm -name %s -title ox_launch:%s -geometry 60x10 -e %s %s %s %s %s %s %s >&/dev/null\">/dev/null",
1.13 noro 684: rsh,host,OX_XTERM,host,launcher,localhost,conn_str,
685: control_port_str,server_port_str,server,"1");
686: else
1.25 noro 687: sprintf(cmd,
1.14 noro 688: "%s -n %s \"xterm -name %s -title ox_launch:%s -display %s -geometry 60x10 -e %s %s %s %s %s %s %s >&/dev/null&\">/dev/null",
1.13 noro 689: rsh,host,OX_XTERM,host,dname,launcher,localhost,conn_str,
1.1 noro 690: control_port_str,server_port_str,server,dname);
691: else
1.25 noro 692: if ( use_ssh )
693: sprintf(cmd,
694: "%s -f -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
695: rsh,host,launcher,localhost,conn_str,
696: control_port_str,server_port_str,server,"1","-nolog");
697: else
698: sprintf(cmd,
1.17 noro 699: "%s -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
1.1 noro 700: rsh,host,launcher,localhost,conn_str,
1.17 noro 701: control_port_str,server_port_str,server,dname0,"-nolog");
1.1 noro 702: system(cmd);
703: }
1.15 noro 704: #endif /* VISUAL */
1.1 noro 705: }
706:
1.26 noro 707: void Pox_launch(NODE arg,Obj *rp)
1.1 noro 708: {
1.26 noro 709: ox_launch_main(1,arg,rp);
1.1 noro 710: }
711:
1.26 noro 712: void Pox_launch_nox(NODE arg,Obj *rp)
1.1 noro 713: {
1.26 noro 714: ox_launch_main(0,arg,rp);
1.1 noro 715: }
716:
717: /*
718: ox_launch() : invoke local ox_asir
719: ox_launch(0,ox_xxx) : invoke local ox_xxx with asir_libdir/ox_launch
720: ox_launch(remote,lib,ox_xxx) : invoke remote ox_xxx with lib/ox_launch
721: */
722:
1.26 noro 723: void ox_launch_main(int with_x,NODE arg,Obj *p)
1.1 noro 724: {
725: char *str;
1.26 noro 726: char *hostname,*servername;
1.1 noro 727: char *control;
728: int use_unix;
1.26 noro 729: Q ret;
1.1 noro 730: extern char *asir_libdir;
731:
732: if ( arg && ARG0(arg) && argc(arg) != 3 )
733: error("ox_launch : argument mismatch");
734: control = (char *)MALLOC(BUFSIZ);
735: if ( !arg || ( !ARG0(arg) && argc(arg) == 1 ) ) {
736: sprintf(control,"%s/ox_launch",asir_libdir);
1.28 noro 737: use_unix = IS_CYGWIN ? 0 : 1;
1.1 noro 738: servername = (char *)MALLOC(BUFSIZ);
739: sprintf(servername,"%s/ox_asir",asir_libdir);
740: } else if ( !ARG0(arg) && argc(arg) == 2 ) {
741: sprintf(control,"%s/ox_launch",asir_libdir);
1.28 noro 742: use_unix = IS_CYGWIN ? 0 : 1;
1.1 noro 743: str = BDY((STRING)ARG1(arg));
744: if ( str[0] == '/' )
745: servername = str;
746: else {
747: servername = (char *)MALLOC(BUFSIZ);
748: sprintf(servername,"%s/%s",asir_libdir,str);
749: }
750: } else {
751: sprintf(control,"%s/ox_launch",BDY((STRING)ARG1(arg)));
752: if ( !ARG0(arg) )
1.28 noro 753: use_unix = IS_CYGWIN ? 0 : 1;
1.1 noro 754: else
755: use_unix = 0;
756: str = BDY((STRING)ARG2(arg));
757: if ( str[0] == '/' )
758: servername = str;
759: else {
760: servername = (char *)MALLOC(BUFSIZ);
761: sprintf(servername,"%s/%s",BDY((STRING)ARG1(arg)),str);
762: }
763: }
764: if ( arg && ARG0(arg) )
765: hostname = BDY((STRING)ARG0(arg));
766: else
767: hostname = 0;
1.26 noro 768: ox_launch_generic(hostname,control,servername,use_unix,0,with_x,0,&ret);
769: *p = (Obj)ret;
1.1 noro 770: }
771:
1.26 noro 772: int register_server(int af_unix,int m,int c)
1.1 noro 773: {
1.26 noro 774: int s,i;
1.1 noro 775: struct m_c *t;
1.9 noro 776: #define INIT_TAB_SIZ 64
1.1 noro 777:
778: if ( c < 0 )
779: return -1;
780: if ( !m_c_tab ) {
1.9 noro 781: s = INIT_TAB_SIZ*sizeof(struct m_c);
1.8 noro 782: m_c_tab = (struct m_c *)MALLOC_ATOMIC(s);
1.9 noro 783: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 784: m_c_tab[i].af_unix = 0;
785: m_c_tab[i].m = m_c_tab[i].c = -1;
786: }
1.9 noro 787: m_c_s = INIT_TAB_SIZ;
1.1 noro 788: }
1.39 noro 789: #if !defined(MPI)
1.1 noro 790: for ( i = 0; i < m_c_i; i++ )
1.8 noro 791: if ( (m_c_tab[i].m<0) && (m_c_tab[i].c<0) )
1.1 noro 792: break;
793: if ( i < m_c_i ) {
794: m_c_tab[i].m = m; m_c_tab[i].c = c;
795: m_c_tab[i].af_unix = af_unix;
796: return i;
797: }
798: #endif
799: if ( m_c_i == m_c_s ) {
1.9 noro 800: s = (m_c_s+INIT_TAB_SIZ)*sizeof(struct m_c);
1.27 noro 801: t = (struct m_c *)MALLOC_ATOMIC(s); bzero((void *)m_c_tab,s);
802: bcopy((void *)m_c_tab,(void *)t,m_c_s*sizeof(struct m_c));
1.9 noro 803: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 804: m_c_tab[m_c_s+i].af_unix = 0;
805: m_c_tab[m_c_s+i].m = m_c_tab[m_c_s+i].c = -1;
806: }
1.9 noro 807: m_c_s += INIT_TAB_SIZ; m_c_tab = t;
1.1 noro 808: }
809: m_c_tab[m_c_i].m = m; m_c_tab[m_c_i].c = c;
810: m_c_tab[m_c_i].af_unix = af_unix;
811: return m_c_i++;
812: }
813:
814: /* iofp index => m_c_tab index */
815:
1.26 noro 816: int get_mcindex(int i)
1.1 noro 817: {
818: int j;
819:
820: for ( j = 0; j < m_c_i; j++ )
821: if ( m_c_tab[j].c == i )
822: return j;
823: return -1;
824: }
825:
826: /* arg = [ind0,ind1,...]; indk = index to m_c_tab */
827:
1.26 noro 828: void Pox_select(NODE arg,LIST *rp)
1.1 noro 829: {
830: int fd,n,i,index,mcind;
831: fd_set r,w,e;
832: NODE list,t,t1;
833: Q q;
834: double max;
835: struct timeval interval;
836: struct timeval *tvp;
837:
838: list = BDY((LIST)ARG0(arg)); arg = NEXT(arg);
839: if ( arg ) {
840: max = ToReal((Num)BDY(arg));
841: interval.tv_sec = (int)max;
842: interval.tv_usec = (int)((max-(int)max)*1000000);
843: tvp = &interval;
844: } else
845: tvp = 0;
846:
847: FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
848: for ( t = list; t; t = NEXT(t) ) {
849: index = QTOS((Q)BDY(t));
850: valid_mctab_index(index);
1.26 noro 851: fd = get_fd(m_c_tab[index].c); FD_SET((unsigned int)fd,&r);
1.1 noro 852: }
853: n = select(FD_SETSIZE,&r,&w,&e,tvp);
854: for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ )
855: if ( FD_ISSET(i,&r) ) {
856: /* index : index to iofp array */
857: index = get_index(i);
858: /* mcind : index to m_c_tab array */
859: mcind = get_mcindex(index);
860: n--; STOQ(mcind,q); MKNODE(t1,q,t); t = t1;
861: }
862: MKLIST(*rp,t);
863: }
864:
1.26 noro 865: void Pox_flush(NODE arg,Q *rp)
1.1 noro 866: {
867: int index = QTOS((Q)ARG0(arg));
868:
869: valid_mctab_index(index);
870: ox_flush_stream_force(m_c_tab[index].c);
871: *rp = ONE;
872: }
873:
1.26 noro 874: void Pox_send_raw_cmo(NODE arg,Obj *rp)
1.8 noro 875: {
876: int s;
877: int index = QTOS((Q)ARG0(arg));
878:
879: valid_mctab_index(index);
880: s = m_c_tab[index].c;
881: ox_write_cmo(s,(Obj)ARG1(arg));
882: /* flush always */
883: ox_flush_stream(s);
884: *rp = 0;
885: }
886:
1.26 noro 887: void Pox_recv_raw_cmo(NODE arg,Obj *rp)
1.8 noro 888: {
889: int s;
890: int index = QTOS((Q)ARG0(arg));
891:
892: valid_mctab_index(index);
893: s = m_c_tab[index].c;
894: ox_read_cmo(s,rp);
895: }
896:
1.26 noro 897: void Pox_push_local(NODE arg,Obj *rp)
1.1 noro 898: {
899: int s;
900: struct oLIST dummy;
901: VL vl;
1.41 noro 902: int index;
1.1 noro 903:
1.41 noro 904: if ( !arg )
905: error("ox_push_local : too few arguments.");
906: index = QTOS((Q)ARG0(arg));
1.1 noro 907: valid_mctab_index(index);
908: s = m_c_tab[index].c; arg = NEXT(arg);
909:
910: dummy.id = O_LIST; dummy.body = arg;
911: get_vars_recursive((Obj)&dummy,&vl);
912:
913: ox_send_local_ring(s,vl);
914: for ( ; arg; arg = NEXT(arg) )
915: ox_send_local_data(s,BDY(arg));
916: *rp = 0;
917: }
918:
1.26 noro 919: void Pox_push_cmo(NODE arg,Obj *rp)
1.1 noro 920: {
921: int s;
1.41 noro 922: int index;
1.1 noro 923:
1.41 noro 924: if ( !arg )
925: error("ox_push_cmo : too few arguments.");
926: index = QTOS((Q)ARG0(arg));
1.1 noro 927: valid_mctab_index(index);
928: s = m_c_tab[index].c; arg = NEXT(arg);
929: for ( ; arg; arg = NEXT(arg) )
930: ox_send_data(s,BDY(arg));
931: *rp = 0;
932: }
933:
1.26 noro 934: void Pox_push_vl(NODE arg,Obj *rp)
1.1 noro 935: {
936: int index = QTOS((Q)ARG0(arg));
937:
938: valid_mctab_index(index);
939: ox_send_local_ring(m_c_tab[index].c,CO);
940: *rp = 0;
941: }
942:
1.26 noro 943: void Pox_pop_local(NODE arg,Obj *rp)
1.1 noro 944: {
945: int s;
946: int index = QTOS((Q)ARG0(arg));
947:
948: valid_mctab_index(index);
949: s = m_c_tab[index].c;
950: ox_send_cmd(s,SM_popSerializedLocalObject);
951: ox_flush_stream_force(s);
952: ox_get_result(s,rp);
953: }
954:
1.26 noro 955: void Pox_pop_cmo(NODE arg,Obj *rp)
1.1 noro 956: {
957: int s;
958: int index = QTOS((Q)ARG0(arg));
959:
960: valid_mctab_index(index);
961: s = m_c_tab[index].c;
962: ox_send_cmd(s,SM_popCMO);
963: ox_flush_stream_force(s);
964: ox_get_result(s,rp);
965: }
966:
1.26 noro 967: void Pox_pop0_local(NODE arg,Obj *rp)
1.1 noro 968: {
969: int index = QTOS((Q)ARG0(arg));
970:
971: valid_mctab_index(index);
972: ox_send_cmd(m_c_tab[index].c,SM_popSerializedLocalObject);
973: *rp = 0;
974: }
975:
1.26 noro 976: void Pox_pop0_cmo(NODE arg,Obj *rp)
1.1 noro 977: {
978: int index = QTOS((Q)ARG0(arg));
979:
980: valid_mctab_index(index);
981: ox_send_cmd(m_c_tab[index].c,SM_popCMO);
982: *rp = 0;
983: }
984:
1.26 noro 985: void Pox_pop0_string(NODE arg,STRING *rp)
1.1 noro 986: {
987: int index = QTOS((Q)ARG0(arg));
988:
989: valid_mctab_index(index);
990: ox_send_cmd(m_c_tab[index].c,SM_popString);
991: *rp = 0;
992: }
993:
1.26 noro 994: void Pox_pop_string(NODE arg,Obj *rp)
1.1 noro 995: {
1.26 noro 996: int s;
1.1 noro 997: int index = QTOS((Q)ARG0(arg));
998:
999: valid_mctab_index(index);
1000: s = m_c_tab[index].c;
1001: ox_send_cmd(s,SM_popString);
1002: ox_flush_stream_force(s);
1003: ox_get_result(s,rp);
1004: }
1005:
1.26 noro 1006: void Pox_get(NODE arg,Obj *rp)
1.1 noro 1007: {
1.3 noro 1008: int index;
1.1 noro 1009: int s;
1010:
1.3 noro 1011: if ( !arg ) {
1012: /* client->server */
1013: ox_get_result(0,rp);
1014: } else {
1015: /* server->client */
1016: index = QTOS((Q)ARG0(arg));
1017: valid_mctab_index(index);
1018: s = m_c_tab[index].c;
1019: ox_flush_stream_force(s);
1020: ox_get_result(s,rp);
1021: }
1.1 noro 1022: }
1023:
1.26 noro 1024: void Pox_pops(NODE arg,Obj *rp)
1.1 noro 1025: {
1026: int s;
1027: USINT n;
1028: int index = QTOS((Q)ARG0(arg));
1029:
1030: valid_mctab_index(index);
1031: s = m_c_tab[index].c;
1032: if ( NEXT(arg) )
1033: MKUSINT(n,QTOS((Q)ARG1(arg)));
1034: else
1035: MKUSINT(n,1);
1036: ox_send_data(s,n);
1037: ox_send_cmd(s,SM_pops);
1038: *rp = 0;
1039: }
1040:
1.26 noro 1041: void Pox_execute_function(NODE arg,Obj *rp)
1.1 noro 1042: {
1043: int s;
1044: USINT ui;
1045: int index = QTOS((Q)ARG0(arg));
1046:
1047: valid_mctab_index(index);
1048: s = m_c_tab[index].c;
1049: MKUSINT(ui,QTOS((Q)ARG2(arg)));
1050: ox_send_data(s,ui);
1051: ox_send_data(s,ARG1(arg));
1052: ox_send_cmd(s,SM_executeFunction);
1053: *rp = 0;
1054: }
1055:
1.26 noro 1056: void Pox_setname(NODE arg,Obj *rp)
1.1 noro 1057: {
1058: int s;
1059: int index = QTOS((Q)ARG0(arg));
1060:
1061: valid_mctab_index(index);
1062: s = m_c_tab[index].c;
1063: ox_send_data(s,ARG1(arg));
1064: ox_send_cmd(s,SM_setName);
1065: *rp = 0;
1066: }
1067:
1.26 noro 1068: void Pox_evalname(NODE arg,Obj *rp)
1.1 noro 1069: {
1070: int s;
1071: int index = QTOS((Q)ARG0(arg));
1072:
1073: valid_mctab_index(index);
1074: s = m_c_tab[index].c;
1075: ox_send_data(s,ARG1(arg));
1076: ox_send_cmd(s,SM_evalName);
1077: *rp = 0;
1078: }
1079:
1.26 noro 1080: void Pox_execute_string(NODE arg,Obj *rp)
1.1 noro 1081: {
1082: int s;
1083: int index = QTOS((Q)ARG0(arg));
1084:
1085: valid_mctab_index(index);
1086: s = m_c_tab[index].c;
1087: ox_send_data(s,ARG1(arg));
1088: ox_send_cmd(s,SM_executeStringByLocalParser);
1089: *rp = 0;
1090: }
1091:
1092: /* arg=[sid,fname,arg0,arg1,...,arg{n-1}] */
1093:
1.26 noro 1094: void Pox_rpc(NODE arg,Obj *rp)
1.1 noro 1095: {
1096: int s,i,n;
1097: STRING f;
1098: USINT ui;
1099: pointer *w;
1100: NODE t;
1101: int index = QTOS((Q)ARG0(arg));
1102:
1103: valid_mctab_index(index);
1104: s = m_c_tab[index].c; arg = NEXT(arg);
1105: f = (STRING)BDY(arg); arg = NEXT(arg);
1106: ox_send_local_ring(s,CO);
1107: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
1108: w = (pointer *)ALLOCA(n*sizeof(pointer));
1109: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
1110: w[i] = BDY(t);
1111: for ( i = n-1; i >= 0; i-- )
1112: ox_send_local_data(s,w[i]);
1113: MKUSINT(ui,n);
1114: ox_send_data(s,ui);
1115: ox_send_data(s,f);
1116: ox_send_cmd(s,SM_executeFunction);
1117: *rp = 0;
1118: }
1119:
1.26 noro 1120: void Pox_cmo_rpc(NODE arg,Obj *rp)
1.1 noro 1121: {
1122: int s,i,n;
1123: STRING f;
1124: USINT ui;
1125: NODE t;
1126: pointer *w;
1127: int index = QTOS((Q)ARG0(arg));
1128:
1129: valid_mctab_index(index);
1130: s = m_c_tab[index].c; arg = NEXT(arg);
1131: f = (STRING)BDY(arg); arg = NEXT(arg);
1132: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
1133: w = (pointer *)ALLOCA(n*sizeof(pointer));
1134: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
1135: w[i] = BDY(t);
1136: for ( i = n-1; i >= 0; i-- )
1137: ox_send_data(s,w[i]);
1138: MKUSINT(ui,n);
1139: ox_send_data(s,ui);
1140: ox_send_data(s,f);
1141: ox_send_cmd(s,SM_executeFunction);
1142: *rp = 0;
1143: }
1144:
1.26 noro 1145: void Pox_reset(NODE arg,Q *rp)
1.1 noro 1146: {
1147: USINT t;
1.26 noro 1148: int id,c,m;
1.1 noro 1149: Obj obj;
1150: int index = QTOS((Q)ARG0(arg));
1151:
1152: valid_mctab_index(index);
1153: m = m_c_tab[index].m;
1154: c = m_c_tab[index].c;
1155: if ( m >= 0 ) {
1156: if ( argc(arg) == 1 ) {
1157: ox_send_cmd(m,SM_control_reset_connection);
1158: ox_flush_stream_force(m);
1.26 noro 1159: ox_recv(m,&id,&obj); t = (USINT)obj;
1.1 noro 1160: }
1161: *rp = ONE;
1162: #if defined(VISUAL)
1163: Sleep(100);
1164: ox_send_cmd(c,SM_nop);
1165: ox_flush_stream_force(c);
1166: #endif
1167: while ( 1 ) {
1168: ox_recv(c,&id,&obj);
1169: if ( id == OX_SYNC_BALL )
1170: break;
1171: }
1172: ox_send_sync(c);
1.5 noro 1173: } else
1174: *rp = 0;
1175: }
1176:
1.26 noro 1177: void Pox_intr(NODE arg,Q *rp)
1.5 noro 1178: {
1179: int m;
1180: int index = QTOS((Q)ARG0(arg));
1181:
1182: valid_mctab_index(index);
1183: m = m_c_tab[index].m;
1184: if ( m >= 0 ) {
1185: if ( argc(arg) == 1 ) {
1186: ox_send_cmd(m,SM_control_intr);
1187: ox_flush_stream_force(m);
1188: }
1189: *rp = ONE;
1.1 noro 1190: } else
1191: *rp = 0;
1192: }
1193:
1.26 noro 1194: void Pox_sync(NODE arg,Q *rp)
1.1 noro 1195: {
1196: int c;
1197: int index = QTOS((Q)ARG0(arg));
1198:
1199: valid_mctab_index(index);
1200: c = m_c_tab[index].c;
1201: ox_send_sync(c);
1202: *rp = 0;
1203: }
1204:
1.26 noro 1205: void Pox_shutdown(NODE arg,Q *rp)
1.1 noro 1206: {
1207: int s;
1208: int index = QTOS((Q)ARG0(arg));
1.26 noro 1209: #if !defined(VISUAL)
1.1 noro 1210: int status;
1.26 noro 1211: #endif
1.1 noro 1212:
1213: valid_mctab_index(index);
1214: s = m_c_tab[index].m;
1215: ox_send_cmd(s,SM_shutdown);
1216: free_iofp(s);
1.18 noro 1217: s = m_c_tab[index].c;
1218: free_iofp(s);
1.39 noro 1219: #if !defined(MPI) && !defined(VISUAL)
1.1 noro 1220: if ( m_c_tab[index].af_unix )
1221: wait(&status);
1222: #endif
1.8 noro 1223: m_c_tab[index].m = -1; m_c_tab[index].c = -1;
1.1 noro 1224: m_c_tab[index].af_unix = 0;
1225: *rp = 0;
1226: }
1227:
1.26 noro 1228: void Pox_push_cmd(NODE arg,Q *rp)
1.1 noro 1229: {
1.7 noro 1230: int ui;
1.1 noro 1231: int index = QTOS((Q)ARG0(arg));
1232:
1233: valid_mctab_index(index);
1.7 noro 1234: ui = QTOS((Q)ARG1(arg));
1.1 noro 1235: ox_send_cmd(m_c_tab[index].c,ui);
1236: *rp = 0;
1237: }
1.16 noro 1238:
1239: void shutdown_all() {
1240: int s;
1241: int i,index;
1.26 noro 1242: #if !defined(VISUAL)
1.16 noro 1243: int status;
1.26 noro 1244: #endif
1.16 noro 1245:
1246: for ( i = I_am_server?1:0; i < m_c_i; i++ ) {
1247: index = i;
1248: check_valid_mctab_index(index);
1249: if ( index < 0 )
1250: continue;
1251: s = m_c_tab[index].m;
1252: ox_send_cmd(s,SM_shutdown);
1.21 noro 1253: #if defined(VISUAL)
1254: Sleep(1000);
1255: #endif
1.16 noro 1256: free_iofp(s);
1.18 noro 1257: s = m_c_tab[index].c;
1258: free_iofp(s);
1.39 noro 1259: #if !defined(MPI) && !defined(VISUAL)
1.16 noro 1260: if ( m_c_tab[index].af_unix )
1261: wait(&status);
1262: #endif
1263: m_c_tab[index].m = 0; m_c_tab[index].c = 0;
1264: m_c_tab[index].af_unix = 0;
1265: }
1.33 noro 1266: }
1267:
1268: char *ox_get_servername(int);
1269:
1270: int is_ox_plot(int index)
1271: {
1272: char *name;
1273:
1274: check_valid_mctab_index(index);
1275: if ( index < 0 )
1276: return 0;
1277: /* m : client, c : server ??? */
1278: name = ox_get_servername(m_c_tab[index].c);
1279: return strcmp(name,"ox_plot") ? 0 : 1;
1280: }
1281:
1282: int validate_ox_plot_stream(int index)
1283: {
1284: int i;
1285: NODE arg;
1286: STRING name;
1287: Obj r;
1288:
1289: if ( is_ox_plot(index) )
1290: return index;
1291: for ( i = 0; i < m_c_i; i++ )
1292: if ( is_ox_plot(i) )
1293: return i;
1294:
1295: /* create an ox_plot server */
1296: MKSTR(name,"ox_plot");
1297: arg = mknode(2,0,name);
1298: Pox_launch_nox(arg,&r);
1.34 noro 1299: i = QTOS((Q)r);
1300: #if defined(VISUAL)
1301: Sleep(100);
1302: ox_send_cmd(m_c_tab[i].c,SM_nop);
1303: ox_flush_stream_force(m_c_tab[i].c);
1304: #endif
1305: return i;
1.42 ! noro 1306: }
! 1307:
! 1308: int get_ox_server_id(int index)
! 1309: {
! 1310: valid_mctab_index(index);
! 1311: return m_c_tab[index].c;
1.16 noro 1312: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>