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