Annotation of OpenXM_contrib2/asir2000/io/tcpf.c, Revision 1.56
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.56 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.55 2004/06/15 09:04:41 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.43 noro 82: extern int little_endian;
83:
1.39 noro 84: #if defined(MPI)
1.1 noro 85: extern int mpi_nprocs;
86: #define valid_mctab_index(ind)\
1.8 noro 87: if((ind)<0||(ind)>=mpi_nprocs){error("invalid server id");}
1.16 noro 88: #define check_valid_mctab_index(ind)\
89: if((ind)<0||(ind)>=mpi_nprocs){(ind)=-1;}
1.1 noro 90: #else
91: #define valid_mctab_index(ind)\
1.54 noro 92: if((ind)<I_am_server||(ind)>=m_c_i||\
1.8 noro 93: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){error("invalid server id");}
1.16 noro 94: #define check_valid_mctab_index(ind)\
1.54 noro 95: if((ind)<I_am_server||(ind)>=m_c_i||\
1.16 noro 96: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){(ind)=-1;}
1.1 noro 97: #endif
98:
1.44 noro 99: struct IOFP iofp_102[MAXIOFP];
100: int nserver_102;
101: int myrank_102;
1.43 noro 102:
103: int register_102(int s,int rank, int is_master);
104:
1.1 noro 105: int register_server();
106: int get_mcindex(int);
107:
1.8 noro 108: void Pox_send_raw_cmo(), Pox_recv_raw_cmo();
109:
1.26 noro 110: void Pox_launch(),Pox_launch_nox();
1.1 noro 111: void Pox_launch_generic();
112: void Pox_shutdown();
113:
1.5 noro 114: void Pox_rpc(),Pox_cmo_rpc(),Pox_reset(),Pox_intr(),Pox_sync(),Pox_select();
1.1 noro 115:
116: void Pox_push_local(),Pox_push_cmo(),Pox_push_vl(),Pox_push_cmd();
117:
118: void Pox_pop_local(),Pox_pop_cmo();
119: void Pox_pop0_local(),Pox_pop0_cmo();
120: void Pox_pop_string(),Pox_pop0_string();
121: void Pox_get(),Pox_pops();
122:
123: void Pox_execute_function(),Pox_execute_string();
124: void Pox_setname(), Pox_evalname();
125: void Pox_flush();
126: void Pgenerate_port(),Ptry_bind_listen(),Ptry_connect(),Ptry_accept();
127: void Pregister_server();
128: void Pox_get_serverinfo();
1.8 noro 129: void Pox_mpi_myid(), Pox_mpi_nprocs();
1.42 noro 130: void Pnd_exec_f4_red();
1.44 noro 131: void Pox_tcp_accept_102(),Pox_tcp_connect_102();
132: void Pox_send_102(),Pox_recv_102();
133: void Pox_set_rank_102();
1.49 noro 134: void Pox_get_rank_102();
1.44 noro 135: void Pox_reset_102();
1.46 noro 136: void Pox_bcast_102();
1.47 noro 137: void Pox_reduce_102();
1.1 noro 138:
139: void ox_launch_generic();
140:
141: pointer bevalf();
142:
143: struct ftab tcp_tab[] = {
1.8 noro 144: {"ox_send_raw_cmo",Pox_send_raw_cmo,2},
145: {"ox_recv_raw_cmo",Pox_recv_raw_cmo,1},
1.1 noro 146: {"ox_get_serverinfo",Pox_get_serverinfo,-1},
147: {"generate_port",Pgenerate_port,-1},
1.44 noro 148:
1.45 noro 149: /* from master to client */
1.44 noro 150: {"ox_set_rank_102",Pox_set_rank_102,3},
1.45 noro 151: {"ox_tcp_accept_102",Pox_tcp_accept_102,3},
152: {"ox_tcp_connect_102",Pox_tcp_connect_102,4},
153: {"ox_reset_102",Pox_reset_102,1},
1.44 noro 154:
1.49 noro 155: {"ox_get_rank_102",Pox_get_rank_102,0},
1.44 noro 156: {"ox_send_102",Pox_send_102,2},
157: {"ox_recv_102",Pox_recv_102,1},
1.46 noro 158: {"ox_bcast_102",Pox_bcast_102,-2},
1.48 noro 159: {"ox_reduce_102",Pox_reduce_102,-3},
1.44 noro 160:
1.1 noro 161: {"try_bind_listen",Ptry_bind_listen,1},
162: {"try_connect",Ptry_connect,2},
163: {"try_accept",Ptry_accept,2},
164: {"register_server",Pregister_server,4},
165: {"ox_flush",Pox_flush,1},
166: {"ox_launch",Pox_launch,-3},
167: {"ox_launch_nox",Pox_launch_nox,-3},
168: {"ox_launch_generic",Pox_launch_generic,7},
169: {"ox_shutdown",Pox_shutdown,1},
170:
171: {"ox_rpc",Pox_rpc,-99999999},
172: {"ox_cmo_rpc",Pox_cmo_rpc,-99999999},
173:
174: {"ox_sync",Pox_sync,1},
1.39 noro 175: #if defined(MPI)
1.8 noro 176: {"ox_mpi_myid",Pox_mpi_myid,0},
177: {"ox_mpi_nprocs",Pox_mpi_nprocs,0},
178: #endif
1.39 noro 179: #if !defined(MPI)
1.1 noro 180: {"ox_reset",Pox_reset,-2},
1.5 noro 181: {"ox_intr",Pox_intr,1},
1.1 noro 182: {"ox_select",Pox_select,-2},
183: #endif
184:
185: {"ox_pop_string",Pox_pop_string,1},
186: {"ox_pop0_string",Pox_pop0_string,1},
187: {"ox_pop_local",Pox_pop_local,1},
188: {"ox_pop0_local",Pox_pop0_local,1},
189: {"ox_pop_cmo",Pox_pop_cmo,1},
190: {"ox_pop0_cmo",Pox_pop0_cmo,1},
1.3 noro 191: {"ox_get",Pox_get,-1},
1.1 noro 192: {"ox_pops",Pox_pops,-2},
193:
194: {"ox_push_vl",Pox_push_vl,1},
195: {"ox_push_local",Pox_push_local,-99999999},
196: {"ox_push_cmo",Pox_push_cmo,-99999999},
197: {"ox_push_cmd",Pox_push_cmd,2},
198:
199: {"ox_setname",Pox_setname,2},
200: {"ox_evalname",Pox_evalname,2},
201:
202: {"ox_execute_string",Pox_execute_string,2},
203: {"ox_execute_function",Pox_execute_function,3},
204:
1.42 noro 205: {"nd_exec_f4_red",Pnd_exec_f4_red,0},
206:
1.1 noro 207:
208: {0,0,0},
209: };
210:
211: extern struct IOFP iofp[];
212: extern MATHCAP my_mathcap;
1.6 noro 213: extern int ox_exchange_mathcap;
1.1 noro 214:
215: char *getenv();
216:
1.42 noro 217: void Pnd_exec_f4_red(Q *rp)
218: {
219: nd_exec_f4_red_dist();
220: *rp = 0;
221: }
222:
1.39 noro 223: #if defined(MPI)
1.8 noro 224: extern int mpi_myid, mpi_nprocs;
225:
1.26 noro 226: void Pox_mpi_myid(Q *rp)
1.8 noro 227: {
228: STOQ(mpi_myid,*rp);
229: }
230:
1.26 noro 231: void Pox_mpi_nprocs(Q *rp)
1.8 noro 232: {
233: STOQ(mpi_nprocs,*rp);
234: }
235: #endif
236:
1.26 noro 237: void Pox_get_serverinfo(NODE arg,LIST *rp)
1.1 noro 238: {
239: int i,c;
1.24 noro 240: Q s_id;
1.1 noro 241: NODE t,n0,n;
242: LIST list,l;
243:
244: if ( !arg ) {
1.35 noro 245: for ( i = I_am_server?1:0, n0 = 0; i < m_c_i; i++ )
1.8 noro 246: if ( (m_c_tab[i].m>=0) || (m_c_tab[i].c>=0) ) {
1.1 noro 247: c = m_c_tab[i].c;
248: ox_get_serverinfo(c,&list);
1.24 noro 249: STOQ(i,s_id);
250: t = mknode(2,s_id,list);
1.1 noro 251: MKLIST(l,t);
252: NEXTNODE(n0,n);
253: BDY(n) = (pointer)l;
254: }
255: if ( n0 )
256: NEXT(n) = 0;
257: MKLIST(*rp,n0);
258: } else {
259: i = QTOS((Q)ARG0(arg));
1.8 noro 260: if ( i >= 0 && i < m_c_i && ((m_c_tab[i].m>=0) || (m_c_tab[i].c>=0)) )
1.1 noro 261: ox_get_serverinfo(m_c_tab[i].c,rp);
262: else {
263: MKLIST(*rp,0);
264: }
265: }
266: }
267:
268: /*
269: if noarg or arg[0]==0 then use IP socket and return a port number
270: else use UNIX socket and return a string which represents a path name
271: */
272:
1.26 noro 273: void Pgenerate_port(NODE arg,Obj *rp)
1.1 noro 274: {
275: char port_str[BUFSIZ];
276: int port;
277: char *s;
278: STRING str;
279: Q q;
280:
281: if ( !arg || !ARG0(arg) ) {
282: generate_port(0,port_str);
283: port = atoi(port_str);
284: STOQ(port,q);
285: *rp = (Obj)q;
286: } else {
287: generate_port(1,port_str);
1.26 noro 288: s = (char *)MALLOC(strlen((char *)port_str)+1);
1.1 noro 289: strcpy(s,port_str);
290: MKSTR(str,s);
291: *rp = (Obj)str;
292: }
293: }
294:
1.44 noro 295: void Pox_reset_102(NODE arg,Q *rp)
296: {
297: int s;
298: int index = QTOS((Q)ARG0(arg));
299:
300: valid_mctab_index(index);
301: s = m_c_tab[index].c;
302: ox_send_cmd(s,SM_reset_102);
303: ox_flush_stream_force(s);
1.50 noro 304: *rp = 0;
1.49 noro 305: }
306:
307: void Pox_get_rank_102(LIST *rp)
308: {
309: Q n,r;
310: NODE node;
311:
312: STOQ(nserver_102,n);
313: STOQ(myrank_102,r);
314: node = mknode(2,n,r);
315: MKLIST(*rp,node);
1.44 noro 316: }
317:
318: void Pox_set_rank_102(NODE arg,Q *rp)
319: {
320: Q nserver,rank;
321: int s;
322: int index = QTOS((Q)ARG0(arg));
323:
324: valid_mctab_index(index);
325: s = m_c_tab[index].c;
326: nserver = (Q)ARG1(arg);
327: rank = (Q)ARG2(arg);
328: ox_send_data(s,nserver);
329: ox_send_data(s,rank);
330: ox_send_cmd(s,SM_set_rank_102);
331: ox_flush_stream_force(s);
332: *rp = 0;
333: }
334:
1.45 noro 335: /* ox_tcp_accept_102(server,port,rank) */
1.43 noro 336:
1.44 noro 337: void Pox_tcp_accept_102(NODE arg,Q *rp)
1.43 noro 338: {
1.45 noro 339: int s;
340: int index = QTOS((Q)ARG0(arg));
341:
342: valid_mctab_index(index);
343: s = m_c_tab[index].c;
1.43 noro 344:
1.45 noro 345: ox_send_data(s,ARG1(arg));
346: ox_send_data(s,ARG2(arg));
347: ox_send_cmd(s,SM_tcp_accept_102);
348: ox_flush_stream_force(s);
349: *rp = 0;
1.43 noro 350: }
351:
352: /*
1.45 noro 353: ox_tcp_connect_102(server,host,port,rank)
1.43 noro 354: */
355:
1.44 noro 356: void Pox_tcp_connect_102(NODE arg,Q *rp)
1.43 noro 357: {
1.45 noro 358: int s;
359: int index = QTOS((Q)ARG0(arg));
360:
361: valid_mctab_index(index);
362: s = m_c_tab[index].c;
1.43 noro 363:
1.45 noro 364: ox_send_data(s,ARG1(arg));
365: ox_send_data(s,ARG2(arg));
366: ox_send_data(s,ARG3(arg));
367: ox_send_cmd(s,SM_tcp_connect_102);
368: ox_flush_stream_force(s);
369: *rp = 0;
1.43 noro 370: }
371:
1.1 noro 372: /*
373: try_bind_listen(port)
374: */
375:
1.26 noro 376: void Ptry_bind_listen(NODE arg,Q *rp)
1.1 noro 377: {
378: char port_str[BUFSIZ];
379: int port,s,use_unix;
380:
1.28 noro 381: if ( IS_CYGWIN || !ARG0(arg) || NUM(ARG0(arg)) ) {
1.1 noro 382: port = QTOS((Q)ARG0(arg));
383: sprintf(port_str,"%d",port);
384: use_unix = 0;
385: } else {
386: strcpy(port_str,BDY((STRING)ARG0(arg)));
387: use_unix = 1;
388: }
389: s = try_bind_listen(use_unix,port_str);
390: STOQ(s,*rp);
391: }
392:
393: /*
394: try_connect(host,port)
395: */
396:
1.26 noro 397: void Ptry_connect(NODE arg,Q *rp)
1.1 noro 398: {
399: char port_str[BUFSIZ];
400: char *host;
401: int port,s,use_unix;
402:
1.28 noro 403: if ( IS_CYGWIN || !ARG1(arg) || NUM(ARG1(arg)) ) {
1.1 noro 404: port = QTOS((Q)ARG1(arg));
405: sprintf(port_str,"%d",port);
406: use_unix = 0;
407: } else {
408: strcpy(port_str,BDY((STRING)ARG1(arg)));
409: use_unix = 1;
410: }
411: host = BDY((STRING)ARG0(arg));
412: s = try_connect(use_unix,host,port_str);
413: STOQ(s,*rp);
414: }
415:
416: /*
417: try_accept(sock,port)
418: */
419:
1.26 noro 420: void Ptry_accept(NODE arg,Q *rp)
1.1 noro 421: {
422: int use_unix,s;
423:
1.28 noro 424: if ( IS_CYGWIN || !ARG1(arg) || NUM(ARG1(arg)) )
1.1 noro 425: use_unix = 0;
426: else
427: use_unix = 1;
428: s = try_accept(use_unix,QTOS((Q)ARG0(arg)));
429: STOQ(s,*rp);
430: }
431:
432: /*
433: register_server(cs,cport,ss,sport)
434: */
435:
1.26 noro 436: void Pregister_server(NODE arg,Q *rp)
1.1 noro 437: {
438: int cs,ss,cn,sn,ind,use_unix,id;
439: char cport_str[BUFSIZ],sport_str[BUFSIZ];
1.26 noro 440: Obj obj;
1.1 noro 441: MATHCAP server_mathcap;
442:
443: cs = QTOS((Q)ARG0(arg));
444: ss = QTOS((Q)ARG2(arg));
1.28 noro 445: if ( IS_CYGWIN || !ARG1(arg) || NUM(ARG1(arg)) ) {
1.1 noro 446: sprintf(cport_str,"%d",QTOS((Q)ARG1(arg)));
447: use_unix = 0;
448: } else {
449: strcpy(cport_str,BDY((STRING)ARG1(arg)));
450: use_unix = 1;
451: }
452: if ( !ARG3(arg) || NUM(ARG3(arg)) ) {
453: if ( use_unix )
454: error("register_server : the protocol should conincide for two sockets");
455: sprintf(sport_str,"%d",QTOS((Q)ARG3(arg)));
456: } else {
457: if ( !use_unix )
458: error("register_server : the protocol should conincide for two sockets");
459: strcpy(sport_str,BDY((STRING)ARG3(arg)));
460: }
461:
462: /* client mode */
463: cn = get_iofp(cs,cport_str,0);
464: sn = get_iofp(ss,sport_str,0);
1.12 noro 465: /* get_iofp returns -1 if the laucher could not spawn the server */
466: if ( sn < 0 ) {
467: /* we should terminate the launcher */
468: ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
469: STOQ(-1,*rp);
470: return;
471: }
1.1 noro 472:
473: /* register server to the server list */
474: ind = register_server(use_unix,cn,sn);
475:
1.6 noro 476: if ( ox_exchange_mathcap ) {
477: /* request remote mathcap */
478: ox_send_cmd(sn,SM_mathcap);
479: ox_send_cmd(sn,SM_popCMO);
480: ox_flush_stream_force(sn);
1.26 noro 481: ox_recv(sn,&id,&obj); server_mathcap = (MATHCAP)obj;
1.6 noro 482: store_remote_mathcap(sn,server_mathcap);
483:
484: /* send my mathcap */
485: create_my_mathcap("asir");
486: ox_send_data(sn,my_mathcap);
487: ox_send_cmd(sn,SM_setMathcap);
488: }
1.1 noro 489: /* return the server id */
490: STOQ(ind,*rp);
491: }
492:
1.55 noro 493: #if !defined(VISUAL)
494: #include <sys/file.h>
495: #include <sys/types.h>
496: #include <sys/stat.h>
497: #include <pwd.h>
498:
499: static int find_executable(char *);
500: static int find_executable_main(char *);
501:
502: static int find_executable(char *com)
503: {
504: char *c,*s;
505: int len;
506: char dir[BUFSIZ],path[BUFSIZ];
507:
508: for ( s = (char *)getenv("PATH"); s; ) {
509: c = (char *)index(s,':');
510: if ( c ) {
511: len = c-s;
512: strncpy(dir,s,len); s = c+1; dir[len] = 0;
513: } else {
514: strcpy(dir,s); s = 0;
515: }
516: sprintf(path,"%s/%s",dir,com);
517: if ( find_executable_main(path) )
518: return 1;
519: }
520: return 0;
521: }
522:
523: static int find_executable_main(char *file)
524: {
525: struct stat buf;
526:
527: if ( stat(file,&buf) || (buf.st_mode & S_IFDIR) )
528: return 0;
529: if ( access(file,X_OK) )
530: return 0;
531: else
532: return 1;
533: }
534:
535: #endif
1.1 noro 536: /*
537: ox_launch_generic(host,launcher,server,use_unix,use_ssh,use_x,conn_to_serv)
538:
539: Input
540: host: hostname on which servers run
541: launcher: path name of the launcher
542: server: path name of the server
543: use_unix: use UNIX domain socket if 1
544: use_ssh: use ssh if 1
545: use_x: use X11 facilities if 1
546: conn_to_serv: connect to server if 1
547: */
548:
1.26 noro 549: void Pox_launch_generic(NODE arg,Q *rp)
1.1 noro 550: {
551: int use_unix,use_ssh,use_x,conn_to_serv;
552: char *host,*launcher,*server;
1.26 noro 553: Q ret;
1.1 noro 554:
555: host = (arg&&ARG0(arg))?BDY((STRING)ARG0(arg)):0;
556: launcher = BDY((STRING)ARG1(arg));
557: server = BDY((STRING)ARG2(arg));
1.28 noro 558: use_unix = !IS_CYGWIN && ARG3(arg) ? 1 : 0;
1.1 noro 559: use_ssh = ARG4(arg) ? 1 : 0;
560: use_x = ARG5(arg) ? 1 : 0;
561: conn_to_serv = QTOS((Q)ARG6(arg));
1.28 noro 562: if ( !IS_CYGWIN && !host )
1.1 noro 563: use_unix = 1;
564: ox_launch_generic(host,launcher,server,
1.26 noro 565: use_unix,use_ssh,use_x,conn_to_serv,&ret);
566: *rp = ret;
1.1 noro 567: }
1.56 ! noro 568:
! 569: #if 0
! 570: void ox_launcher_101_generic(char *host,char *launcher,
! 571: int use_unix,int use_ssh,int use_x,int conn_to_serv,Q *rp)
! 572: {
! 573: int cs,cn,ind,id;
! 574: char control_port_str[BUFSIZ];
! 575: Obj obj;
! 576:
! 577: #if !defined(VISUAL)
! 578: if ( use_unix && !find_executable("xterm") ) use_x = 0;
! 579: #endif
! 580: control_port_str[0] = 0;
! 581: do {
! 582: generate_port(use_unix,control_port_str);
! 583: if ( conn_to_serv ) {
! 584: spawn_server_101(host,launcher,
! 585: use_unix,use_ssh,use_x,conn_to_serv,
! 586: control_port_str);
! 587: cs = try_connect(use_unix,host,control_port_str);
! 588: } else {
! 589: cs = try_bind_listen(use_unix,control_port_str);
! 590: if ( cs < 0 ) continue;
! 591: spawn_laucher_101(host,launcher,
! 592: use_unix,use_ssh,use_x,conn_to_serv,
! 593: control_port_str);
! 594: cs = try_accept(use_unix,cs);
! 595: }
! 596: } while ( cs < 0 );
! 597:
! 598: /* client mode */
! 599: cn = get_iofp(cs,control_port_str,0);
! 600:
! 601: /* register server to the server list */
! 602: ind = register_server_101(use_unix,cn);
! 603:
! 604: STOQ(ind,*rp);
! 605: }
! 606: #endif
1.1 noro 607:
1.26 noro 608: void ox_launch_generic(char *host,char *launcher,char *server,
609: int use_unix,int use_ssh,int use_x,int conn_to_serv,Q *rp)
1.1 noro 610: {
611: int cs,ss,cn,sn,ind,id;
612: char control_port_str[BUFSIZ];
613: char server_port_str[BUFSIZ];
1.26 noro 614: Obj obj;
1.1 noro 615: MATHCAP server_mathcap;
616:
1.55 noro 617: #if !defined(VISUAL)
618: if ( use_unix && !find_executable("xterm") ) use_x = 0;
619: #endif
1.1 noro 620: control_port_str[0] = 0;
621: server_port_str[0] = 0;
622: do {
623: generate_port(use_unix,control_port_str);
624: generate_port(use_unix,server_port_str);
625: if ( !conn_to_serv ) {
626: cs = try_bind_listen(use_unix,control_port_str);
1.40 noro 627: if ( cs < 0 ) continue;
1.1 noro 628: ss = try_bind_listen(use_unix,server_port_str);
1.40 noro 629: if ( ss < 0 ) continue;
1.1 noro 630: }
631: spawn_server(host,launcher,server,
632: use_unix,use_ssh,use_x,conn_to_serv,
633: control_port_str,server_port_str);
634: if ( conn_to_serv ) {
635: cs = try_connect(use_unix,host,control_port_str);
1.40 noro 636: if ( cs < 0 ) continue;
1.1 noro 637: ss = try_connect(use_unix,host,server_port_str);
1.40 noro 638: if ( ss < 0 ) continue;
1.1 noro 639: } else {
640: cs = try_accept(use_unix,cs);
1.40 noro 641: if ( cs < 0 ) continue;
1.1 noro 642: ss = try_accept(use_unix,ss);
1.40 noro 643: if ( ss < 0 ) continue;
1.1 noro 644: }
645: } while ( cs < 0 || ss < 0 );
646:
647: /* client mode */
648: cn = get_iofp(cs,control_port_str,0);
649: sn = get_iofp(ss,server_port_str,0);
1.12 noro 650: /* get_iofp returns -1 if the laucher could not spawn the server */
651: if ( sn < 0 ) {
652: /* we should terminate the launcher */
653: ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
654: STOQ(-1,*rp);
655: return;
656: }
1.1 noro 657:
658: /* register server to the server list */
659: ind = register_server(use_unix,cn,sn);
660:
1.6 noro 661: if ( ox_exchange_mathcap ) {
662: /* request remote mathcap */
663: ox_send_cmd(sn,SM_mathcap);
664: ox_send_cmd(sn,SM_popCMO);
665: ox_flush_stream_force(sn);
1.26 noro 666: ox_recv(sn,&id,&obj); server_mathcap = (MATHCAP)obj;
1.6 noro 667: store_remote_mathcap(sn,server_mathcap);
668:
669: /* send my mathcap */
670: create_my_mathcap("asir");
671: ox_send_data(sn,my_mathcap);
672: ox_send_cmd(sn,SM_setMathcap);
673: }
1.1 noro 674: /* return the server id */
675: STOQ(ind,*rp);
676: }
677:
1.28 noro 678: #if defined(__CYGWIN__)
1.29 noro 679: static void bslash2slash(char *buf)
680: {
681: char *p;
682:
683: for ( p = buf; *p; p++ )
684: if ( *p == '\\' )
685: *p = '/';
686: }
687:
1.28 noro 688: static int get_start_path(char *buf)
689: {
690: static char start_path[BUFSIZ];
691: static int start_initialized = 0;
692: char name[BUFSIZ];
693:
694: if ( start_initialized ) {
695: strcpy(buf,start_path);
696: return 1;
697: }
698:
1.32 noro 699: /* Windows98 */
700: strcpy(buf,"c:\\windows\\command\\start.exe");
701: cygwin_conv_to_full_posix_path(buf,name);
702: if ( !access(name,X_OK) ) {
703: bslash2slash(buf);
704: strcpy(start_path,buf);
705: start_initialized = 1;
706: return 1;
707: }
708:
1.28 noro 709: /* Windows2000 */
710: strcpy(buf,"c:\\winnt\\system32\\start.exe");
711: cygwin_conv_to_full_posix_path(buf,name);
712: if ( !access(name,X_OK) ) {
1.29 noro 713: bslash2slash(buf);
1.28 noro 714: strcpy(start_path,buf);
1.32 noro 715: start_initialized = 1;
716: return 1;
717: }
718:
719: strcpy(buf,"c:\\winnt\\system32\\cmd.exe");
720: cygwin_conv_to_full_posix_path(buf,name);
721: if ( !access(name,X_OK) ) {
722: bslash2slash(buf);
723: sprintf(start_path,"%s /c start",buf);
724: strcpy(buf,start_path);
725: start_initialized = 1;
1.28 noro 726: return 1;
727: }
728:
1.32 noro 729: strcpy(buf,"c:\\windows\\system32\\cmd.exe");
1.28 noro 730: cygwin_conv_to_full_posix_path(buf,name);
731: if ( !access(name,X_OK) ) {
1.29 noro 732: bslash2slash(buf);
1.32 noro 733: sprintf(start_path,"%s /c start",buf);
734: strcpy(buf,start_path);
735: start_initialized = 1;
1.28 noro 736: return 1;
737: }
738:
739: return 0;
740: }
741:
742: static void get_launcher_path(char *buf)
743: {
744: static char rootname[BUFSIZ];
745: static char launcher_path[BUFSIZ];
746: static int launcher_initialized = 0;
747: char name[BUFSIZ];
748:
749: if ( launcher_initialized ) {
750: strcpy(buf,launcher_path);
751: return;
752: }
753:
754: get_rootdir(rootname,sizeof(rootname));
755: sprintf(name,"%s/ox_launch.exe",rootname);
756: cygwin_conv_to_full_win32_path(name,launcher_path);
1.29 noro 757: bslash2slash(launcher_path);
1.28 noro 758: launcher_initialized = 1;
759: strcpy(buf,launcher_path);
760: }
761: #endif
762:
1.26 noro 763: void spawn_server(char *host,char *launcher,char *server,
764: int use_unix,int use_ssh,int use_x,int conn_to_serv,
765: char *control_port_str,char *server_port_str)
1.1 noro 766: {
767: char localhost[BUFSIZ];
1.31 noro 768: char *dname,*conn_str,*rsh,*dname0,*asirhost;
1.15 noro 769: char AsirExe[BUFSIZ];
770: STRING rootdir;
771: char prog[BUFSIZ];
772: char *av[BUFSIZ];
1.26 noro 773: #if !defined(VISUAL)
774: char cmd[BUFSIZ];
775: #endif
1.28 noro 776: #if defined(__CYGWIN__)
777: char win_start[BUFSIZ],win_launcher[BUFSIZ];
778: #endif
1.26 noro 779: void Pget_rootdir();
1.1 noro 780:
1.17 noro 781: dname0 = (char *)getenv("DISPLAY");
1.23 noro 782: if ( !dname0 )
783: dname0 = "0";
1.17 noro 784: dname = use_x ? dname0 : 0;
1.1 noro 785: conn_str = conn_to_serv ? "1" : "0";
1.13 noro 786: rsh = getenv("ASIR_RSH");
787: if ( !rsh )
788: rsh = use_ssh ? "ssh" : RSH;
1.25 noro 789: if ( !use_unix && strstr(rsh,"ssh") ) {
1.13 noro 790: /*
791: * if "ssh" is used to invoke a remote server,
792: * we should not specify "-display".
793: */
794: use_ssh = 1;
795: }
1.31 noro 796: asirhost = (char *)getenv("ASIRHOSTNAME");
797: if ( asirhost )
798: strcpy(localhost,asirhost);
799: else
800: gethostname(localhost,BUFSIZ);
1.15 noro 801: #if defined(VISUAL)
802: if ( !use_unix )
803: error("spawn_server : not implemented on Windows");
804: Pget_rootdir(&rootdir);
805: sprintf(AsirExe,"%s\\bin\\engine.exe",BDY(rootdir));
806: strcpy(prog,server);
807: server = strrchr(prog,'/')+1;
808: av[0] = "ox_launch";
809: av[1] = "127.0.0.1";
810: av[2] = conn_str;
811: av[3] = control_port_str;
812: av[4] = server_port_str;
813: av[5] = server;
814: av[6] = use_x ? "1" : "0";
815: av[7] = 0;
816:
817: _spawnv(_P_NOWAIT,AsirExe,av);
818: // _spawnv(_P_NOWAIT,"d:\\home\\noro\\engine2000\\debug\\engine.exe",av);
819: // printf("ox_launch 127.0.0.1 %s %s %s %s 0\n",conn_str,control_port_str,server_port_str,server);
820: #else
1.28 noro 821: if ( use_unix || !host ) {
1.27 noro 822: #if defined(__CYGWIN__)
1.29 noro 823: get_launcher_path(win_launcher);
1.30 noro 824: if ( dname && strchr(dname,':') ) {
825: if ( !fork() ) {
826: setpgid(0,getpid());
827: execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname,
1.51 noro 828: "-geometry","60x10","-xrm","XTerm*locale:false","-e",launcher,use_unix?".":"127.1",conn_str,
1.30 noro 829: control_port_str,server_port_str,server,dname,0);
830: }
831: } else if ( dname && get_start_path(win_start) ) {
832: sprintf(cmd,"%s %s %s %s %s %s %s 1",
1.29 noro 833: win_start,win_launcher,use_unix?".":"127.1",conn_str,
834: control_port_str,server_port_str,server);
835: system(cmd);
836: } else {
837: if ( !fork() ) {
838: setpgid(0,getpid());
839: execlp(launcher,launcher,use_unix?".":"127.1",conn_str,
840: control_port_str,server_port_str,server,dname0,"-nolog",0);
1.27 noro 841: }
1.29 noro 842: }
1.27 noro 843: #else
1.29 noro 844: if ( !fork() ) {
845: setpgid(0,getpid());
1.28 noro 846: if ( dname )
1.13 noro 847: execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname,
1.51 noro 848: "-geometry","60x10","-xrm","XTerm*locale:false","-e",launcher,use_unix?".":"127.1",conn_str,
1.1 noro 849: control_port_str,server_port_str,server,dname,0);
1.27 noro 850: else
1.28 noro 851: execlp(launcher,launcher,use_unix?".":"127.1",conn_str,
1.17 noro 852: control_port_str,server_port_str,server,dname0,"-nolog",0);
1.1 noro 853: }
1.29 noro 854: #endif
1.1 noro 855: } else if ( conn_to_serv == 2 ) {
856: /* special support for java */
857: if ( dname )
858: sprintf(cmd,
1.13 noro 859: "%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 860: rsh,host,launcher,OX_XTERM,dname,server,localhost,control_port_str,server_port_str);
861: else
862: sprintf(cmd,
863: "%s -n %s \"(cd %s; java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
864: rsh,host,launcher,server,localhost,
865: control_port_str,server_port_str,server);
866: fprintf(stderr,"%s\n",cmd);
867: sleep(20);
868: /* system(cmd); */
1.15 noro 869: } else {
1.1 noro 870: if ( dname )
1.13 noro 871: if ( use_ssh )
1.25 noro 872: sprintf(cmd,
1.51 noro 873: "%s -f -n %s \"xterm -name %s -title ox_launch:%s -geometry 60x10 -xrm 'XTerm*locale:false' -e %s %s %s %s %s %s %s >&/dev/null\">/dev/null",
1.13 noro 874: rsh,host,OX_XTERM,host,launcher,localhost,conn_str,
875: control_port_str,server_port_str,server,"1");
876: else
1.25 noro 877: sprintf(cmd,
1.51 noro 878: "%s -n %s \"xterm -name %s -title ox_launch:%s -display %s -geometry 60x10 -xrm 'XTerm*locale:false' -e %s %s %s %s %s %s %s >&/dev/null&\">/dev/null",
1.13 noro 879: rsh,host,OX_XTERM,host,dname,launcher,localhost,conn_str,
1.1 noro 880: control_port_str,server_port_str,server,dname);
881: else
1.25 noro 882: if ( use_ssh )
883: sprintf(cmd,
884: "%s -f -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
885: rsh,host,launcher,localhost,conn_str,
886: control_port_str,server_port_str,server,"1","-nolog");
887: else
888: sprintf(cmd,
1.17 noro 889: "%s -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
1.1 noro 890: rsh,host,launcher,localhost,conn_str,
1.17 noro 891: control_port_str,server_port_str,server,dname0,"-nolog");
1.1 noro 892: system(cmd);
893: }
1.15 noro 894: #endif /* VISUAL */
1.1 noro 895: }
896:
1.26 noro 897: void Pox_launch(NODE arg,Obj *rp)
1.1 noro 898: {
1.26 noro 899: ox_launch_main(1,arg,rp);
1.1 noro 900: }
901:
1.26 noro 902: void Pox_launch_nox(NODE arg,Obj *rp)
1.1 noro 903: {
1.26 noro 904: ox_launch_main(0,arg,rp);
1.1 noro 905: }
906:
907: /*
908: ox_launch() : invoke local ox_asir
909: ox_launch(0,ox_xxx) : invoke local ox_xxx with asir_libdir/ox_launch
910: ox_launch(remote,lib,ox_xxx) : invoke remote ox_xxx with lib/ox_launch
911: */
912:
1.26 noro 913: void ox_launch_main(int with_x,NODE arg,Obj *p)
1.1 noro 914: {
915: char *str;
1.26 noro 916: char *hostname,*servername;
1.1 noro 917: char *control;
918: int use_unix;
1.26 noro 919: Q ret;
1.1 noro 920: extern char *asir_libdir;
921:
922: if ( arg && ARG0(arg) && argc(arg) != 3 )
923: error("ox_launch : argument mismatch");
924: control = (char *)MALLOC(BUFSIZ);
925: if ( !arg || ( !ARG0(arg) && argc(arg) == 1 ) ) {
926: sprintf(control,"%s/ox_launch",asir_libdir);
1.28 noro 927: use_unix = IS_CYGWIN ? 0 : 1;
1.1 noro 928: servername = (char *)MALLOC(BUFSIZ);
929: sprintf(servername,"%s/ox_asir",asir_libdir);
930: } else if ( !ARG0(arg) && argc(arg) == 2 ) {
931: sprintf(control,"%s/ox_launch",asir_libdir);
1.28 noro 932: use_unix = IS_CYGWIN ? 0 : 1;
1.1 noro 933: str = BDY((STRING)ARG1(arg));
934: if ( str[0] == '/' )
935: servername = str;
936: else {
937: servername = (char *)MALLOC(BUFSIZ);
938: sprintf(servername,"%s/%s",asir_libdir,str);
939: }
940: } else {
941: sprintf(control,"%s/ox_launch",BDY((STRING)ARG1(arg)));
942: if ( !ARG0(arg) )
1.28 noro 943: use_unix = IS_CYGWIN ? 0 : 1;
1.1 noro 944: else
945: use_unix = 0;
946: str = BDY((STRING)ARG2(arg));
947: if ( str[0] == '/' )
948: servername = str;
949: else {
950: servername = (char *)MALLOC(BUFSIZ);
951: sprintf(servername,"%s/%s",BDY((STRING)ARG1(arg)),str);
952: }
953: }
954: if ( arg && ARG0(arg) )
955: hostname = BDY((STRING)ARG0(arg));
956: else
957: hostname = 0;
1.26 noro 958: ox_launch_generic(hostname,control,servername,use_unix,0,with_x,0,&ret);
959: *p = (Obj)ret;
1.1 noro 960: }
961:
1.26 noro 962: int register_server(int af_unix,int m,int c)
1.1 noro 963: {
1.26 noro 964: int s,i;
1.1 noro 965: struct m_c *t;
1.9 noro 966: #define INIT_TAB_SIZ 64
1.1 noro 967:
968: if ( c < 0 )
969: return -1;
970: if ( !m_c_tab ) {
1.9 noro 971: s = INIT_TAB_SIZ*sizeof(struct m_c);
1.8 noro 972: m_c_tab = (struct m_c *)MALLOC_ATOMIC(s);
1.9 noro 973: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 974: m_c_tab[i].af_unix = 0;
975: m_c_tab[i].m = m_c_tab[i].c = -1;
976: }
1.9 noro 977: m_c_s = INIT_TAB_SIZ;
1.1 noro 978: }
1.39 noro 979: #if !defined(MPI)
1.1 noro 980: for ( i = 0; i < m_c_i; i++ )
1.8 noro 981: if ( (m_c_tab[i].m<0) && (m_c_tab[i].c<0) )
1.1 noro 982: break;
983: if ( i < m_c_i ) {
984: m_c_tab[i].m = m; m_c_tab[i].c = c;
985: m_c_tab[i].af_unix = af_unix;
986: return i;
987: }
988: #endif
989: if ( m_c_i == m_c_s ) {
1.9 noro 990: s = (m_c_s+INIT_TAB_SIZ)*sizeof(struct m_c);
1.27 noro 991: t = (struct m_c *)MALLOC_ATOMIC(s); bzero((void *)m_c_tab,s);
992: bcopy((void *)m_c_tab,(void *)t,m_c_s*sizeof(struct m_c));
1.9 noro 993: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 994: m_c_tab[m_c_s+i].af_unix = 0;
995: m_c_tab[m_c_s+i].m = m_c_tab[m_c_s+i].c = -1;
996: }
1.9 noro 997: m_c_s += INIT_TAB_SIZ; m_c_tab = t;
1.1 noro 998: }
999: m_c_tab[m_c_i].m = m; m_c_tab[m_c_i].c = c;
1000: m_c_tab[m_c_i].af_unix = af_unix;
1001: return m_c_i++;
1002: }
1003:
1004: /* iofp index => m_c_tab index */
1005:
1.26 noro 1006: int get_mcindex(int i)
1.1 noro 1007: {
1008: int j;
1009:
1010: for ( j = 0; j < m_c_i; j++ )
1011: if ( m_c_tab[j].c == i )
1012: return j;
1013: return -1;
1014: }
1015:
1016: /* arg = [ind0,ind1,...]; indk = index to m_c_tab */
1017:
1.26 noro 1018: void Pox_select(NODE arg,LIST *rp)
1.1 noro 1019: {
1020: int fd,n,i,index,mcind;
1021: fd_set r,w,e;
1022: NODE list,t,t1;
1023: Q q;
1024: double max;
1025: struct timeval interval;
1026: struct timeval *tvp;
1027:
1028: list = BDY((LIST)ARG0(arg)); arg = NEXT(arg);
1029: if ( arg ) {
1030: max = ToReal((Num)BDY(arg));
1031: interval.tv_sec = (int)max;
1032: interval.tv_usec = (int)((max-(int)max)*1000000);
1033: tvp = &interval;
1034: } else
1035: tvp = 0;
1036:
1037: FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
1038: for ( t = list; t; t = NEXT(t) ) {
1039: index = QTOS((Q)BDY(t));
1040: valid_mctab_index(index);
1.26 noro 1041: fd = get_fd(m_c_tab[index].c); FD_SET((unsigned int)fd,&r);
1.1 noro 1042: }
1043: n = select(FD_SETSIZE,&r,&w,&e,tvp);
1044: for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ )
1045: if ( FD_ISSET(i,&r) ) {
1046: /* index : index to iofp array */
1047: index = get_index(i);
1048: /* mcind : index to m_c_tab array */
1049: mcind = get_mcindex(index);
1050: n--; STOQ(mcind,q); MKNODE(t1,q,t); t = t1;
1051: }
1052: MKLIST(*rp,t);
1053: }
1054:
1.26 noro 1055: void Pox_flush(NODE arg,Q *rp)
1.1 noro 1056: {
1057: int index = QTOS((Q)ARG0(arg));
1058:
1059: valid_mctab_index(index);
1060: ox_flush_stream_force(m_c_tab[index].c);
1061: *rp = ONE;
1062: }
1063:
1.26 noro 1064: void Pox_send_raw_cmo(NODE arg,Obj *rp)
1.8 noro 1065: {
1066: int s;
1067: int index = QTOS((Q)ARG0(arg));
1068:
1069: valid_mctab_index(index);
1070: s = m_c_tab[index].c;
1071: ox_write_cmo(s,(Obj)ARG1(arg));
1072: /* flush always */
1073: ox_flush_stream(s);
1074: *rp = 0;
1075: }
1076:
1.26 noro 1077: void Pox_recv_raw_cmo(NODE arg,Obj *rp)
1.8 noro 1078: {
1079: int s;
1080: int index = QTOS((Q)ARG0(arg));
1081:
1082: valid_mctab_index(index);
1083: s = m_c_tab[index].c;
1084: ox_read_cmo(s,rp);
1085: }
1086:
1.44 noro 1087: void Pox_send_102(NODE arg,Obj *rp)
1.43 noro 1088: {
1089: int rank = QTOS((Q)ARG0(arg));
1090:
1.44 noro 1091: ox_send_data_102(rank,(Obj)ARG1(arg));
1.43 noro 1092: *rp = 0;
1093: }
1094:
1.44 noro 1095: void Pox_recv_102(NODE arg,Obj *rp)
1.43 noro 1096: {
1.44 noro 1097: int id;
1.43 noro 1098: int rank = QTOS((Q)ARG0(arg));
1099:
1.44 noro 1100: ox_recv_102(rank,&id,rp);
1.46 noro 1101: }
1102:
1103: void Pox_bcast_102(NODE arg,Obj *rp)
1104: {
1105: int rank = QTOS((Q)ARG0(arg));
1106: Obj data;
1107:
1.48 noro 1108: if ( argc(arg) > 1 )
1109: asir_push_one((Obj)ARG1(arg));
1110: ox_bcast_102(rank);
1111: *rp = (Obj)asir_pop_one();
1.47 noro 1112: }
1113:
1114: void Pox_reduce_102(NODE arg,Obj *rp)
1115: {
1.48 noro 1116: int root = QTOS((Q)ARG0(arg));
1.47 noro 1117: STRING op;
1118: char *opname;
1119: void (*func)();
1120:
1121: op = (STRING)ARG1(arg);
1122: asir_assert(op,O_STR,"ox_reduce_102");
1123: opname = BDY(op);
1124: if ( !strcmp(opname,"+") )
1125: func = arf_add;
1126: else if ( !strcmp(opname,"*") )
1127: func = arf_mul;
1128: else {
1129: error("ox_reduce_102 : operation not supported");
1130: }
1.48 noro 1131: if ( argc(arg) > 2 )
1132: asir_push_one((Obj)ARG2(arg));
1133: ox_reduce_102(root,func);
1134: *rp = (Obj)asir_pop_one();
1.43 noro 1135: }
1136:
1.26 noro 1137: void Pox_push_local(NODE arg,Obj *rp)
1.1 noro 1138: {
1139: int s;
1140: struct oLIST dummy;
1141: VL vl;
1.41 noro 1142: int index;
1.1 noro 1143:
1.41 noro 1144: if ( !arg )
1145: error("ox_push_local : too few arguments.");
1146: index = QTOS((Q)ARG0(arg));
1.1 noro 1147: valid_mctab_index(index);
1148: s = m_c_tab[index].c; arg = NEXT(arg);
1149:
1150: dummy.id = O_LIST; dummy.body = arg;
1151: get_vars_recursive((Obj)&dummy,&vl);
1152:
1153: ox_send_local_ring(s,vl);
1154: for ( ; arg; arg = NEXT(arg) )
1155: ox_send_local_data(s,BDY(arg));
1156: *rp = 0;
1157: }
1158:
1.26 noro 1159: void Pox_push_cmo(NODE arg,Obj *rp)
1.1 noro 1160: {
1161: int s;
1.41 noro 1162: int index;
1.1 noro 1163:
1.41 noro 1164: if ( !arg )
1165: error("ox_push_cmo : too few arguments.");
1166: index = QTOS((Q)ARG0(arg));
1.1 noro 1167: valid_mctab_index(index);
1168: s = m_c_tab[index].c; arg = NEXT(arg);
1169: for ( ; arg; arg = NEXT(arg) )
1170: ox_send_data(s,BDY(arg));
1171: *rp = 0;
1172: }
1173:
1.26 noro 1174: void Pox_push_vl(NODE arg,Obj *rp)
1.1 noro 1175: {
1176: int index = QTOS((Q)ARG0(arg));
1177:
1178: valid_mctab_index(index);
1179: ox_send_local_ring(m_c_tab[index].c,CO);
1180: *rp = 0;
1181: }
1182:
1.26 noro 1183: void Pox_pop_local(NODE arg,Obj *rp)
1.1 noro 1184: {
1185: int s;
1186: int index = QTOS((Q)ARG0(arg));
1187:
1188: valid_mctab_index(index);
1189: s = m_c_tab[index].c;
1190: ox_send_cmd(s,SM_popSerializedLocalObject);
1191: ox_flush_stream_force(s);
1192: ox_get_result(s,rp);
1193: }
1194:
1.26 noro 1195: void Pox_pop_cmo(NODE arg,Obj *rp)
1.1 noro 1196: {
1197: int s;
1198: int index = QTOS((Q)ARG0(arg));
1199:
1200: valid_mctab_index(index);
1201: s = m_c_tab[index].c;
1202: ox_send_cmd(s,SM_popCMO);
1203: ox_flush_stream_force(s);
1204: ox_get_result(s,rp);
1205: }
1206:
1.26 noro 1207: void Pox_pop0_local(NODE arg,Obj *rp)
1.1 noro 1208: {
1209: int index = QTOS((Q)ARG0(arg));
1210:
1211: valid_mctab_index(index);
1212: ox_send_cmd(m_c_tab[index].c,SM_popSerializedLocalObject);
1213: *rp = 0;
1214: }
1215:
1.26 noro 1216: void Pox_pop0_cmo(NODE arg,Obj *rp)
1.1 noro 1217: {
1218: int index = QTOS((Q)ARG0(arg));
1219:
1220: valid_mctab_index(index);
1221: ox_send_cmd(m_c_tab[index].c,SM_popCMO);
1222: *rp = 0;
1223: }
1224:
1.26 noro 1225: void Pox_pop0_string(NODE arg,STRING *rp)
1.1 noro 1226: {
1227: int index = QTOS((Q)ARG0(arg));
1228:
1229: valid_mctab_index(index);
1230: ox_send_cmd(m_c_tab[index].c,SM_popString);
1231: *rp = 0;
1232: }
1233:
1.26 noro 1234: void Pox_pop_string(NODE arg,Obj *rp)
1.1 noro 1235: {
1.26 noro 1236: int s;
1.1 noro 1237: int index = QTOS((Q)ARG0(arg));
1238:
1239: valid_mctab_index(index);
1240: s = m_c_tab[index].c;
1241: ox_send_cmd(s,SM_popString);
1242: ox_flush_stream_force(s);
1243: ox_get_result(s,rp);
1244: }
1245:
1.26 noro 1246: void Pox_get(NODE arg,Obj *rp)
1.1 noro 1247: {
1.3 noro 1248: int index;
1.1 noro 1249: int s;
1250:
1.3 noro 1251: if ( !arg ) {
1252: /* client->server */
1253: ox_get_result(0,rp);
1254: } else {
1255: /* server->client */
1256: index = QTOS((Q)ARG0(arg));
1257: valid_mctab_index(index);
1258: s = m_c_tab[index].c;
1259: ox_flush_stream_force(s);
1260: ox_get_result(s,rp);
1261: }
1.1 noro 1262: }
1263:
1.26 noro 1264: void Pox_pops(NODE arg,Obj *rp)
1.1 noro 1265: {
1266: int s;
1267: USINT n;
1268: int index = QTOS((Q)ARG0(arg));
1269:
1270: valid_mctab_index(index);
1271: s = m_c_tab[index].c;
1272: if ( NEXT(arg) )
1273: MKUSINT(n,QTOS((Q)ARG1(arg)));
1274: else
1275: MKUSINT(n,1);
1276: ox_send_data(s,n);
1277: ox_send_cmd(s,SM_pops);
1278: *rp = 0;
1279: }
1280:
1.26 noro 1281: void Pox_execute_function(NODE arg,Obj *rp)
1.1 noro 1282: {
1283: int s;
1284: USINT ui;
1285: int index = QTOS((Q)ARG0(arg));
1286:
1287: valid_mctab_index(index);
1288: s = m_c_tab[index].c;
1289: MKUSINT(ui,QTOS((Q)ARG2(arg)));
1290: ox_send_data(s,ui);
1291: ox_send_data(s,ARG1(arg));
1292: ox_send_cmd(s,SM_executeFunction);
1293: *rp = 0;
1294: }
1295:
1.26 noro 1296: void Pox_setname(NODE arg,Obj *rp)
1.1 noro 1297: {
1298: int s;
1299: int index = QTOS((Q)ARG0(arg));
1300:
1301: valid_mctab_index(index);
1302: s = m_c_tab[index].c;
1303: ox_send_data(s,ARG1(arg));
1304: ox_send_cmd(s,SM_setName);
1305: *rp = 0;
1306: }
1307:
1.26 noro 1308: void Pox_evalname(NODE arg,Obj *rp)
1.1 noro 1309: {
1310: int s;
1311: int index = QTOS((Q)ARG0(arg));
1312:
1313: valid_mctab_index(index);
1314: s = m_c_tab[index].c;
1315: ox_send_data(s,ARG1(arg));
1316: ox_send_cmd(s,SM_evalName);
1317: *rp = 0;
1318: }
1319:
1.26 noro 1320: void Pox_execute_string(NODE arg,Obj *rp)
1.1 noro 1321: {
1322: int s;
1323: int index = QTOS((Q)ARG0(arg));
1324:
1.52 noro 1325: asir_assert(ARG1(arg),O_STR,"ox_execute_string");
1.1 noro 1326: valid_mctab_index(index);
1327: s = m_c_tab[index].c;
1.53 noro 1328: ox_send_data(s,ARG1(arg));
1.1 noro 1329: ox_send_cmd(s,SM_executeStringByLocalParser);
1330: *rp = 0;
1331: }
1332:
1333: /* arg=[sid,fname,arg0,arg1,...,arg{n-1}] */
1334:
1.26 noro 1335: void Pox_rpc(NODE arg,Obj *rp)
1.1 noro 1336: {
1337: int s,i,n;
1338: STRING f;
1339: USINT ui;
1340: pointer *w;
1341: NODE t;
1342: int index = QTOS((Q)ARG0(arg));
1343:
1344: valid_mctab_index(index);
1345: s = m_c_tab[index].c; arg = NEXT(arg);
1346: f = (STRING)BDY(arg); arg = NEXT(arg);
1347: ox_send_local_ring(s,CO);
1348: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
1349: w = (pointer *)ALLOCA(n*sizeof(pointer));
1350: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
1351: w[i] = BDY(t);
1352: for ( i = n-1; i >= 0; i-- )
1353: ox_send_local_data(s,w[i]);
1354: MKUSINT(ui,n);
1355: ox_send_data(s,ui);
1356: ox_send_data(s,f);
1357: ox_send_cmd(s,SM_executeFunction);
1358: *rp = 0;
1359: }
1360:
1.26 noro 1361: void Pox_cmo_rpc(NODE arg,Obj *rp)
1.1 noro 1362: {
1363: int s,i,n;
1364: STRING f;
1365: USINT ui;
1366: NODE t;
1367: pointer *w;
1368: int index = QTOS((Q)ARG0(arg));
1369:
1370: valid_mctab_index(index);
1371: s = m_c_tab[index].c; arg = NEXT(arg);
1372: f = (STRING)BDY(arg); arg = NEXT(arg);
1373: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
1374: w = (pointer *)ALLOCA(n*sizeof(pointer));
1375: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
1376: w[i] = BDY(t);
1377: for ( i = n-1; i >= 0; i-- )
1378: ox_send_data(s,w[i]);
1379: MKUSINT(ui,n);
1380: ox_send_data(s,ui);
1381: ox_send_data(s,f);
1382: ox_send_cmd(s,SM_executeFunction);
1383: *rp = 0;
1384: }
1385:
1.26 noro 1386: void Pox_reset(NODE arg,Q *rp)
1.1 noro 1387: {
1388: USINT t;
1.26 noro 1389: int id,c,m;
1.1 noro 1390: Obj obj;
1391: int index = QTOS((Q)ARG0(arg));
1392:
1393: valid_mctab_index(index);
1394: m = m_c_tab[index].m;
1395: c = m_c_tab[index].c;
1396: if ( m >= 0 ) {
1397: if ( argc(arg) == 1 ) {
1398: ox_send_cmd(m,SM_control_reset_connection);
1399: ox_flush_stream_force(m);
1.26 noro 1400: ox_recv(m,&id,&obj); t = (USINT)obj;
1.1 noro 1401: }
1402: *rp = ONE;
1403: #if defined(VISUAL)
1404: Sleep(100);
1405: ox_send_cmd(c,SM_nop);
1406: ox_flush_stream_force(c);
1407: #endif
1408: while ( 1 ) {
1409: ox_recv(c,&id,&obj);
1410: if ( id == OX_SYNC_BALL )
1411: break;
1412: }
1413: ox_send_sync(c);
1.5 noro 1414: } else
1415: *rp = 0;
1416: }
1417:
1.26 noro 1418: void Pox_intr(NODE arg,Q *rp)
1.5 noro 1419: {
1420: int m;
1421: int index = QTOS((Q)ARG0(arg));
1422:
1423: valid_mctab_index(index);
1424: m = m_c_tab[index].m;
1425: if ( m >= 0 ) {
1426: if ( argc(arg) == 1 ) {
1427: ox_send_cmd(m,SM_control_intr);
1428: ox_flush_stream_force(m);
1429: }
1430: *rp = ONE;
1.1 noro 1431: } else
1432: *rp = 0;
1433: }
1434:
1.26 noro 1435: void Pox_sync(NODE arg,Q *rp)
1.1 noro 1436: {
1437: int c;
1438: int index = QTOS((Q)ARG0(arg));
1439:
1440: valid_mctab_index(index);
1441: c = m_c_tab[index].c;
1442: ox_send_sync(c);
1443: *rp = 0;
1444: }
1445:
1.26 noro 1446: void Pox_shutdown(NODE arg,Q *rp)
1.1 noro 1447: {
1448: int s;
1449: int index = QTOS((Q)ARG0(arg));
1.26 noro 1450: #if !defined(VISUAL)
1.1 noro 1451: int status;
1.26 noro 1452: #endif
1.1 noro 1453:
1454: valid_mctab_index(index);
1455: s = m_c_tab[index].m;
1456: ox_send_cmd(s,SM_shutdown);
1457: free_iofp(s);
1.18 noro 1458: s = m_c_tab[index].c;
1459: free_iofp(s);
1.39 noro 1460: #if !defined(MPI) && !defined(VISUAL)
1.1 noro 1461: if ( m_c_tab[index].af_unix )
1462: wait(&status);
1463: #endif
1.8 noro 1464: m_c_tab[index].m = -1; m_c_tab[index].c = -1;
1.1 noro 1465: m_c_tab[index].af_unix = 0;
1466: *rp = 0;
1467: }
1468:
1.26 noro 1469: void Pox_push_cmd(NODE arg,Q *rp)
1.1 noro 1470: {
1.7 noro 1471: int ui;
1.1 noro 1472: int index = QTOS((Q)ARG0(arg));
1473:
1474: valid_mctab_index(index);
1.7 noro 1475: ui = QTOS((Q)ARG1(arg));
1.1 noro 1476: ox_send_cmd(m_c_tab[index].c,ui);
1477: *rp = 0;
1478: }
1.16 noro 1479:
1480: void shutdown_all() {
1481: int s;
1482: int i,index;
1.26 noro 1483: #if !defined(VISUAL)
1.16 noro 1484: int status;
1.26 noro 1485: #endif
1.16 noro 1486:
1487: for ( i = I_am_server?1:0; i < m_c_i; i++ ) {
1488: index = i;
1489: check_valid_mctab_index(index);
1490: if ( index < 0 )
1491: continue;
1492: s = m_c_tab[index].m;
1493: ox_send_cmd(s,SM_shutdown);
1.21 noro 1494: #if defined(VISUAL)
1495: Sleep(1000);
1496: #endif
1.16 noro 1497: free_iofp(s);
1.18 noro 1498: s = m_c_tab[index].c;
1499: free_iofp(s);
1.39 noro 1500: #if !defined(MPI) && !defined(VISUAL)
1.16 noro 1501: if ( m_c_tab[index].af_unix )
1502: wait(&status);
1503: #endif
1504: m_c_tab[index].m = 0; m_c_tab[index].c = 0;
1505: m_c_tab[index].af_unix = 0;
1506: }
1.33 noro 1507: }
1508:
1509: char *ox_get_servername(int);
1510:
1511: int is_ox_plot(int index)
1512: {
1513: char *name;
1514:
1515: check_valid_mctab_index(index);
1516: if ( index < 0 )
1517: return 0;
1518: /* m : client, c : server ??? */
1519: name = ox_get_servername(m_c_tab[index].c);
1520: return strcmp(name,"ox_plot") ? 0 : 1;
1521: }
1522:
1523: int validate_ox_plot_stream(int index)
1524: {
1525: int i;
1526: NODE arg;
1527: STRING name;
1528: Obj r;
1529:
1530: if ( is_ox_plot(index) )
1531: return index;
1532: for ( i = 0; i < m_c_i; i++ )
1533: if ( is_ox_plot(i) )
1534: return i;
1535:
1536: /* create an ox_plot server */
1537: MKSTR(name,"ox_plot");
1538: arg = mknode(2,0,name);
1539: Pox_launch_nox(arg,&r);
1.34 noro 1540: i = QTOS((Q)r);
1541: #if defined(VISUAL)
1542: Sleep(100);
1543: ox_send_cmd(m_c_tab[i].c,SM_nop);
1544: ox_flush_stream_force(m_c_tab[i].c);
1545: #endif
1546: return i;
1.42 noro 1547: }
1548:
1549: int get_ox_server_id(int index)
1550: {
1551: valid_mctab_index(index);
1552: return m_c_tab[index].c;
1.43 noro 1553: }
1554:
1555: int register_102(int s1,int rank,int is_master)
1556: {
1557: unsigned char c,rc;
1558:
1559: if ( rank >= MAXIOFP ) return -1;
1560: iofp_102[rank].s = s1;
1561: #if defined(VISUAL)
1562: iofp_102[rank].in = WSIO_open(s1,"r");
1563: iofp_102[rank].out = WSIO_open(s1,"w");
1564: #else
1565: iofp_102[rank].in = fdopen(s1,"r");
1566: iofp_102[rank].out = fdopen(s1,"w");
1567: #if !defined(__CYGWIN__)
1568: setbuffer(iofp_102[rank].in,iofp_102[rank].inbuf =
1569: (char *)GC_malloc_atomic(LBUFSIZ),LBUFSIZ);
1570: setbuffer(iofp_102[rank].out,iofp_102[rank].outbuf =
1571: (char *)GC_malloc_atomic(LBUFSIZ),LBUFSIZ);
1572: #endif
1573: #endif
1574: if ( little_endian )
1575: c = 1;
1576: else
1577: c = 0xff;
1578: if ( is_master ) {
1579: /* server : write -> read */
1580: write_char((FILE *)iofp_102[rank].out,&c);
1.44 noro 1581: ox_flush_stream_force_102(rank);
1.43 noro 1582: read_char((FILE *)iofp_102[rank].in,&rc);
1583: } else {
1584: /* client : read -> write */
1585: read_char((FILE *)iofp_102[rank].in,&rc);
1586: /* special care for a failure of spawing a server */
1587: if ( rc !=0 && rc != 1 && rc != 0xff )
1588: return -1;
1589: write_char((FILE *)iofp_102[rank].out,&c);
1.44 noro 1590: ox_flush_stream_force_102(rank);
1.43 noro 1591: }
1592: iofp_102[rank].conv = c == rc ? 0 : 1;
1593: iofp_102[rank].socket = 0;
1594: return 0;
1595: }
1596:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>