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

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

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