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