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