[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.4

1.4     ! noro        1: /* $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.3 1999/12/21 04:20:42 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)\
                     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},
1.3       noro       96:        {"ox_get",Pox_get,-1},
1.1       noro       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);
1.4     ! noro      404: #if !defined(VISUAL)
1.1       noro      405:        if ( use_unix ) {
                    406:                if ( !fork() ) {
1.2       noro      407:                        setpgid(0,getpid());
1.1       noro      408:                        if ( dname )
                    409:                                execlp("xterm","xterm","-name",OX_XTERM,"-display",dname,
                    410:                                        "-geometry","60x10","-e",launcher,".",conn_str,
                    411:                                        control_port_str,server_port_str,server,dname,0);
                    412:                        else
                    413:                                execlp(launcher,launcher,".",conn_str,
                    414:                                        control_port_str,server_port_str,server,"0",0);
                    415:                }
                    416:        } else if ( conn_to_serv == 2 ) {
                    417:                /* special support for java */
                    418:                if ( dname )
                    419:                        sprintf(cmd,
                    420:                                "%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",
                    421:                                rsh,host,launcher,OX_XTERM,dname,server,localhost,control_port_str,server_port_str);
                    422:                else
                    423:                        sprintf(cmd,
                    424:                                "%s -n %s \"(cd %s; java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
                    425:                                rsh,host,launcher,server,localhost,
                    426:                                control_port_str,server_port_str,server);
                    427:                fprintf(stderr,"%s\n",cmd);
                    428:                sleep(20);
                    429: /*             system(cmd); */
1.4     ! noro      430:        } else
        !           431: #endif /* VISUAL */
        !           432:        {
1.1       noro      433:                if ( dname )
                    434:                        sprintf(cmd,
                    435:                                "%s -n %s \"xterm -name %s -display %s -geometry 60x10 -e %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
                    436:                                rsh,host,OX_XTERM,dname,launcher,localhost,conn_str,
                    437:                                control_port_str,server_port_str,server,dname);
                    438:                else
                    439:                        sprintf(cmd,
                    440:                                "%s -n %s \"%s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
                    441:                                rsh,host,launcher,localhost,conn_str,
                    442:                                control_port_str,server_port_str,server,"0");
                    443:                system(cmd);
                    444:        }
                    445: }
                    446:
                    447: void Pox_launch(arg,rp)
                    448: NODE arg;
                    449: Obj *rp;
                    450: {
                    451:        Pox_launch_main(1,arg,rp);
                    452: }
                    453:
                    454: void Pox_launch_nox(arg,rp)
                    455: NODE arg;
                    456: Obj *rp;
                    457: {
                    458:        Pox_launch_main(0,arg,rp);
                    459: }
                    460:
                    461: /*
                    462:        ox_launch() : invoke local ox_asir
                    463:        ox_launch(0,ox_xxx) : invoke local ox_xxx with asir_libdir/ox_launch
                    464:        ox_launch(remote,lib,ox_xxx) : invoke remote ox_xxx with lib/ox_launch
                    465: */
                    466:
                    467: void Pox_launch_main(with_x,arg,rp)
                    468: int with_x;
                    469: NODE arg;
                    470: Obj *rp;
                    471: {
                    472:        char *str;
                    473:        char *hostname,*servername,*dname;
                    474:        char *control;
                    475:        int use_unix;
                    476:        extern char *asir_libdir;
                    477:
                    478:        if ( arg && ARG0(arg) && argc(arg) != 3 )
                    479:                error("ox_launch : argument mismatch");
                    480:        control = (char *)MALLOC(BUFSIZ);
                    481:        if ( !arg || ( !ARG0(arg) && argc(arg) == 1 ) ) {
                    482:                sprintf(control,"%s/ox_launch",asir_libdir);
                    483:                use_unix = 1;
                    484:                servername = (char *)MALLOC(BUFSIZ);
                    485:                sprintf(servername,"%s/ox_asir",asir_libdir);
                    486:        } else if ( !ARG0(arg) && argc(arg) == 2 ) {
                    487:                sprintf(control,"%s/ox_launch",asir_libdir);
                    488:                use_unix = 1;
                    489:                str = BDY((STRING)ARG1(arg));
                    490:                if ( str[0] == '/' )
                    491:                        servername = str;
                    492:                else {
                    493:                        servername = (char *)MALLOC(BUFSIZ);
                    494:                        sprintf(servername,"%s/%s",asir_libdir,str);
                    495:                }
                    496:        } else {
                    497:                sprintf(control,"%s/ox_launch",BDY((STRING)ARG1(arg)));
                    498:                if ( !ARG0(arg) )
                    499:                        use_unix = 1;
                    500:                else
                    501:                        use_unix = 0;
                    502:                str = BDY((STRING)ARG2(arg));
                    503:                if ( str[0] == '/' )
                    504:                        servername = str;
                    505:                else {
                    506:                        servername = (char *)MALLOC(BUFSIZ);
                    507:                        sprintf(servername,"%s/%s",BDY((STRING)ARG1(arg)),str);
                    508:                }
                    509:        }
                    510:        if ( arg && ARG0(arg) )
                    511:                hostname = BDY((STRING)ARG0(arg));
                    512:        else
                    513:                hostname = 0;
                    514:        ox_launch_generic(hostname,control,servername,use_unix,0,with_x,0,rp);
                    515: }
                    516:
                    517: int register_server(af_unix,m,c)
                    518: int af_unix,m,c;
                    519: {
                    520:        int s,i,ci;
                    521:        struct m_c *t;
                    522:
                    523:        if ( c < 0 )
                    524:                return -1;
                    525:        if ( !m_c_tab ) {
                    526:                s = BUFSIZ*sizeof(struct m_c);
                    527:                m_c_tab = (struct m_c *)MALLOC_ATOMIC(s); bzero(m_c_tab,s);
                    528:                m_c_s = BUFSIZ;
                    529:        }
                    530: #if !MPI
                    531:        for ( i = 0; i < m_c_i; i++ )
                    532:                if ( !m_c_tab[i].m && !m_c_tab[i].c )
                    533:                        break;
                    534:        if ( i < m_c_i ) {
                    535:                m_c_tab[i].m = m; m_c_tab[i].c = c;
                    536:                m_c_tab[i].af_unix = af_unix;
                    537:                return i;
                    538:        }
                    539: #endif
                    540:        if ( m_c_i == m_c_s ) {
                    541:                s = (m_c_s+BUFSIZ)*sizeof(struct m_c);
                    542:                t = (struct m_c *)MALLOC_ATOMIC(s); bzero(m_c_tab,s);
                    543:                bcopy(m_c_tab,t,m_c_s*sizeof(struct m_c));
                    544:                m_c_s += BUFSIZ; m_c_tab = t;
                    545:        }
                    546:        m_c_tab[m_c_i].m = m; m_c_tab[m_c_i].c = c;
                    547:        m_c_tab[m_c_i].af_unix = af_unix;
                    548:        return m_c_i++;
                    549: }
                    550:
                    551: /* iofp index => m_c_tab index */
                    552:
                    553: int get_mcindex(i)
                    554: int i;
                    555: {
                    556:        int j;
                    557:
                    558:        for ( j = 0; j < m_c_i; j++ )
                    559:                if ( m_c_tab[j].c == i )
                    560:                        return j;
                    561:        return -1;
                    562: }
                    563:
                    564: /* arg = [ind0,ind1,...]; indk = index to m_c_tab */
                    565:
                    566: void Pox_select(arg,rp)
                    567: NODE arg;
                    568: LIST *rp;
                    569: {
                    570:        int fd,n,i,index,mcind;
                    571:        fd_set r,w,e;
                    572:        NODE list,t,t1;
                    573:        Q q;
                    574:        double max;
                    575:        struct timeval interval;
                    576:        struct timeval *tvp;
                    577:
                    578:        list = BDY((LIST)ARG0(arg)); arg = NEXT(arg);
                    579:        if ( arg ) {
                    580:                max = ToReal((Num)BDY(arg));
                    581:                interval.tv_sec = (int)max;
                    582:                interval.tv_usec = (int)((max-(int)max)*1000000);
                    583:                tvp = &interval;
                    584:        } else
                    585:                tvp = 0;
                    586:
                    587:        FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
                    588:        for ( t = list; t; t = NEXT(t) ) {
                    589:                index = QTOS((Q)BDY(t));
                    590:                valid_mctab_index(index);
                    591:                fd = get_fd(m_c_tab[index].c); FD_SET(fd,&r);
                    592:        }
                    593:        n = select(FD_SETSIZE,&r,&w,&e,tvp);
                    594:        for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ )
                    595:                if ( FD_ISSET(i,&r) ) {
                    596:                        /* index : index to iofp array */
                    597:                        index = get_index(i);
                    598:                        /* mcind : index to m_c_tab array */
                    599:                        mcind = get_mcindex(index);
                    600:                        n--; STOQ(mcind,q); MKNODE(t1,q,t); t = t1;
                    601:                }
                    602:        MKLIST(*rp,t);
                    603: }
                    604:
                    605: void Pox_flush(arg,rp)
                    606: NODE arg;
                    607: Q *rp;
                    608: {
                    609:        int index = QTOS((Q)ARG0(arg));
                    610:
                    611:        valid_mctab_index(index);
                    612:        ox_flush_stream_force(m_c_tab[index].c);
                    613:        *rp = ONE;
                    614: }
                    615:
                    616: void Pox_push_local(arg,rp)
                    617: NODE arg;
                    618: Obj *rp;
                    619: {
                    620:        int s;
                    621:        struct oLIST dummy;
                    622:        VL vl;
                    623:        int index = QTOS((Q)ARG0(arg));
                    624:
                    625:        valid_mctab_index(index);
                    626:        s = m_c_tab[index].c; arg = NEXT(arg);
                    627:
                    628:        dummy.id = O_LIST; dummy.body = arg;
                    629:        get_vars_recursive((Obj)&dummy,&vl);
                    630:
                    631:        ox_send_local_ring(s,vl);
                    632:        for ( ; arg; arg = NEXT(arg) )
                    633:                ox_send_local_data(s,BDY(arg));
                    634:        *rp = 0;
                    635: }
                    636:
                    637: void Pox_push_cmo(arg,rp)
                    638: NODE arg;
                    639: Obj *rp;
                    640: {
                    641:        int s;
                    642:        int index = QTOS((Q)ARG0(arg));
                    643:
                    644:        valid_mctab_index(index);
                    645:        s = m_c_tab[index].c; arg = NEXT(arg);
                    646:        for ( ; arg; arg = NEXT(arg) )
                    647:                ox_send_data(s,BDY(arg));
                    648:        *rp = 0;
                    649: }
                    650:
                    651: void Pox_push_vl(arg,rp)
                    652: NODE arg;
                    653: Obj *rp;
                    654: {
                    655:        int s;
                    656:        int index = QTOS((Q)ARG0(arg));
                    657:
                    658:        valid_mctab_index(index);
                    659:        ox_send_local_ring(m_c_tab[index].c,CO);
                    660:        *rp = 0;
                    661: }
                    662:
                    663: void Pox_pop_local(arg,rp)
                    664: NODE arg;
                    665: Obj *rp;
                    666: {
                    667:        int s;
                    668:        int index = QTOS((Q)ARG0(arg));
                    669:
                    670:        valid_mctab_index(index);
                    671:        s = m_c_tab[index].c;
                    672:        ox_send_cmd(s,SM_popSerializedLocalObject);
                    673:        ox_flush_stream_force(s);
                    674:        ox_get_result(s,rp);
                    675: }
                    676:
                    677: void Pox_pop_cmo(arg,rp)
                    678: NODE arg;
                    679: Obj *rp;
                    680: {
                    681:        int s;
                    682:        int index = QTOS((Q)ARG0(arg));
                    683:
                    684:        valid_mctab_index(index);
                    685:        s = m_c_tab[index].c;
                    686:        ox_send_cmd(s,SM_popCMO);
                    687:        ox_flush_stream_force(s);
                    688:        ox_get_result(s,rp);
                    689: }
                    690:
                    691: void Pox_pop0_local(arg,rp)
                    692: NODE arg;
                    693: Obj *rp;
                    694: {
                    695:        int index = QTOS((Q)ARG0(arg));
                    696:
                    697:        valid_mctab_index(index);
                    698:        ox_send_cmd(m_c_tab[index].c,SM_popSerializedLocalObject);
                    699:        *rp = 0;
                    700: }
                    701:
                    702: void Pox_pop0_cmo(arg,rp)
                    703: NODE arg;
                    704: Obj *rp;
                    705: {
                    706:        int index = QTOS((Q)ARG0(arg));
                    707:
                    708:        valid_mctab_index(index);
                    709:        ox_send_cmd(m_c_tab[index].c,SM_popCMO);
                    710:        *rp = 0;
                    711: }
                    712:
                    713: void Pox_pop0_string(arg,rp)
                    714: NODE arg;
                    715: STRING *rp;
                    716: {
                    717:        int index = QTOS((Q)ARG0(arg));
                    718:
                    719:        valid_mctab_index(index);
                    720:        ox_send_cmd(m_c_tab[index].c,SM_popString);
                    721:        *rp = 0;
                    722: }
                    723:
                    724: void Pox_pop_string(arg,rp)
                    725: NODE arg;
                    726: STRING *rp;
                    727: {
                    728:        int s,id;
                    729:        int index = QTOS((Q)ARG0(arg));
                    730:
                    731:        valid_mctab_index(index);
                    732:        s = m_c_tab[index].c;
                    733:        ox_send_cmd(s,SM_popString);
                    734:        ox_flush_stream_force(s);
                    735:        ox_get_result(s,rp);
                    736: }
                    737:
                    738: void Pox_get(arg,rp)
                    739: NODE arg;
                    740: Obj *rp;
                    741: {
1.3       noro      742:        int index;
1.1       noro      743:        int s;
                    744:
1.3       noro      745:        if ( !arg ) {
                    746:                /* client->server */
                    747:                ox_get_result(0,rp);
                    748:        } else {
                    749:                /* server->client */
                    750:                index = QTOS((Q)ARG0(arg));
                    751:                valid_mctab_index(index);
                    752:                s = m_c_tab[index].c;
                    753:                ox_flush_stream_force(s);
                    754:                ox_get_result(s,rp);
                    755:        }
1.1       noro      756: }
                    757:
                    758: void Pox_pops(arg,rp)
                    759: NODE arg;
                    760: Obj *rp;
                    761: {
                    762:        int s;
                    763:        USINT n;
                    764:        int index = QTOS((Q)ARG0(arg));
                    765:
                    766:        valid_mctab_index(index);
                    767:        s = m_c_tab[index].c;
                    768:        if ( NEXT(arg) )
                    769:                MKUSINT(n,QTOS((Q)ARG1(arg)));
                    770:        else
                    771:                MKUSINT(n,1);
                    772:        ox_send_data(s,n);
                    773:        ox_send_cmd(s,SM_pops);
                    774:        *rp = 0;
                    775: }
                    776:
                    777: void Pox_execute_function(arg,rp)
                    778: NODE arg;
                    779: Obj *rp;
                    780: {
                    781:        int s;
                    782:        USINT ui;
                    783:        int index = QTOS((Q)ARG0(arg));
                    784:
                    785:        valid_mctab_index(index);
                    786:        s = m_c_tab[index].c;
                    787:        MKUSINT(ui,QTOS((Q)ARG2(arg)));
                    788:        ox_send_data(s,ui);
                    789:        ox_send_data(s,ARG1(arg));
                    790:        ox_send_cmd(s,SM_executeFunction);
                    791:        *rp = 0;
                    792: }
                    793:
                    794: void Pox_setname(arg,rp)
                    795: NODE arg;
                    796: Obj *rp;
                    797: {
                    798:        int s;
                    799:        int index = QTOS((Q)ARG0(arg));
                    800:
                    801:        valid_mctab_index(index);
                    802:        s = m_c_tab[index].c;
                    803:        ox_send_data(s,ARG1(arg));
                    804:        ox_send_cmd(s,SM_setName);
                    805:        *rp = 0;
                    806: }
                    807:
                    808: void Pox_evalname(arg,rp)
                    809: NODE arg;
                    810: Obj *rp;
                    811: {
                    812:        int s;
                    813:        int index = QTOS((Q)ARG0(arg));
                    814:
                    815:        valid_mctab_index(index);
                    816:        s = m_c_tab[index].c;
                    817:        ox_send_data(s,ARG1(arg));
                    818:        ox_send_cmd(s,SM_evalName);
                    819:        *rp = 0;
                    820: }
                    821:
                    822: void Pox_execute_string(arg,rp)
                    823: NODE arg;
                    824: Obj *rp;
                    825: {
                    826:        int s;
                    827:        int index = QTOS((Q)ARG0(arg));
                    828:
                    829:        valid_mctab_index(index);
                    830:        s = m_c_tab[index].c;
                    831:        ox_send_data(s,ARG1(arg));
                    832:        ox_send_cmd(s,SM_executeStringByLocalParser);
                    833:        *rp = 0;
                    834: }
                    835:
                    836: /* arg=[sid,fname,arg0,arg1,...,arg{n-1}] */
                    837:
                    838: void Pox_rpc(arg,rp)
                    839: NODE arg;
                    840: Obj *rp;
                    841: {
                    842:        int s,i,n;
                    843:        STRING f;
                    844:        USINT ui;
                    845:        pointer *w;
                    846:        NODE t;
                    847:        int index = QTOS((Q)ARG0(arg));
                    848:
                    849:        valid_mctab_index(index);
                    850:        s = m_c_tab[index].c; arg = NEXT(arg);
                    851:        f = (STRING)BDY(arg); arg = NEXT(arg);
                    852:        ox_send_local_ring(s,CO);
                    853:        for ( n = 0, t = arg; t; t = NEXT(t), n++ );
                    854:        w = (pointer *)ALLOCA(n*sizeof(pointer));
                    855:        for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
                    856:                w[i] = BDY(t);
                    857:        for ( i = n-1; i >= 0; i-- )
                    858:                ox_send_local_data(s,w[i]);
                    859:        MKUSINT(ui,n);
                    860:        ox_send_data(s,ui);
                    861:        ox_send_data(s,f);
                    862:        ox_send_cmd(s,SM_executeFunction);
                    863:        *rp = 0;
                    864: }
                    865:
                    866: void Pox_cmo_rpc(arg,rp)
                    867: NODE arg;
                    868: Obj *rp;
                    869: {
                    870:        int s,i,n;
                    871:        STRING f;
                    872:        USINT ui;
                    873:        NODE t;
                    874:        pointer *w;
                    875:        int index = QTOS((Q)ARG0(arg));
                    876:
                    877:        valid_mctab_index(index);
                    878:        s = m_c_tab[index].c; arg = NEXT(arg);
                    879:        f = (STRING)BDY(arg); arg = NEXT(arg);
                    880:        for ( n = 0, t = arg; t; t = NEXT(t), n++ );
                    881:        w = (pointer *)ALLOCA(n*sizeof(pointer));
                    882:        for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
                    883:                w[i] = BDY(t);
                    884:        for ( i = n-1; i >= 0; i-- )
                    885:                ox_send_data(s,w[i]);
                    886:        MKUSINT(ui,n);
                    887:        ox_send_data(s,ui);
                    888:        ox_send_data(s,f);
                    889:        ox_send_cmd(s,SM_executeFunction);
                    890:        *rp = 0;
                    891: }
                    892:
                    893: void Pox_reset(arg,rp)
                    894: NODE arg;
                    895: Q *rp;
                    896: {
                    897:        USINT t;
                    898:        int s,id,c,m;
                    899:        Obj obj;
                    900:        int index = QTOS((Q)ARG0(arg));
                    901:
                    902:        valid_mctab_index(index);
                    903:        m = m_c_tab[index].m;
                    904:        c = m_c_tab[index].c;
                    905:        if ( m >= 0 ) {
                    906:                if ( argc(arg) == 1 ) {
                    907:                        ox_send_cmd(m,SM_control_reset_connection);
                    908:                        ox_flush_stream_force(m);
                    909:                        ox_recv(m,&id,&t);
                    910:                }
                    911:                *rp = ONE;
                    912: #if defined(VISUAL)
                    913:                Sleep(100);
                    914:                ox_send_cmd(c,SM_nop);
                    915:                ox_flush_stream_force(c);
                    916: #endif
                    917:                while ( 1 ) {
                    918:                        ox_recv(c,&id,&obj);
                    919:                        if ( id == OX_SYNC_BALL )
                    920:                                break;
                    921:                }
                    922:                ox_send_sync(c);
                    923:        } else
                    924:                *rp = 0;
                    925: }
                    926:
                    927: void Pox_sync(arg,rp)
                    928: NODE arg;
                    929: Q *rp;
                    930: {
                    931:        int c;
                    932:        int index = QTOS((Q)ARG0(arg));
                    933:
                    934:        valid_mctab_index(index);
                    935:        c = m_c_tab[index].c;
                    936:        ox_send_sync(c);
                    937:        *rp = 0;
                    938: }
                    939:
                    940: void Pox_shutdown(arg,rp)
                    941: NODE arg;
                    942: Q *rp;
                    943: {
                    944:        int s;
                    945:        int index = QTOS((Q)ARG0(arg));
                    946:        int status;
                    947:
                    948:        valid_mctab_index(index);
                    949:        s = m_c_tab[index].m;
                    950:        ox_send_cmd(s,SM_shutdown);
                    951:        free_iofp(s);
                    952: #if !MPI && !defined(VISUAL)
                    953:        if ( m_c_tab[index].af_unix )
                    954:                wait(&status);
                    955: #endif
                    956:        m_c_tab[index].m = 0; m_c_tab[index].c = 0;
                    957:        m_c_tab[index].af_unix = 0;
                    958:        *rp = 0;
                    959: }
                    960:
                    961: void Pox_push_cmd(arg,rp)
                    962: NODE arg;
                    963: Q *rp;
                    964: {
                    965:        unsigned int ui;
                    966:        int index = QTOS((Q)ARG0(arg));
                    967:
                    968:        valid_mctab_index(index);
                    969:        ui = (unsigned int)QTOS((Q)ARG1(arg));
                    970:        ox_send_cmd(m_c_tab[index].c,ui);
                    971:        *rp = 0;
                    972: }
                    973: #endif

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