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

1.10      noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.11      noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.10      noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
1.17    ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.16 2000/11/07 06:35:39 noro Exp $
1.10      noro       48: */
1.1       noro       49: #if INET
                     50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "com.h"
                     53: #include <signal.h>
                     54: #if !defined(VISUAL)
                     55: #include <sys/types.h>
                     56: #include <pwd.h>
                     57: #endif
                     58: #include "ox.h"
                     59:
                     60: #if defined(VISUAL)
1.15      noro       61: #include <stdlib.h>
1.1       noro       62: #include <winsock.h>
1.15      noro       63: #include <process.h>
1.1       noro       64: #endif
                     65:
                     66: #define OX_XTERM "ox_xterm"
                     67:
                     68: #if !defined(_PA_RISC1_1)
                     69: #define RSH "rsh"
                     70: #else
                     71: #define RSH "remsh"
                     72: #endif
                     73:
                     74: static struct m_c {
                     75:        int m,c,af_unix;
                     76: } *m_c_tab;
                     77:
                     78: static int m_c_i,m_c_s;
1.16      noro       79: int I_am_server;
1.1       noro       80:
                     81: #if MPI
                     82: extern int mpi_nprocs;
                     83: #define valid_mctab_index(ind)\
1.8       noro       84: if((ind)<0||(ind)>=mpi_nprocs){error("invalid server id");}
1.16      noro       85: #define check_valid_mctab_index(ind)\
                     86: if((ind)<0||(ind)>=mpi_nprocs){(ind)=-1;}
1.1       noro       87: #else
                     88: #define valid_mctab_index(ind)\
                     89: if((ind)<0||(ind)>=m_c_i||\
1.8       noro       90: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){error("invalid server id");}
1.16      noro       91: #define check_valid_mctab_index(ind)\
                     92: if((ind)<0||(ind)>=m_c_i||\
                     93: ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){(ind)=-1;}
1.1       noro       94: #endif
                     95:
                     96: int register_server();
                     97: int get_mcindex(int);
                     98:
1.8       noro       99: void Pox_send_raw_cmo(), Pox_recv_raw_cmo();
                    100:
1.1       noro      101: void Pox_launch(),Pox_launch_nox(),Pox_launch_main();
                    102: void Pox_launch_generic();
                    103: void Pox_shutdown();
                    104:
1.5       noro      105: void Pox_rpc(),Pox_cmo_rpc(),Pox_reset(),Pox_intr(),Pox_sync(),Pox_select();
1.1       noro      106:
                    107: void Pox_push_local(),Pox_push_cmo(),Pox_push_vl(),Pox_push_cmd();
                    108:
                    109: void Pox_pop_local(),Pox_pop_cmo();
                    110: void Pox_pop0_local(),Pox_pop0_cmo();
                    111: void Pox_pop_string(),Pox_pop0_string();
                    112: void Pox_get(),Pox_pops();
                    113:
                    114: void Pox_execute_function(),Pox_execute_string();
                    115: void Pox_setname(), Pox_evalname();
                    116: void Pox_flush();
                    117: void Pgenerate_port(),Ptry_bind_listen(),Ptry_connect(),Ptry_accept();
                    118: void Pregister_server();
                    119: void Pox_get_serverinfo();
1.8       noro      120: void Pox_mpi_myid(), Pox_mpi_nprocs();
1.1       noro      121:
                    122: void ox_launch_generic();
                    123:
                    124: pointer bevalf();
                    125:
                    126: struct ftab tcp_tab[] = {
1.8       noro      127:        {"ox_send_raw_cmo",Pox_send_raw_cmo,2},
                    128:        {"ox_recv_raw_cmo",Pox_recv_raw_cmo,1},
1.1       noro      129:        {"ox_get_serverinfo",Pox_get_serverinfo,-1},
                    130:        {"generate_port",Pgenerate_port,-1},
                    131:        {"try_bind_listen",Ptry_bind_listen,1},
                    132:        {"try_connect",Ptry_connect,2},
                    133:        {"try_accept",Ptry_accept,2},
                    134:        {"register_server",Pregister_server,4},
                    135:        {"ox_flush",Pox_flush,1},
                    136:        {"ox_launch",Pox_launch,-3},
                    137:        {"ox_launch_nox",Pox_launch_nox,-3},
                    138:        {"ox_launch_generic",Pox_launch_generic,7},
                    139:        {"ox_shutdown",Pox_shutdown,1},
                    140:
                    141:        {"ox_rpc",Pox_rpc,-99999999},
                    142:        {"ox_cmo_rpc",Pox_cmo_rpc,-99999999},
                    143:
                    144:        {"ox_sync",Pox_sync,1},
1.8       noro      145: #if MPI
                    146:        {"ox_mpi_myid",Pox_mpi_myid,0},
                    147:        {"ox_mpi_nprocs",Pox_mpi_nprocs,0},
                    148: #endif
1.1       noro      149: #if !MPI
                    150:        {"ox_reset",Pox_reset,-2},
1.5       noro      151:        {"ox_intr",Pox_intr,1},
1.1       noro      152:        {"ox_select",Pox_select,-2},
                    153: #endif
                    154:
                    155:        {"ox_pop_string",Pox_pop_string,1},
                    156:        {"ox_pop0_string",Pox_pop0_string,1},
                    157:        {"ox_pop_local",Pox_pop_local,1},
                    158:        {"ox_pop0_local",Pox_pop0_local,1},
                    159:        {"ox_pop_cmo",Pox_pop_cmo,1},
                    160:        {"ox_pop0_cmo",Pox_pop0_cmo,1},
1.3       noro      161:        {"ox_get",Pox_get,-1},
1.1       noro      162:        {"ox_pops",Pox_pops,-2},
                    163:
                    164:        {"ox_push_vl",Pox_push_vl,1},
                    165:        {"ox_push_local",Pox_push_local,-99999999},
                    166:        {"ox_push_cmo",Pox_push_cmo,-99999999},
                    167:        {"ox_push_cmd",Pox_push_cmd,2},
                    168:
                    169:        {"ox_setname",Pox_setname,2},
                    170:        {"ox_evalname",Pox_evalname,2},
                    171:
                    172:        {"ox_execute_string",Pox_execute_string,2},
                    173:        {"ox_execute_function",Pox_execute_function,3},
                    174:
                    175:
                    176:        {0,0,0},
                    177: };
                    178:
                    179: extern struct IOFP iofp[];
                    180: extern MATHCAP my_mathcap;
