Annotation of OpenXM_contrib2/asir2000/io/tcpf.c, Revision 1.23
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.23 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.22 2000/12/05 01:24:55 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>
53: #if !defined(VISUAL)
54: #include <sys/types.h>
55: #include <pwd.h>
56: #endif
57: #include "ox.h"
58:
59: #if defined(VISUAL)
1.15 noro 60: #include <stdlib.h>
1.19 noro 61: #include <winsock2.h>
1.15 noro 62: #include <process.h>
1.1 noro 63: #endif
64:
65: #define OX_XTERM "ox_xterm"
66:
67: #if !defined(_PA_RISC1_1)
68: #define RSH "rsh"
69: #else
70: #define RSH "remsh"
71: #endif
72:
73: static struct m_c {
74: int m,c,af_unix;
75: } *m_c_tab;
76:
77: static int m_c_i,m_c_s;
1.16 noro 78: int I_am_server;
1.1 noro 79:
80: #if MPI
81: extern int mpi_nprocs;
82: #define valid_mctab_index(ind)\
1.8 noro 83: if((ind)<0||(ind)>=mpi_nprocs){error("invalid server id");}
1.16 noro 84: #define check_valid_mctab_index(ind)\
85: if((ind)<0||(ind)>=mpi_nprocs){(ind)=-1;}
1.1 noro 86: #else
87: #define valid_mctab_index(ind)\
88: if((ind)<0||(ind)>=m_c_i||\
1.8 noro 89: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){error("invalid server id");}
1.16 noro 90: #define check_valid_mctab_index(ind)\
91: if((ind)<0||(ind)>=m_c_i||\
92: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){(ind)=-1;}
1.1 noro 93: #endif
94:
95: int register_server();
96: int get_mcindex(int);
97:
1.8 noro 98: void Pox_send_raw_cmo(), Pox_recv_raw_cmo();
99:
1.1 noro 100: void Pox_launch(),Pox_launch_nox(),Pox_launch_main();
101: void Pox_launch_generic();
102: void Pox_shutdown();
103:
1.5 noro 104: void Pox_rpc(),Pox_cmo_rpc(),Pox_reset(),Pox_intr(),Pox_sync(),Pox_select();
1.1 noro 105:
106: void Pox_push_local(),Pox_push_cmo(),Pox_push_vl(),Pox_push_cmd();
107:
108: void Pox_pop_local(),Pox_pop_cmo();
109: void Pox_pop0_local(),Pox_pop0_cmo();
110: void Pox_pop_string(),Pox_pop0_string();
111: void Pox_get(),Pox_pops();
112:
113: void Pox_execute_function(),Pox_execute_string();
114: void Pox_setname(), Pox_evalname();
115: void Pox_flush();
116: void Pgenerate_port(),Ptry_bind_listen(),Ptry_connect(),Ptry_accept();
117: void Pregister_server();
118: void Pox_get_serverinfo();
1.8 noro 119: void Pox_mpi_myid(), Pox_mpi_nprocs();
1.1 noro 120:
121: void ox_launch_generic();
122:
123: pointer bevalf();
124:
125: struct ftab tcp_tab[] = {
1.8 noro 126: {"ox_send_raw_cmo",Pox_send_raw_cmo,2},
127: {"ox_recv_raw_cmo",Pox_recv_raw_cmo,1},
1.1 noro 128: {"ox_get_serverinfo",Pox_get_serverinfo,-1},
129: {"generate_port",Pgenerate_port,-1},
130: {"try_bind_listen",Ptry_bind_listen,1},
131: {"try_connect",Ptry_connect,2},
132: {"try_accept",Ptry_accept,2},
133: {"register_server",Pregister_server,4},
134: {"ox_flush",Pox_flush,1},
135: {"ox_launch",Pox_launch,-3},
136: {"ox_launch_nox",Pox_launch_nox,-3},
137: {"ox_launch_generic",Pox_launch_generic,7},
138: {"ox_shutdown",Pox_shutdown,1},
139:
140: {"ox_rpc",Pox_rpc,-99999999},
141: {"ox_cmo_rpc",Pox_cmo_rpc,-99999999},
142:
143: {"ox_sync",Pox_sync,1},
1.8 noro 144: #if MPI
145: {"ox_mpi_myid",Pox_mpi_myid,0},
146: {"ox_mpi_nprocs",Pox_mpi_nprocs,0},
147: #endif
1.1 noro 148: #if !MPI
149: {"ox_reset",Pox_reset,-2},
1.5 noro 150: {"ox_intr",Pox_intr,1},
1.1 noro 151: {"ox_select",Pox_select,-2},
152: #endif
153:
154: {"ox_pop_string",Pox_pop_string,1},
155: {"ox_pop0_string",Pox_pop0_string,1},
156: {"ox_pop_local",Pox_pop_local,1},
157: {"ox_pop0_local",Pox_pop0_local,1},
158: {"ox_pop_cmo",Pox_pop_cmo,1},
159: {"ox_pop0_cmo",Pox_pop0_cmo,1},
1.3 noro 160: {"ox_get",Pox_get,-1},
1.1 noro 161: {"ox_pops",Pox_pops,-2},
162:
163: {"ox_push_vl",Pox_push_vl,1},
164: {"ox_push_local",Pox_push_local,-99999999},
165: {"ox_push_cmo",Pox_push_cmo,-99999999},
166: {"ox_push_cmd",Pox_push_cmd,2},
167:
168: {"ox_setname",Pox_setname,2},
169: {"ox_evalname",Pox_evalname,2},
170:
171: {"ox_execute_string",Pox_execute_string,2},
172: {"ox_execute_function",Pox_execute_function,3},
173:
174:
175: {0,0,0},
176: };
177:
178: extern struct IOFP iofp[];
179: extern MATHCAP my_mathcap;
1.6 noro 180: extern int ox_exchange_mathcap;
1.1 noro 181:
182: char *getenv();
183:
1.8 noro 184: #if MPI
185: extern int mpi_myid, mpi_nprocs;
186:
187: void Pox_mpi_myid(rp)
188: Q *rp;
189: {
190: STOQ(mpi_myid,*rp);
191: }
192:
193: void Pox_mpi_nprocs(rp)
194: Q *rp;
195: {
196: STOQ(mpi_nprocs,*rp);
197: }
198: #endif
199:
1.1 noro 200: void Pox_get_serverinfo(arg,rp)
201: NODE arg;
202: LIST *rp;
203: {
204: int i,c;
205: Q sid;
206: NODE t,n0,n;
207: LIST list,l;
208:
209: if ( !arg ) {
210: for ( i = 0, n0 = 0; i < m_c_i; i++ )
1.8 noro 211: if ( (m_c_tab[i].m>=0) || (m_c_tab[i].c>=0) ) {
1.1 noro 212: c = m_c_tab[i].c;
213: ox_get_serverinfo(c,&list);
214: STOQ(i,sid);
215: t = mknode(2,sid,list);
216: MKLIST(l,t);
217: NEXTNODE(n0,n);
218: BDY(n) = (pointer)l;
219: }
220: if ( n0 )
221: NEXT(n) = 0;
222: MKLIST(*rp,n0);
223: } else {
224: i = QTOS((Q)ARG0(arg));
1.8 noro 225: if ( i >= 0 && i < m_c_i && ((m_c_tab[i].m>=0) || (m_c_tab[i].c>=0)) )
1.1 noro 226: ox_get_serverinfo(m_c_tab[i].c,rp);
227: else {
228: MKLIST(*rp,0);
229: }
230: }
231: }
232:
233: /*
234: if noarg or arg[0]==0 then use IP socket and return a port number
235: else use UNIX socket and return a string which represents a path name
236: */
237:
238: void Pgenerate_port(arg,rp)
239: NODE arg;
240: Obj *rp;
241: {
242: char port_str[BUFSIZ];
243: int port;
244: char *s;
245: STRING str;
246: Q q;
247:
248: if ( !arg || !ARG0(arg) ) {
249: generate_port(0,port_str);
250: port = atoi(port_str);
251: STOQ(port,q);
252: *rp = (Obj)q;
253: } else {
254: generate_port(1,port_str);
255: s = (char *)MALLOC(strlen(port_str)+1);
256: strcpy(s,port_str);
257: MKSTR(str,s);
258: *rp = (Obj)str;
259: }
260: }
261:
262: /*
263: try_bind_listen(port)
264: */
265:
266: void Ptry_bind_listen(arg,rp)
267: NODE arg;
268: Q *rp;
269: {
270: char port_str[BUFSIZ];
271: int port,s,use_unix;
272:
273: if ( !ARG0(arg) || NUM(ARG0(arg)) ) {
274: port = QTOS((Q)ARG0(arg));
275: sprintf(port_str,"%d",port);
276: use_unix = 0;
277: } else {
278: strcpy(port_str,BDY((STRING)ARG0(arg)));
279: use_unix = 1;
280: }
281: s = try_bind_listen(use_unix,port_str);
282: STOQ(s,*rp);
283: }
284:
285: /*
286: try_connect(host,port)
287: */
288:
289: void Ptry_connect(arg,rp)
290: NODE arg;
291: Q *rp;
292: {
293: char port_str[BUFSIZ];
294: char *host;
295: int port,s,use_unix;
296:
297: if ( !ARG1(arg) || NUM(ARG1(arg)) ) {
298: port = QTOS((Q)ARG1(arg));
299: sprintf(port_str,"%d",port);
300: use_unix = 0;
301: } else {
302: strcpy(port_str,BDY((STRING)ARG1(arg)));
303: use_unix = 1;
304: }
305: host = BDY((STRING)ARG0(arg));
306: s = try_connect(use_unix,host,port_str);
307: STOQ(s,*rp);
308: }
309:
310: /*
311: try_accept(sock,port)
312: */
313:
314: void Ptry_accept(arg,rp)
315: NODE arg;
316: Q *rp;
317: {
318: int use_unix,s;
319:
320: if ( !ARG1(arg) || NUM(ARG1(arg)) )
321: use_unix = 0;
322: else
323: use_unix = 1;
324: s = try_accept(use_unix,QTOS((Q)ARG0(arg)));
325: STOQ(s,*rp);
326: }
327:
328: /*
329: register_server(cs,cport,ss,sport)
330: */
331:
332: void Pregister_server(arg,rp)
333: NODE arg;
334: Q *rp;
335: {
336: int cs,ss,cn,sn,ind,use_unix,id;
337: char cport_str[BUFSIZ],sport_str[BUFSIZ];
338: MATHCAP server_mathcap;
339:
340: cs = QTOS((Q)ARG0(arg));
341: ss = QTOS((Q)ARG2(arg));
342: if ( !ARG1(arg) || NUM(ARG1(arg)) ) {
343: sprintf(cport_str,"%d",QTOS((Q)ARG1(arg)));
344: use_unix = 0;
345: } else {
346: strcpy(cport_str,BDY((STRING)ARG1(arg)));
347: use_unix = 1;
348: }
349: if ( !ARG3(arg) || NUM(ARG3(arg)) ) {
350: if ( use_unix )
351: error("register_server : the protocol should conincide for two sockets");
352: sprintf(sport_str,"%d",QTOS((Q)ARG3(arg)));
353: } else {
354: if ( !use_unix )
355: error("register_server : the protocol should conincide for two sockets");
356: strcpy(sport_str,BDY((STRING)ARG3(arg)));
357: }
358:
359: /* client mode */
360: cn = get_iofp(cs,cport_str,0);
361: sn = get_iofp(ss,sport_str,0);
1.12 noro 362: /* get_iofp returns -1 if the laucher could not spawn the server */
363: if ( sn < 0 ) {
364: /* we should terminate the launcher */
365: ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
366: STOQ(-1,*rp);
367: return;
368: }
1.1 noro 369:
370: /* register server to the server list */
371: ind = register_server(use_unix,cn,sn);
372:
1.6 noro 373: if ( ox_exchange_mathcap ) {
374: /* request remote mathcap */
375: ox_send_cmd(sn,SM_mathcap);
376: ox_send_cmd(sn,SM_popCMO);
377: ox_flush_stream_force(sn);
378: ox_recv(sn,&id,&server_mathcap);
379: store_remote_mathcap(sn,server_mathcap);
380:
381: /* send my mathcap */
382: create_my_mathcap("asir");
383: ox_send_data(sn,my_mathcap);
384: ox_send_cmd(sn,SM_setMathcap);
385: }
1.1 noro 386: /* return the server id */
387: STOQ(ind,*rp);
388: }
389:
390: /*
391: ox_launch_generic(host,launcher,server,use_unix,use_ssh,use_x,conn_to_serv)
392:
393: Input
394: host: hostname on which servers run
395: launcher: path name of the launcher
396: server: path name of the server
397: use_unix: use UNIX domain socket if 1
398: use_ssh: use ssh if 1
399: use_x: use X11 facilities if 1
400: conn_to_serv: connect to server if 1
401: */
402:
403: void Pox_launch_generic(arg,rp)
404: NODE arg;
405: Q *rp;
406: {
407: int use_unix,use_ssh,use_x,conn_to_serv;
408: char *host,*launcher,*server;
409:
410: host = (arg&&ARG0(arg))?BDY((STRING)ARG0(arg)):0;
411: launcher = BDY((STRING)ARG1(arg));
412: server = BDY((STRING)ARG2(arg));
413: use_unix = ARG3(arg) ? 1 : 0;
414: use_ssh = ARG4(arg) ? 1 : 0;
415: use_x = ARG5(arg) ? 1 : 0;
416: conn_to_serv = QTOS((Q)ARG6(arg));
417: if ( !host )
418: use_unix = 1;
419: ox_launch_generic(host,launcher,server,
420: use_unix,use_ssh,use_x,conn_to_serv,rp);
421: }
422:
423: void ox_launch_generic(host,launcher,server,
424: use_unix,use_ssh,use_x,conn_to_serv,rp)
425: char *host,*launcher,*server;
426: int use_unix,use_ssh,use_x,conn_to_serv;
427: Q *rp;
428: {
429: int cs,ss,cn,sn,ind,id;
430: char control_port_str[BUFSIZ];
431: char server_port_str[BUFSIZ];
432: MATHCAP server_mathcap;
433:
434: control_port_str[0] = 0;
435: server_port_str[0] = 0;
436: do {
437: generate_port(use_unix,control_port_str);
438: generate_port(use_unix,server_port_str);
439: if ( !conn_to_serv ) {
440: cs = try_bind_listen(use_unix,control_port_str);
441: ss = try_bind_listen(use_unix,server_port_str);
442: }
443: spawn_server(host,launcher,server,
444: use_unix,use_ssh,use_x,conn_to_serv,
445: control_port_str,server_port_str);
446: if ( conn_to_serv ) {
447: cs = try_connect(use_unix,host,control_port_str);
448: ss = try_connect(use_unix,host,server_port_str);
449: } else {
450: cs = try_accept(use_unix,cs);
451: ss = try_accept(use_unix,ss);
452: }
453: } while ( cs < 0 || ss < 0 );
454:
455: /* client mode */
456: cn = get_iofp(cs,control_port_str,0);
457: sn = get_iofp(ss,server_port_str,0);
1.12 noro 458: /* get_iofp returns -1 if the laucher could not spawn the server */
459: if ( sn < 0 ) {
460: /* we should terminate the launcher */
461: ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
462: STOQ(-1,*rp);
463: return;
464: }
1.1 noro 465:
466: /* register server to the server list */
467: ind = register_server(use_unix,cn,sn);
468:
1.6 noro 469: if ( ox_exchange_mathcap ) {
470: /* request remote mathcap */
471: ox_send_cmd(sn,SM_mathcap);
472: ox_send_cmd(sn,SM_popCMO);
473: ox_flush_stream_force(sn);
474: ox_recv(sn,&id,&server_mathcap);
475: store_remote_mathcap(sn,server_mathcap);
476:
477: /* send my mathcap */
478: create_my_mathcap("asir");
479: ox_send_data(sn,my_mathcap);
480: ox_send_cmd(sn,SM_setMathcap);
481: }
1.1 noro 482: /* return the server id */
483: STOQ(ind,*rp);
484: }
485:
486: int spawn_server(host,launcher,server,
487: use_unix,use_ssh,use_x,conn_to_serv,
488: control_port_str,server_port_str)
489: char *host,*launcher,*server;
490: int use_unix,use_ssh,use_x,conn_to_serv;
491: char *control_port_str,*server_port_str;
492: {
493: char cmd[BUFSIZ];
494: char localhost[BUFSIZ];
1.17 noro 495: char *dname,*conn_str,*rsh,*dname0;
1.13 noro 496: char dname_str[BUFSIZ];
1.15 noro 497: char AsirExe[BUFSIZ];
498: STRING rootdir;
499: char prog[BUFSIZ];
500: char *av[BUFSIZ];
1.1 noro 501:
1.17 noro 502: dname0 = (char *)getenv("DISPLAY");
1.23 ! noro 503: if ( !dname0 )
! 504: dname0 = "0";
1.17 noro 505: dname = use_x ? dname0 : 0;
1.1 noro 506: conn_str = conn_to_serv ? "1" : "0";
1.13 noro 507: rsh = getenv("ASIR_RSH");
508: if ( !rsh )
509: rsh = use_ssh ? "ssh" : RSH;
510: if ( !use_unix && dname && strstr(rsh,"ssh") ) {
511: /*
512: * if "ssh" is used to invoke a remote server,
513: * we should not specify "-display".
514: */
515: use_ssh = 1;
516: }
1.1 noro 517: gethostname(localhost,BUFSIZ);
1.15 noro 518: #if defined(VISUAL)
519: if ( !use_unix )
520: error("spawn_server : not implemented on Windows");
521: Pget_rootdir(&rootdir);
522: sprintf(AsirExe,"%s\\bin\\engine.exe",BDY(rootdir));
523: strcpy(prog,server);
524: server = strrchr(prog,'/')+1;
525: av[0] = "ox_launch";
526: av[1] = "127.0.0.1";
527: av[2] = conn_str;
528: av[3] = control_port_str;
529: av[4] = server_port_str;
530: av[5] = server;
531: av[6] = use_x ? "1" : "0";
532: av[7] = 0;
533:
534: _spawnv(_P_NOWAIT,AsirExe,av);
535: // _spawnv(_P_NOWAIT,"d:\\home\\noro\\engine2000\\debug\\engine.exe",av);
536: // printf("ox_launch 127.0.0.1 %s %s %s %s 0\n",conn_str,control_port_str,server_port_str,server);
537: #else
1.1 noro 538: if ( use_unix ) {
539: if ( !fork() ) {
1.2 noro 540: setpgid(0,getpid());
1.1 noro 541: if ( dname )
1.13 noro 542: execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname,
1.1 noro 543: "-geometry","60x10","-e",launcher,".",conn_str,
544: control_port_str,server_port_str,server,dname,0);
545: else
546: execlp(launcher,launcher,".",conn_str,
1.17 noro 547: control_port_str,server_port_str,server,dname0,"-nolog",0);
1.1 noro 548: }
549: } else if ( conn_to_serv == 2 ) {
550: /* special support for java */
551: if ( dname )
552: sprintf(cmd,
1.13 noro 553: "%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 554: rsh,host,launcher,OX_XTERM,dname,server,localhost,control_port_str,server_port_str);
555: else
556: sprintf(cmd,
557: "%s -n %s \"(cd %s; java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
558: rsh,host,launcher,server,localhost,
559: control_port_str,server_port_str,server);
560: fprintf(stderr,"%s\n",cmd);
561: sleep(20);
562: /* system(cmd); */
1.15 noro 563: } else {
1.1 noro 564: if ( dname )
1.13 noro 565: if ( use_ssh )
566: sprintf(cmd,
1.14 noro 567: "%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 568: rsh,host,OX_XTERM,host,launcher,localhost,conn_str,
569: control_port_str,server_port_str,server,"1");
570: else
1.1 noro 571: sprintf(cmd,
1.14 noro 572: "%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 573: rsh,host,OX_XTERM,host,dname,launcher,localhost,conn_str,
1.1 noro 574: control_port_str,server_port_str,server,dname);
575: else
576: sprintf(cmd,
1.17 noro 577: "%s -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
1.1 noro 578: rsh,host,launcher,localhost,conn_str,
1.17 noro 579: control_port_str,server_port_str,server,dname0,"-nolog");
1.1 noro 580: system(cmd);
581: }
1.15 noro 582: #endif /* VISUAL */
1.1 noro 583: }
584:
585: void Pox_launch(arg,rp)
586: NODE arg;
587: Obj *rp;
588: {
589: Pox_launch_main(1,arg,rp);
590: }
591:
592: void Pox_launch_nox(arg,rp)
593: NODE arg;
594: Obj *rp;
595: {
596: Pox_launch_main(0,arg,rp);
597: }
598:
599: /*
600: ox_launch() : invoke local ox_asir
601: ox_launch(0,ox_xxx) : invoke local ox_xxx with asir_libdir/ox_launch
602: ox_launch(remote,lib,ox_xxx) : invoke remote ox_xxx with lib/ox_launch
603: */
604:
605: void Pox_launch_main(with_x,arg,rp)
606: int with_x;
607: NODE arg;
608: Obj *rp;
609: {
610: char *str;
611: char *hostname,*servername,*dname;
612: char *control;
613: int use_unix;
614: extern char *asir_libdir;
615:
616: if ( arg && ARG0(arg) && argc(arg) != 3 )
617: error("ox_launch : argument mismatch");
618: control = (char *)MALLOC(BUFSIZ);
619: if ( !arg || ( !ARG0(arg) && argc(arg) == 1 ) ) {
620: sprintf(control,"%s/ox_launch",asir_libdir);
621: use_unix = 1;
622: servername = (char *)MALLOC(BUFSIZ);
623: sprintf(servername,"%s/ox_asir",asir_libdir);
624: } else if ( !ARG0(arg) && argc(arg) == 2 ) {
625: sprintf(control,"%s/ox_launch",asir_libdir);
626: use_unix = 1;
627: str = BDY((STRING)ARG1(arg));
628: if ( str[0] == '/' )
629: servername = str;
630: else {
631: servername = (char *)MALLOC(BUFSIZ);
632: sprintf(servername,"%s/%s",asir_libdir,str);
633: }
634: } else {
635: sprintf(control,"%s/ox_launch",BDY((STRING)ARG1(arg)));
636: if ( !ARG0(arg) )
637: use_unix = 1;
638: else
639: use_unix = 0;
640: str = BDY((STRING)ARG2(arg));
641: if ( str[0] == '/' )
642: servername = str;
643: else {
644: servername = (char *)MALLOC(BUFSIZ);
645: sprintf(servername,"%s/%s",BDY((STRING)ARG1(arg)),str);
646: }
647: }
648: if ( arg && ARG0(arg) )
649: hostname = BDY((STRING)ARG0(arg));
650: else
651: hostname = 0;
652: ox_launch_generic(hostname,control,servername,use_unix,0,with_x,0,rp);
653: }
654:
655: int register_server(af_unix,m,c)
656: int af_unix,m,c;
657: {
658: int s,i,ci;
659: struct m_c *t;
1.9 noro 660: #define INIT_TAB_SIZ 64
1.1 noro 661:
662: if ( c < 0 )
663: return -1;
664: if ( !m_c_tab ) {
1.9 noro 665: s = INIT_TAB_SIZ*sizeof(struct m_c);
1.8 noro 666: m_c_tab = (struct m_c *)MALLOC_ATOMIC(s);
1.9 noro 667: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 668: m_c_tab[i].af_unix = 0;
669: m_c_tab[i].m = m_c_tab[i].c = -1;
670: }
1.9 noro 671: m_c_s = INIT_TAB_SIZ;
1.1 noro 672: }
673: #if !MPI
674: for ( i = 0; i < m_c_i; i++ )
1.8 noro 675: if ( (m_c_tab[i].m<0) && (m_c_tab[i].c<0) )
1.1 noro 676: break;
677: if ( i < m_c_i ) {
678: m_c_tab[i].m = m; m_c_tab[i].c = c;
679: m_c_tab[i].af_unix = af_unix;
680: return i;
681: }
682: #endif
683: if ( m_c_i == m_c_s ) {
1.9 noro 684: s = (m_c_s+INIT_TAB_SIZ)*sizeof(struct m_c);
1.1 noro 685: t = (struct m_c *)MALLOC_ATOMIC(s); bzero(m_c_tab,s);
686: bcopy(m_c_tab,t,m_c_s*sizeof(struct m_c));
1.9 noro 687: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 688: m_c_tab[m_c_s+i].af_unix = 0;
689: m_c_tab[m_c_s+i].m = m_c_tab[m_c_s+i].c = -1;
690: }
1.9 noro 691: m_c_s += INIT_TAB_SIZ; m_c_tab = t;
1.1 noro 692: }
693: m_c_tab[m_c_i].m = m; m_c_tab[m_c_i].c = c;
694: m_c_tab[m_c_i].af_unix = af_unix;
695: return m_c_i++;
696: }
697:
698: /* iofp index => m_c_tab index */
699:
700: int get_mcindex(i)
701: int i;
702: {
703: int j;
704:
705: for ( j = 0; j < m_c_i; j++ )
706: if ( m_c_tab[j].c == i )
707: return j;
708: return -1;
709: }
710:
711: /* arg = [ind0,ind1,...]; indk = index to m_c_tab */
712:
713: void Pox_select(arg,rp)
714: NODE arg;
715: LIST *rp;
716: {
717: int fd,n,i,index,mcind;
718: fd_set r,w,e;
719: NODE list,t,t1;
720: Q q;
721: double max;
722: struct timeval interval;
723: struct timeval *tvp;
724:
725: list = BDY((LIST)ARG0(arg)); arg = NEXT(arg);
726: if ( arg ) {
727: max = ToReal((Num)BDY(arg));
728: interval.tv_sec = (int)max;
729: interval.tv_usec = (int)((max-(int)max)*1000000);
730: tvp = &interval;
731: } else
732: tvp = 0;
733:
734: FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
735: for ( t = list; t; t = NEXT(t) ) {
736: index = QTOS((Q)BDY(t));
737: valid_mctab_index(index);
738: fd = get_fd(m_c_tab[index].c); FD_SET(fd,&r);
739: }
740: n = select(FD_SETSIZE,&r,&w,&e,tvp);
741: for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ )
742: if ( FD_ISSET(i,&r) ) {
743: /* index : index to iofp array */
744: index = get_index(i);
745: /* mcind : index to m_c_tab array */
746: mcind = get_mcindex(index);
747: n--; STOQ(mcind,q); MKNODE(t1,q,t); t = t1;
748: }
749: MKLIST(*rp,t);
750: }
751:
752: void Pox_flush(arg,rp)
753: NODE arg;
754: Q *rp;
755: {
756: int index = QTOS((Q)ARG0(arg));
757:
758: valid_mctab_index(index);
759: ox_flush_stream_force(m_c_tab[index].c);
760: *rp = ONE;
761: }
762:
1.8 noro 763: void Pox_send_raw_cmo(arg,rp)
764: NODE arg;
765: Obj *rp;
766: {
767: int s;
768: int index = QTOS((Q)ARG0(arg));
769:
770: valid_mctab_index(index);
771: s = m_c_tab[index].c;
772: ox_write_cmo(s,(Obj)ARG1(arg));
773: /* flush always */
774: ox_flush_stream(s);
775: *rp = 0;
776: }
777:
778: void Pox_recv_raw_cmo(arg,rp)
779: NODE arg;
780: Obj *rp;
781: {
782: int s;
783: int index = QTOS((Q)ARG0(arg));
784:
785: valid_mctab_index(index);
786: s = m_c_tab[index].c;
787: ox_read_cmo(s,rp);
788: }
789:
1.1 noro 790: void Pox_push_local(arg,rp)
791: NODE arg;
792: Obj *rp;
793: {
794: int s;
795: struct oLIST dummy;
796: VL vl;
797: int index = QTOS((Q)ARG0(arg));
798:
799: valid_mctab_index(index);
800: s = m_c_tab[index].c; arg = NEXT(arg);
801:
802: dummy.id = O_LIST; dummy.body = arg;
803: get_vars_recursive((Obj)&dummy,&vl);
804:
805: ox_send_local_ring(s,vl);
806: for ( ; arg; arg = NEXT(arg) )
807: ox_send_local_data(s,BDY(arg));
808: *rp = 0;
809: }
810:
811: void Pox_push_cmo(arg,rp)
812: NODE arg;
813: Obj *rp;
814: {
815: int s;
816: int index = QTOS((Q)ARG0(arg));
817:
818: valid_mctab_index(index);
819: s = m_c_tab[index].c; arg = NEXT(arg);
820: for ( ; arg; arg = NEXT(arg) )
821: ox_send_data(s,BDY(arg));
822: *rp = 0;
823: }
824:
825: void Pox_push_vl(arg,rp)
826: NODE arg;
827: Obj *rp;
828: {
829: int s;
830: int index = QTOS((Q)ARG0(arg));
831:
832: valid_mctab_index(index);
833: ox_send_local_ring(m_c_tab[index].c,CO);
834: *rp = 0;
835: }
836:
837: void Pox_pop_local(arg,rp)
838: NODE arg;
839: Obj *rp;
840: {
841: int s;
842: int index = QTOS((Q)ARG0(arg));
843:
844: valid_mctab_index(index);
845: s = m_c_tab[index].c;
846: ox_send_cmd(s,SM_popSerializedLocalObject);
847: ox_flush_stream_force(s);
848: ox_get_result(s,rp);
849: }
850:
851: void Pox_pop_cmo(arg,rp)
852: NODE arg;
853: Obj *rp;
854: {
855: int s;
856: int index = QTOS((Q)ARG0(arg));
857:
858: valid_mctab_index(index);
859: s = m_c_tab[index].c;
860: ox_send_cmd(s,SM_popCMO);
861: ox_flush_stream_force(s);
862: ox_get_result(s,rp);
863: }
864:
865: void Pox_pop0_local(arg,rp)
866: NODE arg;
867: Obj *rp;
868: {
869: int index = QTOS((Q)ARG0(arg));
870:
871: valid_mctab_index(index);
872: ox_send_cmd(m_c_tab[index].c,SM_popSerializedLocalObject);
873: *rp = 0;
874: }
875:
876: void Pox_pop0_cmo(arg,rp)
877: NODE arg;
878: Obj *rp;
879: {
880: int index = QTOS((Q)ARG0(arg));
881:
882: valid_mctab_index(index);
883: ox_send_cmd(m_c_tab[index].c,SM_popCMO);
884: *rp = 0;
885: }
886:
887: void Pox_pop0_string(arg,rp)
888: NODE arg;
889: STRING *rp;
890: {
891: int index = QTOS((Q)ARG0(arg));
892:
893: valid_mctab_index(index);
894: ox_send_cmd(m_c_tab[index].c,SM_popString);
895: *rp = 0;
896: }
897:
898: void Pox_pop_string(arg,rp)
899: NODE arg;
900: STRING *rp;
901: {
902: int s,id;
903: int index = QTOS((Q)ARG0(arg));
904:
905: valid_mctab_index(index);
906: s = m_c_tab[index].c;
907: ox_send_cmd(s,SM_popString);
908: ox_flush_stream_force(s);
909: ox_get_result(s,rp);
910: }
911:
912: void Pox_get(arg,rp)
913: NODE arg;
914: Obj *rp;
915: {
1.3 noro 916: int index;
1.1 noro 917: int s;
918:
1.3 noro 919: if ( !arg ) {
920: /* client->server */
921: ox_get_result(0,rp);
922: } else {
923: /* server->client */
924: index = QTOS((Q)ARG0(arg));
925: valid_mctab_index(index);
926: s = m_c_tab[index].c;
927: ox_flush_stream_force(s);
928: ox_get_result(s,rp);
929: }
1.1 noro 930: }
931:
932: void Pox_pops(arg,rp)
933: NODE arg;
934: Obj *rp;
935: {
936: int s;
937: USINT n;
938: int index = QTOS((Q)ARG0(arg));
939:
940: valid_mctab_index(index);
941: s = m_c_tab[index].c;
942: if ( NEXT(arg) )
943: MKUSINT(n,QTOS((Q)ARG1(arg)));
944: else
945: MKUSINT(n,1);
946: ox_send_data(s,n);
947: ox_send_cmd(s,SM_pops);
948: *rp = 0;
949: }
950:
951: void Pox_execute_function(arg,rp)
952: NODE arg;
953: Obj *rp;
954: {
955: int s;
956: USINT ui;
957: int index = QTOS((Q)ARG0(arg));
958:
959: valid_mctab_index(index);
960: s = m_c_tab[index].c;
961: MKUSINT(ui,QTOS((Q)ARG2(arg)));
962: ox_send_data(s,ui);
963: ox_send_data(s,ARG1(arg));
964: ox_send_cmd(s,SM_executeFunction);
965: *rp = 0;
966: }
967:
968: void Pox_setname(arg,rp)
969: NODE arg;
970: Obj *rp;
971: {
972: int s;
973: int index = QTOS((Q)ARG0(arg));
974:
975: valid_mctab_index(index);
976: s = m_c_tab[index].c;
977: ox_send_data(s,ARG1(arg));
978: ox_send_cmd(s,SM_setName);
979: *rp = 0;
980: }
981:
982: void Pox_evalname(arg,rp)
983: NODE arg;
984: Obj *rp;
985: {
986: int s;
987: int index = QTOS((Q)ARG0(arg));
988:
989: valid_mctab_index(index);
990: s = m_c_tab[index].c;
991: ox_send_data(s,ARG1(arg));
992: ox_send_cmd(s,SM_evalName);
993: *rp = 0;
994: }
995:
996: void Pox_execute_string(arg,rp)
997: NODE arg;
998: Obj *rp;
999: {
1000: int s;
1001: int index = QTOS((Q)ARG0(arg));
1002:
1003: valid_mctab_index(index);
1004: s = m_c_tab[index].c;
1005: ox_send_data(s,ARG1(arg));
1006: ox_send_cmd(s,SM_executeStringByLocalParser);
1007: *rp = 0;
1008: }
1009:
1010: /* arg=[sid,fname,arg0,arg1,...,arg{n-1}] */
1011:
1012: void Pox_rpc(arg,rp)
1013: NODE arg;
1014: Obj *rp;
1015: {
1016: int s,i,n;
1017: STRING f;
1018: USINT ui;
1019: pointer *w;
1020: NODE t;
1021: int index = QTOS((Q)ARG0(arg));
1022:
1023: valid_mctab_index(index);
1024: s = m_c_tab[index].c; arg = NEXT(arg);
1025: f = (STRING)BDY(arg); arg = NEXT(arg);
1026: ox_send_local_ring(s,CO);
1027: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
1028: w = (pointer *)ALLOCA(n*sizeof(pointer));
1029: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
1030: w[i] = BDY(t);
1031: for ( i = n-1; i >= 0; i-- )
1032: ox_send_local_data(s,w[i]);
1033: MKUSINT(ui,n);
1034: ox_send_data(s,ui);
1035: ox_send_data(s,f);
1036: ox_send_cmd(s,SM_executeFunction);
1037: *rp = 0;
1038: }
1039:
1040: void Pox_cmo_rpc(arg,rp)
1041: NODE arg;
1042: Obj *rp;
1043: {
1044: int s,i,n;
1045: STRING f;
1046: USINT ui;
1047: NODE t;
1048: pointer *w;
1049: int index = QTOS((Q)ARG0(arg));
1050:
1051: valid_mctab_index(index);
1052: s = m_c_tab[index].c; arg = NEXT(arg);
1053: f = (STRING)BDY(arg); arg = NEXT(arg);
1054: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
1055: w = (pointer *)ALLOCA(n*sizeof(pointer));
1056: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
1057: w[i] = BDY(t);
1058: for ( i = n-1; i >= 0; i-- )
1059: ox_send_data(s,w[i]);
1060: MKUSINT(ui,n);
1061: ox_send_data(s,ui);
1062: ox_send_data(s,f);
1063: ox_send_cmd(s,SM_executeFunction);
1064: *rp = 0;
1065: }
1066:
1067: void Pox_reset(arg,rp)
1068: NODE arg;
1069: Q *rp;
1070: {
1071: USINT t;
1072: int s,id,c,m;
1073: Obj obj;
1074: int index = QTOS((Q)ARG0(arg));
1075:
1076: valid_mctab_index(index);
1077: m = m_c_tab[index].m;
1078: c = m_c_tab[index].c;
1079: if ( m >= 0 ) {
1080: if ( argc(arg) == 1 ) {
1081: ox_send_cmd(m,SM_control_reset_connection);
1082: ox_flush_stream_force(m);
1083: ox_recv(m,&id,&t);
1084: }
1085: *rp = ONE;
1086: #if defined(VISUAL)
1087: Sleep(100);
1088: ox_send_cmd(c,SM_nop);
1089: ox_flush_stream_force(c);
1090: #endif
1091: while ( 1 ) {
1092: ox_recv(c,&id,&obj);
1093: if ( id == OX_SYNC_BALL )
1094: break;
1095: }
1096: ox_send_sync(c);
1.5 noro 1097: } else
1098: *rp = 0;
1099: }
1100:
1101: void Pox_intr(arg,rp)
1102: NODE arg;
1103: Q *rp;
1104: {
1105: int m;
1106: Obj obj;
1107: int index = QTOS((Q)ARG0(arg));
1108:
1109: valid_mctab_index(index);
1110: m = m_c_tab[index].m;
1111: if ( m >= 0 ) {
1112: if ( argc(arg) == 1 ) {
1113: ox_send_cmd(m,SM_control_intr);
1114: ox_flush_stream_force(m);
1115: }
1116: *rp = ONE;
1.1 noro 1117: } else
1118: *rp = 0;
1119: }
1120:
1121: void Pox_sync(arg,rp)
1122: NODE arg;
1123: Q *rp;
1124: {
1125: int c;
1126: int index = QTOS((Q)ARG0(arg));
1127:
1128: valid_mctab_index(index);
1129: c = m_c_tab[index].c;
1130: ox_send_sync(c);
1131: *rp = 0;
1132: }
1133:
1134: void Pox_shutdown(arg,rp)
1135: NODE arg;
1136: Q *rp;
1137: {
1138: int s;
1139: int index = QTOS((Q)ARG0(arg));
1140: int status;
1141:
1142: valid_mctab_index(index);
1143: s = m_c_tab[index].m;
1144: ox_send_cmd(s,SM_shutdown);
1145: free_iofp(s);
1.18 noro 1146: #if !defined(VISUAL)
1147: s = m_c_tab[index].c;
1148: free_iofp(s);
1149: #endif
1.1 noro 1150: #if !MPI && !defined(VISUAL)
1151: if ( m_c_tab[index].af_unix )
1152: wait(&status);
1153: #endif
1.8 noro 1154: m_c_tab[index].m = -1; m_c_tab[index].c = -1;
1.1 noro 1155: m_c_tab[index].af_unix = 0;
1156: *rp = 0;
1157: }
1158:
1159: void Pox_push_cmd(arg,rp)
1160: NODE arg;
1161: Q *rp;
1162: {
1.7 noro 1163: int ui;
1.1 noro 1164: int index = QTOS((Q)ARG0(arg));
1165:
1166: valid_mctab_index(index);
1.7 noro 1167: ui = QTOS((Q)ARG1(arg));
1.1 noro 1168: ox_send_cmd(m_c_tab[index].c,ui);
1169: *rp = 0;
1170: }
1.16 noro 1171:
1172: void shutdown_all() {
1173: int s;
1174: int i,index;
1175: int status;
1176:
1177: for ( i = I_am_server?1:0; i < m_c_i; i++ ) {
1178: index = i;
1179: check_valid_mctab_index(index);
1180: if ( index < 0 )
1181: continue;
1182: s = m_c_tab[index].m;
1183: ox_send_cmd(s,SM_shutdown);
1.21 noro 1184: #if defined(VISUAL)
1185: Sleep(1000);
1186: #endif
1.16 noro 1187: free_iofp(s);
1.18 noro 1188: #if !defined(VISUAL)
1189: s = m_c_tab[index].c;
1190: free_iofp(s);
1191: #endif
1.16 noro 1192: #if !MPI && !defined(VISUAL)
1193: if ( m_c_tab[index].af_unix )
1194: wait(&status);
1195: #endif
1196: m_c_tab[index].m = 0; m_c_tab[index].c = 0;
1197: m_c_tab[index].af_unix = 0;
1198: }
1199: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>