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