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

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

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