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

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

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