1.6       noro      181: extern int ox_exchange_mathcap;
1.1       noro      182:
                    183: char *getenv();
                    184:
1.8       noro      185: #if MPI
                    186: extern int mpi_myid, mpi_nprocs;
                    187:
                    188: void Pox_mpi_myid(rp)
                    189: Q *rp;
                    190: {
                    191:        STOQ(mpi_myid,*rp);
                    192: }
                    193:
                    194: void Pox_mpi_nprocs(rp)
                    195: Q *rp;
                    196: {
                    197:        STOQ(mpi_nprocs,*rp);
                    198: }
                    199: #endif
                    200:
1.1       noro      201: void Pox_get_serverinfo(arg,rp)
                    202: NODE arg;
                    203: LIST *rp;
                    204: {
                    205:        int i,c;
                    206:        Q sid;
                    207:        NODE t,n0,n;
                    208:        LIST list,l;
                    209:
                    210:        if ( !arg ) {
                    211:                for ( i = 0, n0 = 0; i < m_c_i; i++ )
1.8       noro      212:                        if ( (m_c_tab[i].m>=0) || (m_c_tab[i].c>=0) ) {
1.1       noro      213:                                c = m_c_tab[i].c;
                    214:                                ox_get_serverinfo(c,&list);
                    215:                                STOQ(i,sid);
                    216:                                t = mknode(2,sid,list);
                    217:                                MKLIST(l,t);
                    218:                                NEXTNODE(n0,n);
                    219:                                BDY(n) = (pointer)l;
                    220:                        }
                    221:                if ( n0 )
                    222:                        NEXT(n) = 0;
                    223:                MKLIST(*rp,n0);
                    224:        } else {
                    225:                i = QTOS((Q)ARG0(arg));
1.8       noro      226:                if ( i >= 0 && i < m_c_i && ((m_c_tab[i].m>=0) || (m_c_tab[i].c>=0)) )
1.1       noro      227:                        ox_get_serverinfo(m_c_tab[i].c,rp);
                    228:                else {
                    229:                        MKLIST(*rp,0);
                    230:                }
                    231:        }
                    232: }
                    233:
                    234: /*
                    235:   if noarg or arg[0]==0 then use IP socket and return a port number
                    236:   else use UNIX socket and return a string which represents a path name
                    237: */
                    238:
                    239: void Pgenerate_port(arg,rp)
                    240: NODE arg;
                    241: Obj *rp;
                    242: {
                    243:        char port_str[BUFSIZ];
                    244:        int port;
                    245:        char *s;
                    246:        STRING str;
                    247:        Q q;
                    248:
                    249:        if ( !arg || !ARG0(arg) ) {
                    250:                generate_port(0,port_str);
                    251:                port = atoi(port_str);
                    252:                STOQ(port,q);
                    253:                *rp = (Obj)q;
                    254:        } else {
                    255:                generate_port(1,port_str);
                    256:                s = (char *)MALLOC(strlen(port_str)+1);
                    257:                strcpy(s,port_str);
                    258:                MKSTR(str,s);
                    259:                *rp = (Obj)str;
                    260:        }
                    261: }
                    262:
                    263: /*
                    264:  try_bind_listen(port)
                    265: */
                    266:
                    267: void Ptry_bind_listen(arg,rp)
                    268: NODE arg;
                    269: Q *rp;
                    270: {
                    271:        char port_str[BUFSIZ];
                    272:        int port,s,use_unix;
                    273:
                    274:        if ( !ARG0(arg) || NUM(ARG0(arg)) ) {
                    275:                port = QTOS((Q)ARG0(arg));
                    276:                sprintf(port_str,"%d",port);
                    277:                use_unix = 0;
                    278:        } else {
                    279:                strcpy(port_str,BDY((STRING)ARG0(arg)));
                    280:                use_unix = 1;
                    281:        }
                    282:        s = try_bind_listen(use_unix,port_str);
                    283:        STOQ(s,*rp);
                    284: }
                    285:
                    286: /*
                    287:  try_connect(host,port)
                    288: */
                    289:
                    290: void Ptry_connect(arg,rp)
                    291: NODE arg;
                    292: Q *rp;
                    293: {
                    294:        char port_str[BUFSIZ];
                    295:        char *host;
                    296:        int port,s,use_unix;
                    297:
                    298:        if ( !ARG1(arg) || NUM(ARG1(arg)) ) {
                    299:                port = QTOS((Q)ARG1(arg));
                    300:                sprintf(port_str,"%d",port);
                    301:                use_unix = 0;
                    302:        } else {
                    303:                strcpy(port_str,BDY((STRING)ARG1(arg)));
                    304:                use_unix = 1;
                    305:        }
                    306:        host = BDY((STRING)ARG0(arg));
                    307:        s = try_connect(use_unix,host,port_str);
                    308:        STOQ(s,*rp);
                    309: }
                    310:
                    311: /*
                    312:  try_accept(sock,port)
                    313: */
                    314:
                    315: void Ptry_accept(arg,rp)
                    316: NODE arg;
                    317: Q *rp;
                    318: {
                    319:        int use_unix,s;
                    320:
                    321:        if ( !ARG1(arg) || NUM(ARG1(arg)) )
                    322:                use_unix = 0;
                    323:        else
                    324:                use_unix = 1;
                    325:        s = try_accept(use_unix,QTOS((Q)ARG0(arg)));
                    326:        STOQ(s,*rp);
                    327: }
                    328:
                    329: /*
                    330:  register_server(cs,cport,ss,sport)
                    331: */
                    332:
                    333: void Pregister_server(arg,rp)
                    334: NODE arg;
                    335: Q *rp;
                    336: {
                    337:        int cs,ss,cn,sn,ind,use_unix,id;
                    338:        char cport_str[BUFSIZ],sport_str[BUFSIZ];
                    339:        MATHCAP server_mathcap;
                    340:
                    341:        cs = QTOS((Q)ARG0(arg));
                    342:        ss = QTOS((Q)ARG2(arg));
                    343:        if ( !ARG1(arg) || NUM(ARG1(arg)) ) {
                    344:                sprintf(cport_str,"%d",QTOS((Q)ARG1(arg)));
                    345:                use_unix = 0;
                    346:        } else {
                    347:                strcpy(cport_str,BDY((STRING)ARG1(arg)));
                    348:                use_unix = 1;
                    349:        }
                    350:        if ( !ARG3(arg) || NUM(ARG3(arg)) ) {
                    351:                if ( use_unix )
                    352:                        error("register_server : the protocol should conincide for two sockets");
                    353:                sprintf(sport_str,"%d",QTOS((Q)ARG3(arg)));
                    354:        } else {
                    355:                if ( !use_unix )
                    356:                        error("register_server : the protocol should conincide for two sockets");
                    357:                strcpy(sport_str,BDY((STRING)ARG3(arg)));
                    358:        }
                    359:
                    360:        /* client mode */
                    361:        cn = get_iofp(cs,cport_str,0);
                    362:        sn = get_iofp(ss,sport_str,0);
1.12      noro      363:        /* get_iofp returns -1 if the laucher could not spawn the server */
                    364:        if ( sn < 0 ) {
                    365:                /* we should terminate the launcher */
                    366:                ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
                    367:                STOQ(-1,*rp);
                    368:                return;
                    369:        }
1.1       noro      370:
                    371:        /* register server to the server list */
                    372:        ind = register_server(use_unix,cn,sn);
                    373:
1.6       noro      374:        if ( ox_exchange_mathcap ) {
                    375:                /* request remote mathcap */
                    376:                ox_send_cmd(sn,SM_mathcap);
                    377:                ox_send_cmd(sn,SM_popCMO);
                    378:                ox_flush_stream_force(sn);
                    379:                ox_recv(sn,&id,&server_mathcap);
                    380:                store_remote_mathcap(sn,server_mathcap);
                    381:
                    382:                /* send my mathcap */
                    383:                create_my_mathcap("asir");
                    384:                ox_send_data(sn,my_mathcap);
                    385:                ox_send_cmd(sn,SM_setMathcap);
                    386:        }
1.1       noro      387:        /* return the server id */
                    388:        STOQ(ind,*rp);
                    389: }
                    390:
                    391: /*
                    392:   ox_launch_generic(host,launcher,server,use_unix,use_ssh,use_x,conn_to_serv)
                    393:
                    394:   Input
                    395:        host: hostname on which servers run
                    396:        launcher: path name of the launcher
                    397:        server: path name of the server
                    398:        use_unix: use UNIX domain socket if 1
                    399:        use_ssh: use ssh if 1
                    400:        use_x: use X11 facilities if 1
                    401:        conn_to_serv: connect to server if 1
                    402: */
                    403:
                    404: void Pox_launch_generic(arg,rp)
                    405: NODE arg;
                    406: Q *rp;
                    407: {
                    408:        int use_unix,use_ssh,use_x,conn_to_serv;
                    409:        char *host,*launcher,*server;
                    410:
                    411:        host = (arg&&ARG0(arg))?BDY((STRING)ARG0(arg)):0;
                    412:        launcher = BDY((STRING)ARG1(arg));
                    413:        server = BDY((STRING)ARG2(arg));
                    414:        use_unix = ARG3(arg) ? 1 : 0;
                    415:        use_ssh = ARG4(arg) ? 1 : 0;
                    416:        use_x = ARG5(arg) ? 1 : 0;
                    417:        conn_to_serv = QTOS((Q)ARG6(arg));
                    418:        if ( !host )
                    419:                use_unix = 1;
                    420:        ox_launch_generic(host,launcher,server,
                    421:                use_unix,use_ssh,use_x,conn_to_serv,rp);
                    422: }
                    423:
                    424: void ox_launch_generic(host,launcher,server,
                    425:                use_unix,use_ssh,use_x,conn_to_serv,rp)
                    426: char *host,*launcher,*server;
                    427: int use_unix,use_ssh,use_x,conn_to_serv;
                    428: Q *rp;
                    429: {
                    430:        int cs,ss,cn,sn,ind,id;
                    431:        char control_port_str[BUFSIZ];
                    432:        char server_port_str[BUFSIZ];
                    433:        MATHCAP server_mathcap;
                    434:
                    435:        control_port_str[0] = 0;
                    436:        server_port_str[0] = 0;
                    437:        do {
                    438:                generate_port(use_unix,control_port_str);
                    439:                generate_port(use_unix,server_port_str);
                    440:                if ( !conn_to_serv ) {
                    441:                        cs = try_bind_listen(use_unix,control_port_str);
                    442:                        ss = try_bind_listen(use_unix,server_port_str);
                    443:                }
                    444:                spawn_server(host,launcher,server,
                    445:                        use_unix,use_ssh,use_x,conn_to_serv,
                    446:                                control_port_str,server_port_str);
                    447:                if ( conn_to_serv ) {
                    448:                        cs = try_connect(use_unix,host,control_port_str);
                    449:                        ss = try_connect(use_unix,host,server_port_str);
                    450:                } else {
                    451:                        cs = try_accept(use_unix,cs);
                    452:                        ss = try_accept(use_unix,ss);
                    453:                }
                    454:        } while ( cs < 0 || ss < 0 );
                    455:
                    456:        /* client mode */
                    457:        cn = get_iofp(cs,control_port_str,0);
                    458:        sn = get_iofp(ss,server_port_str,0);
1.12      noro      459:        /* get_iofp returns -1 if the laucher could not spawn the server */
                    460:        if ( sn < 0 ) {
                    461:                /* we should terminate the launcher */
                    462:                ox_send_cmd(cn,SM_shutdown); ox_flush_stream_force(cn);
                    463:                STOQ(-1,*rp);
                    464:                return;
                    465:        }
1.1       noro      466:
                    467:        /* register server to the server list */
                    468:        ind = register_server(use_unix,cn,sn);
                    469:
1.6       noro      470:        if ( ox_exchange_mathcap ) {
                    471:                /* request remote mathcap */
                    472:                ox_send_cmd(sn,SM_mathcap);
                    473:                ox_send_cmd(sn,SM_popCMO);
                    474:                ox_flush_stream_force(sn);
                    475:                ox_recv(sn,&id,&server_mathcap);
                    476:                store_remote_mathcap(sn,server_mathcap);
                    477:
                    478:                /* send my mathcap */
                    479:                create_my_mathcap("asir");
                    480:                ox_send_data(sn,my_mathcap);
                    481:                ox_send_cmd(sn,SM_setMathcap);
                    482:        }
1.1       noro      483:        /* return the server id */
                    484:        STOQ(ind,*rp);
                    485: }
                    486:
                    487: int spawn_server(host,launcher,server,
                    488:        use_unix,use_ssh,use_x,conn_to_serv,
                    489:        control_port_str,server_port_str)
                    490: char *host,*launcher,*server;
                    491: int use_unix,use_ssh,use_x,conn_to_serv;
                    492: char *control_port_str,*server_port_str;
                    493: {
                    494:        char cmd[BUFSIZ];
                    495:        char localhost[BUFSIZ];
1.17    ! noro      496:        char *dname,*conn_str,*rsh,*dname0;
1.13      noro      497:        char dname_str[BUFSIZ];
1.15      noro      498:        char AsirExe[BUFSIZ];
                    499:        STRING rootdir;
                    500:        char prog[BUFSIZ];
                    501:        char *av[BUFSIZ];
1.1       noro      502:
1.17    ! noro      503:        dname0 = (char *)getenv("DISPLAY");
        !           504:        dname = use_x ? dname0 : 0;
1.1       noro      505:        conn_str = conn_to_serv ? "1" : "0";
1.13      noro      506:        rsh = getenv("ASIR_RSH");
                    507:        if ( !rsh )
                    508:                rsh = use_ssh ? "ssh" : RSH;
                    509:        if ( !use_unix && dname && strstr(rsh,"ssh") ) {
                    510:                /*
                    511:                 * if "ssh" is used to invoke a remote server,
                    512:                 * we should not specify "-display".
                    513:                 */
                    514:                use_ssh = 1;
                    515:        }
1.1       noro      516:        gethostname(localhost,BUFSIZ);
1.15      noro      517: #if defined(VISUAL)
                    518:        if ( !use_unix )
                    519:                error("spawn_server : not implemented on Windows");
                    520:        Pget_rootdir(&rootdir);
                    521:        sprintf(AsirExe,"%s\\bin\\engine.exe",BDY(rootdir));
                    522:        strcpy(prog,server);
                    523:        server = strrchr(prog,'/')+1;
                    524:        av[0] = "ox_launch";
                    525:        av[1] = "127.0.0.1";
                    526:        av[2] = conn_str;
                    527:        av[3] = control_port_str;
                    528:        av[4] = server_port_str;
                    529:        av[5] = server;
                    530:        av[6] = use_x ? "1" : "0";
                    531:        av[7] = 0;
                    532:
                    533:        _spawnv(_P_NOWAIT,AsirExe,av);
                    534: //     _spawnv(_P_NOWAIT,"d:\\home\\noro\\engine2000\\debug\\engine.exe",av);
                    535: //     printf("ox_launch 127.0.0.1 %s %s %s %s 0\n",conn_str,control_port_str,server_port_str,server);
                    536: #else
1.1       noro      537:        if ( use_unix ) {
                    538:                if ( !fork() ) {
1.2       noro      539:                        setpgid(0,getpid());
1.1       noro      540:                        if ( dname )
1.13      noro      541:                                execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname,
1.1       noro      542:                                        "-geometry","60x10","-e",launcher,".",conn_str,
                    543:                                        control_port_str,server_port_str,server,dname,0);
                    544:                        else
                    545:                                execlp(launcher,launcher,".",conn_str,
1.17    ! noro      546:                                        control_port_str,server_port_str,server,dname0,"-nolog",0);
1.1       noro      547:                }
                    548:        } else if ( conn_to_serv == 2 ) {
                    549:                /* special support for java */
                    550:                if ( dname )
                    551:                        sprintf(cmd,
1.13      noro      552:                                "%s -n %s \"(cd %s; xterm -name %s %s -geometry 60x10 -e java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
1.1       noro      553:                                rsh,host,launcher,OX_XTERM,dname,server,localhost,control_port_str,server_port_str);
                    554:                else
                    555:                        sprintf(cmd,
                    556:                                "%s -n %s \"(cd %s; java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
                    557:                                rsh,host,launcher,server,localhost,
                    558:                                control_port_str,server_port_str,server);
                    559:                fprintf(stderr,"%s\n",cmd);
                    560:                sleep(20);
                    561: /*             system(cmd); */
1.15      noro      562:        } else {
1.1       noro      563:                if ( dname )
1.13      noro      564:                        if ( use_ssh )
                    565:                        sprintf(cmd,
1.14      noro      566: "%s -f -n %s \"xterm -name %s -title ox_launch:%s -geometry 60x10 -e %s %s %s %s %s %s %s >&/dev/null\">/dev/null",
1.13      noro      567:                                rsh,host,OX_XTERM,host,launcher,localhost,conn_str,
                    568:                                control_port_str,server_port_str,server,"1");
                    569:                        else
1.1       noro      570:                        sprintf(cmd,
1.14      noro      571: "%s -n %s \"xterm -name %s -title ox_launch:%s -display %s -geometry 60x10 -e %s %s %s %s %s %s %s >&/dev/null&\">/dev/null",
1.13      noro      572:                                rsh,host,OX_XTERM,host,dname,launcher,localhost,conn_str,
1.1       noro      573:                                control_port_str,server_port_str,server,dname);
                    574:                else
                    575:                        sprintf(cmd,
1.17    ! noro      576: "%s -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
1.1       noro      577:                                rsh,host,launcher,localhost,conn_str,
1.17    ! noro      578:                                control_port_str,server_port_str,server,dname0,"-nolog");
1.1       noro      579:                system(cmd);
                    580:        }
