[BACK]Return to tcpf.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / io

Annotation of OpenXM_contrib2/asir2000/io/tcpf.c, Revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>