Annotation of OpenXM_contrib2/asir2000/io/tcpf.c, Revision 1.9
1.9 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.8 2000/07/13 05:09:03 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;
1.9 ! noro 551: #define INIT_TAB_SIZ 64
1.1 noro 552:
553: if ( c < 0 )
554: return -1;
555: if ( !m_c_tab ) {
1.9 ! noro 556: s = INIT_TAB_SIZ*sizeof(struct m_c);
1.8 noro 557: m_c_tab = (struct m_c *)MALLOC_ATOMIC(s);
1.9 ! noro 558: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 559: m_c_tab[i].af_unix = 0;
560: m_c_tab[i].m = m_c_tab[i].c = -1;
561: }
1.9 ! noro 562: m_c_s = INIT_TAB_SIZ;
1.1 noro 563: }
564: #if !MPI
565: for ( i = 0; i < m_c_i; i++ )
1.8 noro 566: if ( (m_c_tab[i].m<0) && (m_c_tab[i].c<0) )
1.1 noro 567: break;
568: if ( i < m_c_i ) {
569: m_c_tab[i].m = m; m_c_tab[i].c = c;
570: m_c_tab[i].af_unix = af_unix;
571: return i;
572: }
573: #endif
574: if ( m_c_i == m_c_s ) {
1.9 ! noro 575: s = (m_c_s+INIT_TAB_SIZ)*sizeof(struct m_c);
1.1 noro 576: t = (struct m_c *)MALLOC_ATOMIC(s); bzero(m_c_tab,s);
577: bcopy(m_c_tab,t,m_c_s*sizeof(struct m_c));
1.9 ! noro 578: for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8 noro 579: m_c_tab[m_c_s+i].af_unix = 0;
580: m_c_tab[m_c_s+i].m = m_c_tab[m_c_s+i].c = -1;
581: }
1.9 ! noro 582: m_c_s += INIT_TAB_SIZ; m_c_tab = t;
1.1 noro 583: }
584: m_c_tab[m_c_i].m = m; m_c_tab[m_c_i].c = c;
585: m_c_tab[m_c_i].af_unix = af_unix;
586: return m_c_i++;
587: }
588:
589: /* iofp index => m_c_tab index */
590:
591: int get_mcindex(i)
592: int i;
593: {
594: int j;
595:
596: for ( j = 0; j < m_c_i; j++ )
597: if ( m_c_tab[j].c == i )
598: return j;
599: return -1;
600: }
601:
602: /* arg = [ind0,ind1,...]; indk = index to m_c_tab */
603:
604: void Pox_select(arg,rp)
605: NODE arg;
606: LIST *rp;
607: {
608: int fd,n,i,index,mcind;
609: fd_set r,w,e;
610: NODE list,t,t1;
611: Q q;
612: double max;
613: struct timeval interval;
614: struct timeval *tvp;
615:
616: list = BDY((LIST)ARG0(arg)); arg = NEXT(arg);
617: if ( arg ) {
618: max = ToReal((Num)BDY(arg));
619: interval.tv_sec = (int)max;
620: interval.tv_usec = (int)((max-(int)max)*1000000);
621: tvp = &interval;
622: } else
623: tvp = 0;
624:
625: FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
626: for ( t = list; t; t = NEXT(t) ) {
627: index = QTOS((Q)BDY(t));
628: valid_mctab_index(index);
629: fd = get_fd(m_c_tab[index].c); FD_SET(fd,&r);
630: }
631: n = select(FD_SETSIZE,&r,&w,&e,tvp);
632: for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ )
633: if ( FD_ISSET(i,&r) ) {
634: /* index : index to iofp array */
635: index = get_index(i);
636: /* mcind : index to m_c_tab array */
637: mcind = get_mcindex(index);
638: n--; STOQ(mcind,q); MKNODE(t1,q,t); t = t1;
639: }
640: MKLIST(*rp,t);
641: }
642:
643: void Pox_flush(arg,rp)
644: NODE arg;
645: Q *rp;
646: {
647: int index = QTOS((Q)ARG0(arg));
648:
649: valid_mctab_index(index);
650: ox_flush_stream_force(m_c_tab[index].c);
651: *rp = ONE;
652: }
653:
1.8 noro 654: void Pox_send_raw_cmo(arg,rp)
655: NODE arg;
656: Obj *rp;
657: {
658: int s;
659: int index = QTOS((Q)ARG0(arg));
660:
661: valid_mctab_index(index);
662: s = m_c_tab[index].c;
663: ox_write_cmo(s,(Obj)ARG1(arg));
664: /* flush always */
665: ox_flush_stream(s);
666: *rp = 0;
667: }
668:
669: void Pox_recv_raw_cmo(arg,rp)
670: NODE arg;
671: Obj *rp;
672: {
673: int s;
674: int index = QTOS((Q)ARG0(arg));
675:
676: valid_mctab_index(index);
677: s = m_c_tab[index].c;
678: ox_read_cmo(s,rp);
679: }
680:
1.1 noro 681: void Pox_push_local(arg,rp)
682: NODE arg;
683: Obj *rp;
684: {
685: int s;
686: struct oLIST dummy;
687: VL vl;
688: int index = QTOS((Q)ARG0(arg));
689:
690: valid_mctab_index(index);
691: s = m_c_tab[index].c; arg = NEXT(arg);
692:
693: dummy.id = O_LIST; dummy.body = arg;
694: get_vars_recursive((Obj)&dummy,&vl);
695:
696: ox_send_local_ring(s,vl);
697: for ( ; arg; arg = NEXT(arg) )
698: ox_send_local_data(s,BDY(arg));
699: *rp = 0;
700: }
701:
702: void Pox_push_cmo(arg,rp)
703: NODE arg;
704: Obj *rp;
705: {
706: int s;
707: int index = QTOS((Q)ARG0(arg));
708:
709: valid_mctab_index(index);
710: s = m_c_tab[index].c; arg = NEXT(arg);
711: for ( ; arg; arg = NEXT(arg) )
712: ox_send_data(s,BDY(arg));
713: *rp = 0;
714: }
715:
716: void Pox_push_vl(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: ox_send_local_ring(m_c_tab[index].c,CO);
725: *rp = 0;
726: }
727:
728: void Pox_pop_local(arg,rp)
729: NODE arg;
730: Obj *rp;
731: {
732: int s;
733: int index = QTOS((Q)ARG0(arg));
734:
735: valid_mctab_index(index);
736: s = m_c_tab[index].c;
737: ox_send_cmd(s,SM_popSerializedLocalObject);
738: ox_flush_stream_force(s);
739: ox_get_result(s,rp);
740: }
741:
742: void Pox_pop_cmo(arg,rp)
743: NODE arg;
744: Obj *rp;
745: {
746: int s;
747: int index = QTOS((Q)ARG0(arg));
748:
749: valid_mctab_index(index);
750: s = m_c_tab[index].c;
751: ox_send_cmd(s,SM_popCMO);
752: ox_flush_stream_force(s);
753: ox_get_result(s,rp);
754: }
755:
756: void Pox_pop0_local(arg,rp)
757: NODE arg;
758: Obj *rp;
759: {
760: int index = QTOS((Q)ARG0(arg));
761:
762: valid_mctab_index(index);
763: ox_send_cmd(m_c_tab[index].c,SM_popSerializedLocalObject);
764: *rp = 0;
765: }
766:
767: void Pox_pop0_cmo(arg,rp)
768: NODE arg;
769: Obj *rp;
770: {
771: int index = QTOS((Q)ARG0(arg));
772:
773: valid_mctab_index(index);
774: ox_send_cmd(m_c_tab[index].c,SM_popCMO);
775: *rp = 0;
776: }
777:
778: void Pox_pop0_string(arg,rp)
779: NODE arg;
780: STRING *rp;
781: {
782: int index = QTOS((Q)ARG0(arg));
783:
784: valid_mctab_index(index);
785: ox_send_cmd(m_c_tab[index].c,SM_popString);
786: *rp = 0;
787: }
788:
789: void Pox_pop_string(arg,rp)
790: NODE arg;
791: STRING *rp;
792: {
793: int s,id;
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_popString);
799: ox_flush_stream_force(s);
800: ox_get_result(s,rp);
801: }
802:
803: void Pox_get(arg,rp)
804: NODE arg;
805: Obj *rp;
806: {
1.3 noro 807: int index;
1.1 noro 808: int s;
809:
1.3 noro 810: if ( !arg ) {
811: /* client->server */
812: ox_get_result(0,rp);
813: } else {
814: /* server->client */
815: index = QTOS((Q)ARG0(arg));
816: valid_mctab_index(index);
817: s = m_c_tab[index].c;
818: ox_flush_stream_force(s);
819: ox_get_result(s,rp);
820: }
1.1 noro 821: }
822:
823: void Pox_pops(arg,rp)
824: NODE arg;
825: Obj *rp;
826: {
827: int s;
828: USINT n;
829: int index = QTOS((Q)ARG0(arg));
830:
831: valid_mctab_index(index);
832: s = m_c_tab[index].c;
833: if ( NEXT(arg) )
834: MKUSINT(n,QTOS((Q)ARG1(arg)));
835: else
836: MKUSINT(n,1);
837: ox_send_data(s,n);
838: ox_send_cmd(s,SM_pops);
839: *rp = 0;
840: }
841:
842: void Pox_execute_function(arg,rp)
843: NODE arg;
844: Obj *rp;
845: {
846: int s;
847: USINT ui;
848: int index = QTOS((Q)ARG0(arg));
849:
850: valid_mctab_index(index);
851: s = m_c_tab[index].c;
852: MKUSINT(ui,QTOS((Q)ARG2(arg)));
853: ox_send_data(s,ui);
854: ox_send_data(s,ARG1(arg));
855: ox_send_cmd(s,SM_executeFunction);
856: *rp = 0;
857: }
858:
859: void Pox_setname(arg,rp)
860: NODE arg;
861: Obj *rp;
862: {
863: int s;
864: int index = QTOS((Q)ARG0(arg));
865:
866: valid_mctab_index(index);
867: s = m_c_tab[index].c;
868: ox_send_data(s,ARG1(arg));
869: ox_send_cmd(s,SM_setName);
870: *rp = 0;
871: }
872:
873: void Pox_evalname(arg,rp)
874: NODE arg;
875: Obj *rp;
876: {
877: int s;
878: int index = QTOS((Q)ARG0(arg));
879:
880: valid_mctab_index(index);
881: s = m_c_tab[index].c;
882: ox_send_data(s,ARG1(arg));
883: ox_send_cmd(s,SM_evalName);
884: *rp = 0;
885: }
886:
887: void Pox_execute_string(arg,rp)
888: NODE arg;
889: Obj *rp;
890: {
891: int s;
892: int index = QTOS((Q)ARG0(arg));
893:
894: valid_mctab_index(index);
895: s = m_c_tab[index].c;
896: ox_send_data(s,ARG1(arg));
897: ox_send_cmd(s,SM_executeStringByLocalParser);
898: *rp = 0;
899: }
900:
901: /* arg=[sid,fname,arg0,arg1,...,arg{n-1}] */
902:
903: void Pox_rpc(arg,rp)
904: NODE arg;
905: Obj *rp;
906: {
907: int s,i,n;
908: STRING f;
909: USINT ui;
910: pointer *w;
911: NODE t;
912: int index = QTOS((Q)ARG0(arg));
913:
914: valid_mctab_index(index);
915: s = m_c_tab[index].c; arg = NEXT(arg);
916: f = (STRING)BDY(arg); arg = NEXT(arg);
917: ox_send_local_ring(s,CO);
918: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
919: w = (pointer *)ALLOCA(n*sizeof(pointer));
920: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
921: w[i] = BDY(t);
922: for ( i = n-1; i >= 0; i-- )
923: ox_send_local_data(s,w[i]);
924: MKUSINT(ui,n);
925: ox_send_data(s,ui);
926: ox_send_data(s,f);
927: ox_send_cmd(s,SM_executeFunction);
928: *rp = 0;
929: }
930:
931: void Pox_cmo_rpc(arg,rp)
932: NODE arg;
933: Obj *rp;
934: {
935: int s,i,n;
936: STRING f;
937: USINT ui;
938: NODE t;
939: pointer *w;
940: int index = QTOS((Q)ARG0(arg));
941:
942: valid_mctab_index(index);
943: s = m_c_tab[index].c; arg = NEXT(arg);
944: f = (STRING)BDY(arg); arg = NEXT(arg);
945: for ( n = 0, t = arg; t; t = NEXT(t), n++ );
946: w = (pointer *)ALLOCA(n*sizeof(pointer));
947: for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
948: w[i] = BDY(t);
949: for ( i = n-1; i >= 0; i-- )
950: ox_send_data(s,w[i]);
951: MKUSINT(ui,n);
952: ox_send_data(s,ui);
953: ox_send_data(s,f);
954: ox_send_cmd(s,SM_executeFunction);
955: *rp = 0;
956: }
957:
958: void Pox_reset(arg,rp)
959: NODE arg;
960: Q *rp;
961: {
962: USINT t;
963: int s,id,c,m;
964: Obj obj;
965: int index = QTOS((Q)ARG0(arg));
966:
967: valid_mctab_index(index);
968: m = m_c_tab[index].m;
969: c = m_c_tab[index].c;
970: if ( m >= 0 ) {
971: if ( argc(arg) == 1 ) {
972: ox_send_cmd(m,SM_control_reset_connection);
973: ox_flush_stream_force(m);
974: ox_recv(m,&id,&t);
975: }
976: *rp = ONE;
977: #if defined(VISUAL)
978: Sleep(100);
979: ox_send_cmd(c,SM_nop);
980: ox_flush_stream_force(c);
981: #endif
982: while ( 1 ) {
983: ox_recv(c,&id,&obj);
984: if ( id == OX_SYNC_BALL )
985: break;
986: }
987: ox_send_sync(c);
1.5 noro 988: } else
989: *rp = 0;
990: }
991:
992: void Pox_intr(arg,rp)
993: NODE arg;
994: Q *rp;
995: {
996: int m;
997: Obj obj;
998: int index = QTOS((Q)ARG0(arg));
999:
1000: valid_mctab_index(index);
1001: m = m_c_tab[index].m;
1002: if ( m >= 0 ) {
1003: if ( argc(arg) == 1 ) {
1004: ox_send_cmd(m,SM_control_intr);
1005: ox_flush_stream_force(m);
1006: }
1007: *rp = ONE;
1.1 noro 1008: } else
1009: *rp = 0;
1010: }
1011:
1012: void Pox_sync(arg,rp)
1013: NODE arg;
1014: Q *rp;
1015: {
1016: int c;
1017: int index = QTOS((Q)ARG0(arg));
1018:
1019: valid_mctab_index(index);
1020: c = m_c_tab[index].c;
1021: ox_send_sync(c);
1022: *rp = 0;
1023: }
1024:
1025: void Pox_shutdown(arg,rp)
1026: NODE arg;
1027: Q *rp;
1028: {
1029: int s;
1030: int index = QTOS((Q)ARG0(arg));
1031: int status;
1032:
1033: valid_mctab_index(index);
1034: s = m_c_tab[index].m;
1035: ox_send_cmd(s,SM_shutdown);
1036: free_iofp(s);
1037: #if !MPI && !defined(VISUAL)
1038: if ( m_c_tab[index].af_unix )
1039: wait(&status);
1040: #endif
1.8 noro 1041: m_c_tab[index].m = -1; m_c_tab[index].c = -1;
1.1 noro 1042: m_c_tab[index].af_unix = 0;
1043: *rp = 0;
1044: }
1045:
1046: void Pox_push_cmd(arg,rp)
1047: NODE arg;
1048: Q *rp;
1049: {
1.7 noro 1050: int ui;
1.1 noro 1051: int index = QTOS((Q)ARG0(arg));
1052:
1053: valid_mctab_index(index);
1.7 noro 1054: ui = QTOS((Q)ARG1(arg));
1.1 noro 1055: ox_send_cmd(m_c_tab[index].c,ui);
1056: *rp = 0;
1057: }
1058: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>