1.15      noro      581: #endif /* VISUAL */
1.1       noro      582: }
                    583:
                    584: void Pox_launch(arg,rp)
                    585: NODE arg;
                    586: Obj *rp;
                    587: {
                    588:        Pox_launch_main(1,arg,rp);
                    589: }
                    590:
                    591: void Pox_launch_nox(arg,rp)
                    592: NODE arg;
                    593: Obj *rp;
                    594: {
                    595:        Pox_launch_main(0,arg,rp);
                    596: }
                    597:
                    598: /*
                    599:        ox_launch() : invoke local ox_asir
                    600:        ox_launch(0,ox_xxx) : invoke local ox_xxx with asir_libdir/ox_launch
                    601:        ox_launch(remote,lib,ox_xxx) : invoke remote ox_xxx with lib/ox_launch
                    602: */
                    603:
                    604: void Pox_launch_main(with_x,arg,rp)
                    605: int with_x;
                    606: NODE arg;
                    607: Obj *rp;
                    608: {
                    609:        char *str;
                    610:        char *hostname,*servername,*dname;
                    611:        char *control;
                    612:        int use_unix;
                    613:        extern char *asir_libdir;
                    614:
                    615:        if ( arg && ARG0(arg) && argc(arg) != 3 )
                    616:                error("ox_launch : argument mismatch");
                    617:        control = (char *)MALLOC(BUFSIZ);
                    618:        if ( !arg || ( !ARG0(arg) && argc(arg) == 1 ) ) {
                    619:                sprintf(control,"%s/ox_launch",asir_libdir);
                    620:                use_unix = 1;
                    621:                servername = (char *)MALLOC(BUFSIZ);
                    622:                sprintf(servername,"%s/ox_asir",asir_libdir);
                    623:        } else if ( !ARG0(arg) && argc(arg) == 2 ) {
                    624:                sprintf(control,"%s/ox_launch",asir_libdir);
                    625:                use_unix = 1;
                    626:                str = BDY((STRING)ARG1(arg));
                    627:                if ( str[0] == '/' )
                    628:                        servername = str;
                    629:                else {
                    630:                        servername = (char *)MALLOC(BUFSIZ);
                    631:                        sprintf(servername,"%s/%s",asir_libdir,str);
                    632:                }
                    633:        } else {
                    634:                sprintf(control,"%s/ox_launch",BDY((STRING)ARG1(arg)));
                    635:                if ( !ARG0(arg) )
                    636:                        use_unix = 1;
                    637:                else
                    638:                        use_unix = 0;
                    639:                str = BDY((STRING)ARG2(arg));
                    640:                if ( str[0] == '/' )
                    641:                        servername = str;
                    642:                else {
                    643:                        servername = (char *)MALLOC(BUFSIZ);
                    644:                        sprintf(servername,"%s/%s",BDY((STRING)ARG1(arg)),str);
                    645:                }
                    646:        }
                    647:        if ( arg && ARG0(arg) )
                    648:                hostname = BDY((STRING)ARG0(arg));
                    649:        else
                    650:                hostname = 0;
                    651:        ox_launch_generic(hostname,control,servername,use_unix,0,with_x,0,rp);
                    652: }
                    653:
                    654: int register_server(af_unix,m,c)
                    655: int af_unix,m,c;
                    656: {
                    657:        int s,i,ci;
                    658:        struct m_c *t;
1.9       noro      659: #define INIT_TAB_SIZ 64
1.1       noro      660:
                    661:        if ( c < 0 )
                    662:                return -1;
                    663:        if ( !m_c_tab ) {
1.9       noro      664:                s = INIT_TAB_SIZ*sizeof(struct m_c);
1.8       noro      665:                m_c_tab = (struct m_c *)MALLOC_ATOMIC(s);
1.9       noro      666:                for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8       noro      667:                        m_c_tab[i].af_unix = 0;
                    668:                        m_c_tab[i].m = m_c_tab[i].c = -1;
                    669:                }
1.9       noro      670:                m_c_s = INIT_TAB_SIZ;
1.1       noro      671:        }
                    672: #if !MPI
                    673:        for ( i = 0; i < m_c_i; i++ )
