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