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

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

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