1.8       noro      674:                if ( (m_c_tab[i].m<0) && (m_c_tab[i].c<0) )
1.1       noro      675:                        break;
                    676:        if ( i < m_c_i ) {
                    677:                m_c_tab[i].m = m; m_c_tab[i].c = c;
                    678:                m_c_tab[i].af_unix = af_unix;
                    679:                return i;
                    680:        }
                    681: #endif
                    682:        if ( m_c_i == m_c_s ) {
1.9       noro      683:                s = (m_c_s+INIT_TAB_SIZ)*sizeof(struct m_c);
1.1       noro      684:                t = (struct m_c *)MALLOC_ATOMIC(s); bzero(m_c_tab,s);
                    685:                bcopy(m_c_tab,t,m_c_s*sizeof(struct m_c));
1.9       noro      686:                for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8       noro      687:                        m_c_tab[m_c_s+i].af_unix = 0;
                    688:                        m_c_tab[m_c_s+i].m = m_c_tab[m_c_s+i].c = -1;
                    689:                }
1.9       noro      690:                m_c_s += INIT_TAB_SIZ; m_c_tab = t;
1.1       noro      691:        }
                    692:        m_c_tab[m_c_i].m = m; m_c_tab[m_c_i].c = c;
                    693:        m_c_tab[m_c_i].af_unix = af_unix;
                    694:        return m_c_i++;
                    695: }
                    696:
                    697: /* iofp index => m_c_tab index */
                    698:
                    699: int get_mcindex(i)
                    700: int i;
                    701: {
                    702:        int j;
                    703:
                    704:        for ( j = 0; j < m_c_i; j++ )
                    705:                if ( m_c_tab[j].c == i )
                    706:                        return j;
                    707:        return -1;
                    708: }
                    709:
                    710: /* arg = [ind0,ind1,...]; indk = index to m_c_tab */
                    711:
                    712: void Pox_select(arg,rp)
                    713: NODE arg;
                    714: LIST *rp;
                    715: {
                    716:        int fd,n,i,index,mcind;
                    717:        fd_set r,w,e;
                    718:        NODE list,t,t1;
                    719:        Q q;
                    720:        double max;
                    721:        struct timeval interval;
                    722:        struct timeval *tvp;
                    723:
                    724:        list = BDY((LIST)ARG0(arg)); arg = NEXT(arg);
                    725:        if ( arg ) {
                    726:                max = ToReal((Num)BDY(arg));
                    727:                interval.tv_sec = (int)max;
                    728:                interval.tv_usec = (int)((max-(int)max)*1000000);
                    729:                tvp = &interval;
                    730:        } else
                    731:                tvp = 0;
                    732:
                    733:        FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
                    734:        for ( t = list; t; t = NEXT(t) ) {
                    735:                index = QTOS((Q)BDY(t));
                    736:                valid_mctab_index(index);
                    737:                fd = get_fd(m_c_tab[index].c); FD_SET(fd,&r);
                    738:        }
                    739:        n = select(FD_SETSIZE,&r,&w,&e,tvp);
                    740:        for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ )
                    741:                if ( FD_ISSET(i,&r) ) {
                    742:                        /* index : index to iofp array */
                    743:                        index = get_index(i);
                    744:                        /* mcind : index to m_c_tab array */
                    745:                        mcind = get_mcindex(index);
                    746:                        n--; STOQ(mcind,q); MKNODE(t1,q,t); t = t1;
                    747:                }
                    748:        MKLIST(*rp,t);
                    749: }
                    750:
                    751: void Pox_flush(arg,rp)
                    752: NODE arg;
                    753: Q *rp;
                    754: {
                    755:        int index = QTOS((Q)ARG0(arg));
                    756:
                    757:        valid_mctab_index(index);
                    758:        ox_flush_stream_force(m_c_tab[index].c);
                    759:        *rp = ONE;
                    760: }
                    761:
