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