1.8       noro      762: void Pox_send_raw_cmo(arg,rp)
                    763: NODE arg;
                    764: Obj *rp;
                    765: {
                    766:        int s;
                    767:        int index = QTOS((Q)ARG0(arg));
                    768:
                    769:        valid_mctab_index(index);
                    770:        s = m_c_tab[index].c;
                    771:        ox_write_cmo(s,(Obj)ARG1(arg));
                    772:        /* flush always */
                    773:        ox_flush_stream(s);
                    774:        *rp = 0;
                    775: }
                    776:
                    777: void Pox_recv_raw_cmo(arg,rp)
                    778: NODE arg;
                    779: Obj *rp;
                    780: {
                    781:        int s;
                    782:        int index = QTOS((Q)ARG0(arg));
                    783:
                    784:        valid_mctab_index(index);
                    785:        s = m_c_tab[index].c;
                    786:        ox_read_cmo(s,rp);
                    787: }
                    788:
1.1       noro      789: void Pox_push_local(arg,rp)
                    790: NODE arg;
                    791: Obj *rp;
                    792: {
                    793:        int s;
                    794:        struct oLIST dummy;
                    795:        VL vl;
                    796:        int index = QTOS((Q)ARG0(arg));
                    797:
                    798:        valid_mctab_index(index);
                    799:        s = m_c_tab[index].c; arg = NEXT(arg);
                    800:
                    801:        dummy.id = O_LIST; dummy.body = arg;
                    802:        get_vars_recursive((Obj)&dummy,&vl);
                    803:
                    804:        ox_send_local_ring(s,vl);
                    805:        for ( ; arg; arg = NEXT(arg) )
                    806:                ox_send_local_data(s,BDY(arg));
                    807:        *rp = 0;
                    808: }
                    809:
                    810: void Pox_push_cmo(arg,rp)
                    811: NODE arg;
                    812: Obj *rp;
                    813: {
                    814:        int s;
                    815:        int index = QTOS((Q)ARG0(arg));
                    816:
                    817:        valid_mctab_index(index);
                    818:        s = m_c_tab[index].c; arg = NEXT(arg);
                    819:        for ( ; arg; arg = NEXT(arg) )
                    820:                ox_send_data(s,BDY(arg));
                    821:        *rp = 0;
                    822: }
                    823:
                    824: void Pox_push_vl(arg,rp)
                    825: NODE arg;
                    826: Obj *rp;
                    827: {
                    828:        int s;
                    829:        int index = QTOS((Q)ARG0(arg));
                    830:
                    831:        valid_mctab_index(index);
                    832:        ox_send_local_ring(m_c_tab[index].c,CO);
                    833:        *rp = 0;
                    834: }
                    835:
                    836: void Pox_pop_local(arg,rp)
                    837: NODE arg;
                    838: Obj *rp;
                    839: {
                    840:        int s;
                    841:        int index = QTOS((Q)ARG0(arg));
                    842:
                    843:        valid_mctab_index(index);
                    844:        s = m_c_tab[index].c;
                    845:        ox_send_cmd(s,SM_popSerializedLocalObject);
                    846:        ox_flush_stream_force(s);
                    847:        ox_get_result(s,rp);
                    848: }
                    849:
                    850: void Pox_pop_cmo(arg,rp)
                    851: NODE arg;
                    852: Obj *rp;
                    853: {
                    854:        int s;
                    855:        int index = QTOS((Q)ARG0(arg));
                    856:
                    857:        valid_mctab_index(index);
                    858:        s = m_c_tab[index].c;
                    859:        ox_send_cmd(s,SM_popCMO);
                    860:        ox_flush_stream_force(s);
                    861:        ox_get_result(s,rp);
                    862: }
                    863:
                    864: void Pox_pop0_local(arg,rp)
                    865: NODE arg;
                    866: Obj *rp;
                    867: {
                    868:        int index = QTOS((Q)ARG0(arg));
                    869:
                    870:        valid_mctab_index(index);
                    871:        ox_send_cmd(m_c_tab[index].c,SM_popSerializedLocalObject);
                    872:        *rp = 0;
                    873: }
                    874:
                    875: void Pox_pop0_cmo(arg,rp)
                    876: NODE arg;
                    877: Obj *rp;
                    878: {
                    879:        int index = QTOS((Q)ARG0(arg));
                    880:
                    881:        valid_mctab_index(index);
                    882:        ox_send_cmd(m_c_tab[index].c,SM_popCMO);
                    883:        *rp = 0;
                    884: }
                    885:
                    886: void Pox_pop0_string(arg,rp)
                    887: NODE arg;
                    888: STRING *rp;
                    889: {
                    890:        int index = QTOS((Q)ARG0(arg));
                    891:
                    892:        valid_mctab_index(index);
                    893:        ox_send_cmd(m_c_tab[index].c,SM_popString);
                    894:        *rp = 0;
                    895: }
                    896:
                    897: void Pox_pop_string(arg,rp)
                    898: NODE arg;
                    899: STRING *rp;
                    900: {
                    901:        int s,id;
                    902:        int index = QTOS((Q)ARG0(arg));
                    903:
                    904:        valid_mctab_index(index);
                    905:        s = m_c_tab[index].c;
                    906:        ox_send_cmd(s,SM_popString);
                    907:        ox_flush_stream_force(s);
                    908:        ox_get_result(s,rp);
                    909: }
                    910:
                    911: void Pox_get(arg,rp)
                    912: NODE arg;
                    913: Obj *rp;
                    914: {
1.3       noro      915:        int index;
1.1       noro      916:        int s;
                    917:
1.3       noro      918:        if ( !arg ) {
                    919:                /* client->server */
                    920:                ox_get_result(0,rp);
                    921:        } else {
                    922:                /* server->client */
                    923:                index = QTOS((Q)ARG0(arg));
                    924:                valid_mctab_index(index);
                    925:                s = m_c_tab[index].c;
                    926:                ox_flush_stream_force(s);
                    927:                ox_get_result(s,rp);
                    928:        }
1.1       noro      929: }
                    930:
                    931: void Pox_pops(arg,rp)
                    932: NODE arg;
                    933: Obj *rp;
                    934: {
                    935:        int s;
                    936:        USINT n;
                    937:        int index = QTOS((Q)ARG0(arg));
                    938:
                    939:        valid_mctab_index(index);
                    940:        s = m_c_tab[index].c;
                    941:        if ( NEXT(arg) )
                    942:                MKUSINT(n,QTOS((Q)ARG1(arg)));
                    943:        else
                    944:                MKUSINT(n,1);
                    945:        ox_send_data(s,n);
                    946:        ox_send_cmd(s,SM_pops);
                    947:        *rp = 0;
                    948: }
                    949:
                    950: void Pox_execute_function(arg,rp)
                    951: NODE arg;
                    952: Obj *rp;
                    953: {
                    954:        int s;
                    955:        USINT ui;
                    956:        int index = QTOS((Q)ARG0(arg));
                    957:
                    958:        valid_mctab_index(index);
                    959:        s = m_c_tab[index].c;
                    960:        MKUSINT(ui,QTOS((Q)ARG2(arg)));
                    961:        ox_send_data(s,ui);
                    962:        ox_send_data(s,ARG1(arg));
                    963:        ox_send_cmd(s,SM_executeFunction);
                    964:        *rp = 0;
                    965: }
                    966:
                    967: void Pox_setname(arg,rp)
                    968: NODE arg;
                    969: Obj *rp;
                    970: {
                    971:        int s;
                    972:        int index = QTOS((Q)ARG0(arg));
                    973:
                    974:        valid_mctab_index(index);
                    975:        s = m_c_tab[index].c;
                    976:        ox_send_data(s,ARG1(arg));
                    977:        ox_send_cmd(s,SM_setName);
                    978:        *rp = 0;
                    979: }
                    980:
                    981: void Pox_evalname(arg,rp)
                    982: NODE arg;
                    983: Obj *rp;
                    984: {
                    985:        int s;
                    986:        int index = QTOS((Q)ARG0(arg));
                    987:
                    988:        valid_mctab_index(index);
                    989:        s = m_c_tab[index].c;
                    990:        ox_send_data(s,ARG1(arg));
                    991:        ox_send_cmd(s,SM_evalName);
                    992:        *rp = 0;
                    993: }
                    994:
                    995: void Pox_execute_string(arg,rp)
                    996: NODE arg;
                    997: Obj *rp;
                    998: {
                    999:        int s;
                   1000:        int index = QTOS((Q)ARG0(arg));
                   1001:
                   1002:        valid_mctab_index(index);
                   1003:        s = m_c_tab[index].c;
                   1004:        ox_send_data(s,ARG1(arg));
                   1005:        ox_send_cmd(s,SM_executeStringByLocalParser);
                   1006:        *rp = 0;
                   1007: }
                   1008:
                   1009: /* arg=[sid,fname,arg0,arg1,...,arg{n-1}] */
                   1010:
                   1011: void Pox_rpc(arg,rp)
                   1012: NODE arg;
                   1013: Obj *rp;
                   1014: {
                   1015:        int s,i,n;
                   1016:        STRING f;
                   1017:        USINT ui;
                   1018:        pointer *w;
                   1019:        NODE t;
                   1020:        int index = QTOS((Q)ARG0(arg));
                   1021:
                   1022:        valid_mctab_index(index);
                   1023:        s = m_c_tab[index].c; arg = NEXT(arg);
                   1024:        f = (STRING)BDY(arg); arg = NEXT(arg);
                   1025:        ox_send_local_ring(s,CO);
                   1026:        for ( n = 0, t = arg; t; t = NEXT(t), n++ );
                   1027:        w = (pointer *)ALLOCA(n*sizeof(pointer));
                   1028:        for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
                   1029:                w[i] = BDY(t);
                   1030:        for ( i = n-1; i >= 0; i-- )
                   1031:                ox_send_local_data(s,w[i]);
                   1032:        MKUSINT(ui,n);
                   1033:        ox_send_data(s,ui);
                   1034:        ox_send_data(s,f);
                   1035:        ox_send_cmd(s,SM_executeFunction);
                   1036:        *rp = 0;
                   1037: }
                   1038:
                   1039: void Pox_cmo_rpc(arg,rp)
                   1040: NODE arg;
                   1041: Obj *rp;
                   1042: {
                   1043:        int s,i,n;
                   1044:        STRING f;
                   1045:        USINT ui;
                   1046:        NODE t;
                   1047:        pointer *w;
                   1048:        int index = QTOS((Q)ARG0(arg));
                   1049:
                   1050:        valid_mctab_index(index);
                   1051:        s = m_c_tab[index].c; arg = NEXT(arg);
                   1052:        f = (STRING)BDY(arg); arg = NEXT(arg);
                   1053:        for ( n = 0, t = arg; t; t = NEXT(t), n++ );
                   1054:        w = (pointer *)ALLOCA(n*sizeof(pointer));
                   1055:        for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
                   1056:                w[i] = BDY(t);
                   1057:        for ( i = n-1; i >= 0; i-- )
                   1058:                ox_send_data(s,w[i]);
                   1059:        MKUSINT(ui,n);
                   1060:        ox_send_data(s,ui);
                   1061:        ox_send_data(s,f);
                   1062:        ox_send_cmd(s,SM_executeFunction);
                   1063:        *rp = 0;
                   1064: }
                   1065:
                   1066: void Pox_reset(arg,rp)
                   1067: NODE arg;
                   1068: Q *rp;
                   1069: {
                   1070:        USINT t;
                   1071:        int s,id,c,m;
                   1072:        Obj obj;
                   1073:        int index = QTOS((Q)ARG0(arg));
                   1074:
                   1075:        valid_mctab_index(index);
                   1076:        m = m_c_tab[index].m;
                   1077:        c = m_c_tab[index].c;
                   1078:        if ( m >= 0 ) {
                   1079:                if ( argc(arg) == 1 ) {
                   1080:                        ox_send_cmd(m,SM_control_reset_connection);
                   1081:                        ox_flush_stream_force(m);
                   1082:                        ox_recv(m,&id,&t);
                   1083:                }
                   1084:                *rp = ONE;
                   1085: #if defined(VISUAL)
                   1086:                Sleep(100);
                   1087:                ox_send_cmd(c,SM_nop);
                   1088:                ox_flush_stream_force(c);
                   1089: #endif
                   1090:                while ( 1 ) {
                   1091:                        ox_recv(c,&id,&obj);
                   1092:                        if ( id == OX_SYNC_BALL )
                   1093:                                break;
                   1094:                }
                   1095:                ox_send_sync(c);
1.5       noro     1096:        } else
                   1097:                *rp = 0;
                   1098: }
                   1099:
                   1100: void Pox_intr(arg,rp)
                   1101: NODE arg;
                   1102: Q *rp;
                   1103: {
                   1104:        int m;
                   1105:        Obj obj;
                   1106:        int index = QTOS((Q)ARG0(arg));
                   1107:
                   1108:        valid_mctab_index(index);
                   1109:        m = m_c_tab[index].m;
                   1110:        if ( m >= 0 ) {
                   1111:                if ( argc(arg) == 1 ) {
                   1112:                        ox_send_cmd(m,SM_control_intr);
                   1113:                        ox_flush_stream_force(m);
                   1114:                }
                   1115:                *rp = ONE;
1.1       noro     1116:        } else
                   1117:                *rp = 0;
                   1118: }
                   1119:
                   1120: void Pox_sync(arg,rp)
                   1121: NODE arg;
                   1122: Q *rp;
                   1123: {
                   1124:        int c;
                   1125:        int index = QTOS((Q)ARG0(arg));
                   1126:
                   1127:        valid_mctab_index(index);
                   1128:        c = m_c_tab[index].c;
                   1129:        ox_send_sync(c);
                   1130:        *rp = 0;
                   1131: }
                   1132:
                   1133: void Pox_shutdown(arg,rp)
                   1134: NODE arg;
                   1135: Q *rp;
                   1136: {
                   1137:        int s;
                   1138:        int index = QTOS((Q)ARG0(arg));
                   1139:        int status;
                   1140:
                   1141:        valid_mctab_index(index);
                   1142:        s = m_c_tab[index].m;
                   1143:        ox_send_cmd(s,SM_shutdown);
                   1144:        free_iofp(s);
                   1145: #if !MPI && !defined(VISUAL)
                   1146:        if ( m_c_tab[index].af_unix )
                   1147:                wait(&status);
                   1148: #endif
1.8       noro     1149:        m_c_tab[index].m = -1; m_c_tab[index].c = -1;
1.1       noro     1150:        m_c_tab[index].af_unix = 0;
                   1151:        *rp = 0;
                   1152: }
                   1153:
                   1154: void Pox_push_cmd(arg,rp)
                   1155: NODE arg;
                   1156: Q *rp;
                   1157: {
1.7       noro     1158:        int ui;
1.1       noro     1159:        int index = QTOS((Q)ARG0(arg));
                   1160:
                   1161:        valid_mctab_index(index);
1.7       noro     1162:        ui = QTOS((Q)ARG1(arg));
1.1       noro     1163:        ox_send_cmd(m_c_tab[index].c,ui);
                   1164:        *rp = 0;
                   1165: }
                   1166: #endif
1.16      noro     1167:
                   1168: void shutdown_all() {
                   1169:        int s;
                   1170:        int i,index;
                   1171:        int status;
                   1172:
                   1173:        for ( i = I_am_server?1:0; i < m_c_i; i++ ) {
                   1174:                index = i;
                   1175:                check_valid_mctab_index(index);
                   1176:                if ( index < 0 )
                   1177:                        continue;
                   1178:                s = m_c_tab[index].m;
                   1179:                ox_send_cmd(s,SM_shutdown);
                   1180:                free_iofp(s);
                   1181: #if !MPI && !defined(VISUAL)
                   1182:                if ( m_c_tab[index].af_unix )
                   1183:                        wait(&status);
                   1184: #endif
                   1185:                m_c_tab[index].m = 0; m_c_tab[index].c = 0;
                   1186:                m_c_tab[index].af_unix = 0;
                   1187:        }
                   1188: }

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