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

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.25    ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.24 2001/06/04 02:49:47 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;
1.24      noro      205:        Q s_id;
1.1       noro      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);
1.24      noro      214:                                STOQ(i,s_id);
                    215:                                t = mknode(2,s_id,list);
1.1       noro      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");
1.23      noro      503:        if ( !dname0 )
                    504:                dname0 = "0";
1.17      noro      505:        dname = use_x ? dname0 : 0;
1.1       noro      506:        conn_str = conn_to_serv ? "1" : "0";
1.13      noro      507:        rsh = getenv("ASIR_RSH");
                    508:        if ( !rsh )
                    509:                rsh = use_ssh ? "ssh" : RSH;
1.25    ! noro      510:        if ( !use_unix && strstr(rsh,"ssh") ) {
1.13      noro      511:                /*
                    512:                 * if "ssh" is used to invoke a remote server,
                    513:                 * we should not specify "-display".
                    514:                 */
                    515:                use_ssh = 1;
                    516:        }
1.1       noro      517:        gethostname(localhost,BUFSIZ);
1.15      noro      518: #if defined(VISUAL)
                    519:        if ( !use_unix )
                    520:                error("spawn_server : not implemented on Windows");
                    521:        Pget_rootdir(&rootdir);
                    522:        sprintf(AsirExe,"%s\\bin\\engine.exe",BDY(rootdir));
                    523:        strcpy(prog,server);
                    524:        server = strrchr(prog,'/')+1;
                    525:        av[0] = "ox_launch";
                    526:        av[1] = "127.0.0.1";
                    527:        av[2] = conn_str;
                    528:        av[3] = control_port_str;
                    529:        av[4] = server_port_str;
                    530:        av[5] = server;
                    531:        av[6] = use_x ? "1" : "0";
                    532:        av[7] = 0;
                    533:
                    534:        _spawnv(_P_NOWAIT,AsirExe,av);
                    535: //     _spawnv(_P_NOWAIT,"d:\\home\\noro\\engine2000\\debug\\engine.exe",av);
                    536: //     printf("ox_launch 127.0.0.1 %s %s %s %s 0\n",conn_str,control_port_str,server_port_str,server);
                    537: #else
1.1       noro      538:        if ( use_unix ) {
                    539:                if ( !fork() ) {
1.2       noro      540:                        setpgid(0,getpid());
1.1       noro      541:                        if ( dname )
1.13      noro      542:                                execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname,
1.1       noro      543:                                        "-geometry","60x10","-e",launcher,".",conn_str,
                    544:                                        control_port_str,server_port_str,server,dname,0);
                    545:                        else
                    546:                                execlp(launcher,launcher,".",conn_str,
1.17      noro      547:                                        control_port_str,server_port_str,server,dname0,"-nolog",0);
1.1       noro      548:                }
                    549:        } else if ( conn_to_serv == 2 ) {
                    550:                /* special support for java */
                    551:                if ( dname )
                    552:                        sprintf(cmd,
1.13      noro      553:                                "%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      554:                                rsh,host,launcher,OX_XTERM,dname,server,localhost,control_port_str,server_port_str);
                    555:                else
                    556:                        sprintf(cmd,
                    557:                                "%s -n %s \"(cd %s; java %s -host %s -control %s -data %s)>&/dev/null&\">/dev/null",
                    558:                                rsh,host,launcher,server,localhost,
                    559:                                control_port_str,server_port_str,server);
                    560:                fprintf(stderr,"%s\n",cmd);
                    561:                sleep(20);
                    562: /*             system(cmd); */
1.15      noro      563:        } else {
1.1       noro      564:                if ( dname )
1.13      noro      565:                        if ( use_ssh )
1.25    ! noro      566:                                sprintf(cmd,
1.14      noro      567: "%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      568:                                rsh,host,OX_XTERM,host,launcher,localhost,conn_str,
                    569:                                control_port_str,server_port_str,server,"1");
                    570:                        else
1.25    ! noro      571:                                sprintf(cmd,
1.14      noro      572: "%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      573:                                rsh,host,OX_XTERM,host,dname,launcher,localhost,conn_str,
1.1       noro      574:                                control_port_str,server_port_str,server,dname);
                    575:                else
1.25    ! noro      576:                        if ( use_ssh )
        !           577:                                sprintf(cmd,
        !           578: "%s -f -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
        !           579:                                rsh,host,launcher,localhost,conn_str,
        !           580:                                control_port_str,server_port_str,server,"1","-nolog");
        !           581:                        else
        !           582:                                sprintf(cmd,
1.17      noro      583: "%s -n %s \"%s %s %s %s %s %s %s %s>&/dev/null&\">/dev/null",
1.1       noro      584:                                rsh,host,launcher,localhost,conn_str,
1.17      noro      585:                                control_port_str,server_port_str,server,dname0,"-nolog");
1.1       noro      586:                system(cmd);
                    587:        }
1.15      noro      588: #endif /* VISUAL */
1.1       noro      589: }
                    590:
                    591: void Pox_launch(arg,rp)
                    592: NODE arg;
                    593: Obj *rp;
                    594: {
                    595:        Pox_launch_main(1,arg,rp);
                    596: }
                    597:
                    598: void Pox_launch_nox(arg,rp)
                    599: NODE arg;
                    600: Obj *rp;
                    601: {
                    602:        Pox_launch_main(0,arg,rp);
                    603: }
                    604:
                    605: /*
                    606:        ox_launch() : invoke local ox_asir
                    607:        ox_launch(0,ox_xxx) : invoke local ox_xxx with asir_libdir/ox_launch
                    608:        ox_launch(remote,lib,ox_xxx) : invoke remote ox_xxx with lib/ox_launch
                    609: */
                    610:
                    611: void Pox_launch_main(with_x,arg,rp)
                    612: int with_x;
                    613: NODE arg;
                    614: Obj *rp;
                    615: {
                    616:        char *str;
                    617:        char *hostname,*servername,*dname;
                    618:        char *control;
                    619:        int use_unix;
                    620:        extern char *asir_libdir;
                    621:
                    622:        if ( arg && ARG0(arg) && argc(arg) != 3 )
                    623:                error("ox_launch : argument mismatch");
                    624:        control = (char *)MALLOC(BUFSIZ);
                    625:        if ( !arg || ( !ARG0(arg) && argc(arg) == 1 ) ) {
                    626:                sprintf(control,"%s/ox_launch",asir_libdir);
                    627:                use_unix = 1;
                    628:                servername = (char *)MALLOC(BUFSIZ);
                    629:                sprintf(servername,"%s/ox_asir",asir_libdir);
                    630:        } else if ( !ARG0(arg) && argc(arg) == 2 ) {
                    631:                sprintf(control,"%s/ox_launch",asir_libdir);
                    632:                use_unix = 1;
                    633:                str = BDY((STRING)ARG1(arg));
                    634:                if ( str[0] == '/' )
                    635:                        servername = str;
                    636:                else {
                    637:                        servername = (char *)MALLOC(BUFSIZ);
                    638:                        sprintf(servername,"%s/%s",asir_libdir,str);
                    639:                }
                    640:        } else {
                    641:                sprintf(control,"%s/ox_launch",BDY((STRING)ARG1(arg)));
                    642:                if ( !ARG0(arg) )
                    643:                        use_unix = 1;
                    644:                else
                    645:                        use_unix = 0;
                    646:                str = BDY((STRING)ARG2(arg));
                    647:                if ( str[0] == '/' )
                    648:                        servername = str;
                    649:                else {
                    650:                        servername = (char *)MALLOC(BUFSIZ);
                    651:                        sprintf(servername,"%s/%s",BDY((STRING)ARG1(arg)),str);
                    652:                }
                    653:        }
                    654:        if ( arg && ARG0(arg) )
                    655:                hostname = BDY((STRING)ARG0(arg));
                    656:        else
                    657:                hostname = 0;
                    658:        ox_launch_generic(hostname,control,servername,use_unix,0,with_x,0,rp);
                    659: }
                    660:
                    661: int register_server(af_unix,m,c)
                    662: int af_unix,m,c;
                    663: {
                    664:        int s,i,ci;
                    665:        struct m_c *t;
1.9       noro      666: #define INIT_TAB_SIZ 64
1.1       noro      667:
                    668:        if ( c < 0 )
                    669:                return -1;
                    670:        if ( !m_c_tab ) {
1.9       noro      671:                s = INIT_TAB_SIZ*sizeof(struct m_c);
1.8       noro      672:                m_c_tab = (struct m_c *)MALLOC_ATOMIC(s);
1.9       noro      673:                for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8       noro      674:                        m_c_tab[i].af_unix = 0;
                    675:                        m_c_tab[i].m = m_c_tab[i].c = -1;
                    676:                }
1.9       noro      677:                m_c_s = INIT_TAB_SIZ;
1.1       noro      678:        }
                    679: #if !MPI
                    680:        for ( i = 0; i < m_c_i; i++ )
1.8       noro      681:                if ( (m_c_tab[i].m<0) && (m_c_tab[i].c<0) )
1.1       noro      682:                        break;
                    683:        if ( i < m_c_i ) {
                    684:                m_c_tab[i].m = m; m_c_tab[i].c = c;
                    685:                m_c_tab[i].af_unix = af_unix;
                    686:                return i;
                    687:        }
                    688: #endif
                    689:        if ( m_c_i == m_c_s ) {
1.9       noro      690:                s = (m_c_s+INIT_TAB_SIZ)*sizeof(struct m_c);
1.1       noro      691:                t = (struct m_c *)MALLOC_ATOMIC(s); bzero(m_c_tab,s);
                    692:                bcopy(m_c_tab,t,m_c_s*sizeof(struct m_c));
1.9       noro      693:                for ( i = 0; i < INIT_TAB_SIZ; i++ ) {
1.8       noro      694:                        m_c_tab[m_c_s+i].af_unix = 0;
                    695:                        m_c_tab[m_c_s+i].m = m_c_tab[m_c_s+i].c = -1;
                    696:                }
1.9       noro      697:                m_c_s += INIT_TAB_SIZ; m_c_tab = t;
1.1       noro      698:        }
                    699:        m_c_tab[m_c_i].m = m; m_c_tab[m_c_i].c = c;
                    700:        m_c_tab[m_c_i].af_unix = af_unix;
                    701:        return m_c_i++;
                    702: }
                    703:
                    704: /* iofp index => m_c_tab index */
                    705:
                    706: int get_mcindex(i)
                    707: int i;
                    708: {
                    709:        int j;
                    710:
                    711:        for ( j = 0; j < m_c_i; j++ )
                    712:                if ( m_c_tab[j].c == i )
                    713:                        return j;
                    714:        return -1;
                    715: }
                    716:
                    717: /* arg = [ind0,ind1,...]; indk = index to m_c_tab */
                    718:
                    719: void Pox_select(arg,rp)
                    720: NODE arg;
                    721: LIST *rp;
                    722: {
                    723:        int fd,n,i,index,mcind;
                    724:        fd_set r,w,e;
                    725:        NODE list,t,t1;
                    726:        Q q;
                    727:        double max;
                    728:        struct timeval interval;
                    729:        struct timeval *tvp;
                    730:
                    731:        list = BDY((LIST)ARG0(arg)); arg = NEXT(arg);
                    732:        if ( arg ) {
                    733:                max = ToReal((Num)BDY(arg));
                    734:                interval.tv_sec = (int)max;
                    735:                interval.tv_usec = (int)((max-(int)max)*1000000);
                    736:                tvp = &interval;
                    737:        } else
                    738:                tvp = 0;
                    739:
                    740:        FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
                    741:        for ( t = list; t; t = NEXT(t) ) {
                    742:                index = QTOS((Q)BDY(t));
                    743:                valid_mctab_index(index);
                    744:                fd = get_fd(m_c_tab[index].c); FD_SET(fd,&r);
                    745:        }
                    746:        n = select(FD_SETSIZE,&r,&w,&e,tvp);
                    747:        for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ )
                    748:                if ( FD_ISSET(i,&r) ) {
                    749:                        /* index : index to iofp array */
                    750:                        index = get_index(i);
                    751:                        /* mcind : index to m_c_tab array */
                    752:                        mcind = get_mcindex(index);
                    753:                        n--; STOQ(mcind,q); MKNODE(t1,q,t); t = t1;
                    754:                }
                    755:        MKLIST(*rp,t);
                    756: }
                    757:
                    758: void Pox_flush(arg,rp)
                    759: NODE arg;
                    760: Q *rp;
                    761: {
                    762:        int index = QTOS((Q)ARG0(arg));
                    763:
                    764:        valid_mctab_index(index);
                    765:        ox_flush_stream_force(m_c_tab[index].c);
                    766:        *rp = ONE;
                    767: }
                    768:
1.8       noro      769: void Pox_send_raw_cmo(arg,rp)
                    770: NODE arg;
                    771: Obj *rp;
                    772: {
                    773:        int s;
                    774:        int index = QTOS((Q)ARG0(arg));
                    775:
                    776:        valid_mctab_index(index);
                    777:        s = m_c_tab[index].c;
                    778:        ox_write_cmo(s,(Obj)ARG1(arg));
                    779:        /* flush always */
                    780:        ox_flush_stream(s);
                    781:        *rp = 0;
                    782: }
                    783:
                    784: void Pox_recv_raw_cmo(arg,rp)
                    785: NODE arg;
                    786: Obj *rp;
                    787: {
                    788:        int s;
                    789:        int index = QTOS((Q)ARG0(arg));
                    790:
                    791:        valid_mctab_index(index);
                    792:        s = m_c_tab[index].c;
                    793:        ox_read_cmo(s,rp);
                    794: }
                    795:
1.1       noro      796: void Pox_push_local(arg,rp)
                    797: NODE arg;
                    798: Obj *rp;
                    799: {
                    800:        int s;
                    801:        struct oLIST dummy;
                    802:        VL vl;
                    803:        int index = QTOS((Q)ARG0(arg));
                    804:
                    805:        valid_mctab_index(index);
                    806:        s = m_c_tab[index].c; arg = NEXT(arg);
                    807:
                    808:        dummy.id = O_LIST; dummy.body = arg;
                    809:        get_vars_recursive((Obj)&dummy,&vl);
                    810:
                    811:        ox_send_local_ring(s,vl);
                    812:        for ( ; arg; arg = NEXT(arg) )
                    813:                ox_send_local_data(s,BDY(arg));
                    814:        *rp = 0;
                    815: }
                    816:
                    817: void Pox_push_cmo(arg,rp)
                    818: NODE arg;
                    819: Obj *rp;
                    820: {
                    821:        int s;
                    822:        int index = QTOS((Q)ARG0(arg));
                    823:
                    824:        valid_mctab_index(index);
                    825:        s = m_c_tab[index].c; arg = NEXT(arg);
                    826:        for ( ; arg; arg = NEXT(arg) )
                    827:                ox_send_data(s,BDY(arg));
                    828:        *rp = 0;
                    829: }
                    830:
                    831: void Pox_push_vl(arg,rp)
                    832: NODE arg;
                    833: Obj *rp;
                    834: {
                    835:        int s;
                    836:        int index = QTOS((Q)ARG0(arg));
                    837:
                    838:        valid_mctab_index(index);
                    839:        ox_send_local_ring(m_c_tab[index].c,CO);
                    840:        *rp = 0;
                    841: }
                    842:
                    843: void Pox_pop_local(arg,rp)
                    844: NODE arg;
                    845: Obj *rp;
                    846: {
                    847:        int s;
                    848:        int index = QTOS((Q)ARG0(arg));
                    849:
                    850:        valid_mctab_index(index);
                    851:        s = m_c_tab[index].c;
                    852:        ox_send_cmd(s,SM_popSerializedLocalObject);
                    853:        ox_flush_stream_force(s);
                    854:        ox_get_result(s,rp);
                    855: }
                    856:
                    857: void Pox_pop_cmo(arg,rp)
                    858: NODE arg;
                    859: Obj *rp;
                    860: {
                    861:        int s;
                    862:        int index = QTOS((Q)ARG0(arg));
                    863:
                    864:        valid_mctab_index(index);
                    865:        s = m_c_tab[index].c;
                    866:        ox_send_cmd(s,SM_popCMO);
                    867:        ox_flush_stream_force(s);
                    868:        ox_get_result(s,rp);
                    869: }
                    870:
                    871: void Pox_pop0_local(arg,rp)
                    872: NODE arg;
                    873: Obj *rp;
                    874: {
                    875:        int index = QTOS((Q)ARG0(arg));
                    876:
                    877:        valid_mctab_index(index);
                    878:        ox_send_cmd(m_c_tab[index].c,SM_popSerializedLocalObject);
                    879:        *rp = 0;
                    880: }
                    881:
                    882: void Pox_pop0_cmo(arg,rp)
                    883: NODE arg;
                    884: Obj *rp;
                    885: {
                    886:        int index = QTOS((Q)ARG0(arg));
                    887:
                    888:        valid_mctab_index(index);
                    889:        ox_send_cmd(m_c_tab[index].c,SM_popCMO);
                    890:        *rp = 0;
                    891: }
                    892:
                    893: void Pox_pop0_string(arg,rp)
                    894: NODE arg;
                    895: STRING *rp;
                    896: {
                    897:        int index = QTOS((Q)ARG0(arg));
                    898:
                    899:        valid_mctab_index(index);
                    900:        ox_send_cmd(m_c_tab[index].c,SM_popString);
                    901:        *rp = 0;
                    902: }
                    903:
                    904: void Pox_pop_string(arg,rp)
                    905: NODE arg;
                    906: STRING *rp;
                    907: {
                    908:        int s,id;
                    909:        int index = QTOS((Q)ARG0(arg));
                    910:
                    911:        valid_mctab_index(index);
                    912:        s = m_c_tab[index].c;
                    913:        ox_send_cmd(s,SM_popString);
                    914:        ox_flush_stream_force(s);
                    915:        ox_get_result(s,rp);
                    916: }
                    917:
                    918: void Pox_get(arg,rp)
                    919: NODE arg;
                    920: Obj *rp;
                    921: {
1.3       noro      922:        int index;
1.1       noro      923:        int s;
                    924:
1.3       noro      925:        if ( !arg ) {
                    926:                /* client->server */
                    927:                ox_get_result(0,rp);
                    928:        } else {
                    929:                /* server->client */
                    930:                index = QTOS((Q)ARG0(arg));
                    931:                valid_mctab_index(index);
                    932:                s = m_c_tab[index].c;
                    933:                ox_flush_stream_force(s);
                    934:                ox_get_result(s,rp);
                    935:        }
1.1       noro      936: }
                    937:
                    938: void Pox_pops(arg,rp)
                    939: NODE arg;
                    940: Obj *rp;
                    941: {
                    942:        int s;
                    943:        USINT n;
                    944:        int index = QTOS((Q)ARG0(arg));
                    945:
                    946:        valid_mctab_index(index);
                    947:        s = m_c_tab[index].c;
                    948:        if ( NEXT(arg) )
                    949:                MKUSINT(n,QTOS((Q)ARG1(arg)));
                    950:        else
                    951:                MKUSINT(n,1);
                    952:        ox_send_data(s,n);
                    953:        ox_send_cmd(s,SM_pops);
                    954:        *rp = 0;
                    955: }
                    956:
                    957: void Pox_execute_function(arg,rp)
                    958: NODE arg;
                    959: Obj *rp;
                    960: {
                    961:        int s;
                    962:        USINT ui;
                    963:        int index = QTOS((Q)ARG0(arg));
                    964:
                    965:        valid_mctab_index(index);
                    966:        s = m_c_tab[index].c;
                    967:        MKUSINT(ui,QTOS((Q)ARG2(arg)));
                    968:        ox_send_data(s,ui);
                    969:        ox_send_data(s,ARG1(arg));
                    970:        ox_send_cmd(s,SM_executeFunction);
                    971:        *rp = 0;
                    972: }
                    973:
                    974: void Pox_setname(arg,rp)
                    975: NODE arg;
                    976: Obj *rp;
                    977: {
                    978:        int s;
                    979:        int index = QTOS((Q)ARG0(arg));
                    980:
                    981:        valid_mctab_index(index);
                    982:        s = m_c_tab[index].c;
                    983:        ox_send_data(s,ARG1(arg));
                    984:        ox_send_cmd(s,SM_setName);
                    985:        *rp = 0;
                    986: }
                    987:
                    988: void Pox_evalname(arg,rp)
                    989: NODE arg;
                    990: Obj *rp;
                    991: {
                    992:        int s;
                    993:        int index = QTOS((Q)ARG0(arg));
                    994:
                    995:        valid_mctab_index(index);
                    996:        s = m_c_tab[index].c;
                    997:        ox_send_data(s,ARG1(arg));
                    998:        ox_send_cmd(s,SM_evalName);
                    999:        *rp = 0;
                   1000: }
                   1001:
                   1002: void Pox_execute_string(arg,rp)
                   1003: NODE arg;
                   1004: Obj *rp;
                   1005: {
                   1006:        int s;
                   1007:        int index = QTOS((Q)ARG0(arg));
                   1008:
                   1009:        valid_mctab_index(index);
                   1010:        s = m_c_tab[index].c;
                   1011:        ox_send_data(s,ARG1(arg));
                   1012:        ox_send_cmd(s,SM_executeStringByLocalParser);
                   1013:        *rp = 0;
                   1014: }
                   1015:
                   1016: /* arg=[sid,fname,arg0,arg1,...,arg{n-1}] */
                   1017:
                   1018: void Pox_rpc(arg,rp)
                   1019: NODE arg;
                   1020: Obj *rp;
                   1021: {
                   1022:        int s,i,n;
                   1023:        STRING f;
                   1024:        USINT ui;
                   1025:        pointer *w;
                   1026:        NODE t;
                   1027:        int index = QTOS((Q)ARG0(arg));
                   1028:
                   1029:        valid_mctab_index(index);
                   1030:        s = m_c_tab[index].c; arg = NEXT(arg);
                   1031:        f = (STRING)BDY(arg); arg = NEXT(arg);
                   1032:        ox_send_local_ring(s,CO);
                   1033:        for ( n = 0, t = arg; t; t = NEXT(t), n++ );
                   1034:        w = (pointer *)ALLOCA(n*sizeof(pointer));
                   1035:        for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
                   1036:                w[i] = BDY(t);
                   1037:        for ( i = n-1; i >= 0; i-- )
                   1038:                ox_send_local_data(s,w[i]);
                   1039:        MKUSINT(ui,n);
                   1040:        ox_send_data(s,ui);
                   1041:        ox_send_data(s,f);
                   1042:        ox_send_cmd(s,SM_executeFunction);
                   1043:        *rp = 0;
                   1044: }
                   1045:
                   1046: void Pox_cmo_rpc(arg,rp)
                   1047: NODE arg;
                   1048: Obj *rp;
                   1049: {
                   1050:        int s,i,n;
                   1051:        STRING f;
                   1052:        USINT ui;
                   1053:        NODE t;
                   1054:        pointer *w;
                   1055:        int index = QTOS((Q)ARG0(arg));
                   1056:
                   1057:        valid_mctab_index(index);
                   1058:        s = m_c_tab[index].c; arg = NEXT(arg);
                   1059:        f = (STRING)BDY(arg); arg = NEXT(arg);
                   1060:        for ( n = 0, t = arg; t; t = NEXT(t), n++ );
                   1061:        w = (pointer *)ALLOCA(n*sizeof(pointer));
                   1062:        for ( i = 0, t = arg; i < n; t = NEXT(t), i++ )
                   1063:                w[i] = BDY(t);
                   1064:        for ( i = n-1; i >= 0; i-- )
                   1065:                ox_send_data(s,w[i]);
                   1066:        MKUSINT(ui,n);
                   1067:        ox_send_data(s,ui);
                   1068:        ox_send_data(s,f);
                   1069:        ox_send_cmd(s,SM_executeFunction);
                   1070:        *rp = 0;
                   1071: }
                   1072:
                   1073: void Pox_reset(arg,rp)
                   1074: NODE arg;
                   1075: Q *rp;
                   1076: {
                   1077:        USINT t;
                   1078:        int s,id,c,m;
                   1079:        Obj obj;
                   1080:        int index = QTOS((Q)ARG0(arg));
                   1081:
                   1082:        valid_mctab_index(index);
                   1083:        m = m_c_tab[index].m;
                   1084:        c = m_c_tab[index].c;
                   1085:        if ( m >= 0 ) {
                   1086:                if ( argc(arg) == 1 ) {
                   1087:                        ox_send_cmd(m,SM_control_reset_connection);
                   1088:                        ox_flush_stream_force(m);
                   1089:                        ox_recv(m,&id,&t);
                   1090:                }
                   1091:                *rp = ONE;
                   1092: #if defined(VISUAL)
                   1093:                Sleep(100);
                   1094:                ox_send_cmd(c,SM_nop);
                   1095:                ox_flush_stream_force(c);
                   1096: #endif
                   1097:                while ( 1 ) {
                   1098:                        ox_recv(c,&id,&obj);
                   1099:                        if ( id == OX_SYNC_BALL )
                   1100:                                break;
                   1101:                }
                   1102:                ox_send_sync(c);
1.5       noro     1103:        } else
                   1104:                *rp = 0;
                   1105: }
                   1106:
                   1107: void Pox_intr(arg,rp)
                   1108: NODE arg;
                   1109: Q *rp;
                   1110: {
                   1111:        int m;
                   1112:        Obj obj;
                   1113:        int index = QTOS((Q)ARG0(arg));
                   1114:
                   1115:        valid_mctab_index(index);
                   1116:        m = m_c_tab[index].m;
                   1117:        if ( m >= 0 ) {
                   1118:                if ( argc(arg) == 1 ) {
                   1119:                        ox_send_cmd(m,SM_control_intr);
                   1120:                        ox_flush_stream_force(m);
                   1121:                }
                   1122:                *rp = ONE;
1.1       noro     1123:        } else
                   1124:                *rp = 0;
                   1125: }
                   1126:
                   1127: void Pox_sync(arg,rp)
                   1128: NODE arg;
                   1129: Q *rp;
                   1130: {
                   1131:        int c;
                   1132:        int index = QTOS((Q)ARG0(arg));
                   1133:
                   1134:        valid_mctab_index(index);
                   1135:        c = m_c_tab[index].c;
                   1136:        ox_send_sync(c);
                   1137:        *rp = 0;
                   1138: }
                   1139:
                   1140: void Pox_shutdown(arg,rp)
                   1141: NODE arg;
                   1142: Q *rp;
                   1143: {
                   1144:        int s;
                   1145:        int index = QTOS((Q)ARG0(arg));
                   1146:        int status;
                   1147:
                   1148:        valid_mctab_index(index);
                   1149:        s = m_c_tab[index].m;
                   1150:        ox_send_cmd(s,SM_shutdown);
                   1151:        free_iofp(s);
1.18      noro     1152: #if !defined(VISUAL)
                   1153:        s = m_c_tab[index].c;
                   1154:        free_iofp(s);
                   1155: #endif
1.1       noro     1156: #if !MPI && !defined(VISUAL)
                   1157:        if ( m_c_tab[index].af_unix )
                   1158:                wait(&status);
                   1159: #endif
1.8       noro     1160:        m_c_tab[index].m = -1; m_c_tab[index].c = -1;
1.1       noro     1161:        m_c_tab[index].af_unix = 0;
                   1162:        *rp = 0;
                   1163: }
                   1164:
                   1165: void Pox_push_cmd(arg,rp)
                   1166: NODE arg;
                   1167: Q *rp;
                   1168: {
1.7       noro     1169:        int ui;
1.1       noro     1170:        int index = QTOS((Q)ARG0(arg));
                   1171:
                   1172:        valid_mctab_index(index);
1.7       noro     1173:        ui = QTOS((Q)ARG1(arg));
1.1       noro     1174:        ox_send_cmd(m_c_tab[index].c,ui);
                   1175:        *rp = 0;
                   1176: }
1.16      noro     1177:
                   1178: void shutdown_all() {
                   1179:        int s;
                   1180:        int i,index;
                   1181:        int status;
                   1182:
                   1183:        for ( i = I_am_server?1:0; i < m_c_i; i++ ) {
                   1184:                index = i;
                   1185:                check_valid_mctab_index(index);
                   1186:                if ( index < 0 )
                   1187:                        continue;
                   1188:                s = m_c_tab[index].m;
                   1189:                ox_send_cmd(s,SM_shutdown);
1.21      noro     1190: #if defined(VISUAL)
                   1191:        Sleep(1000);
                   1192: #endif
1.16      noro     1193:                free_iofp(s);
1.18      noro     1194: #if !defined(VISUAL)
                   1195:                s = m_c_tab[index].c;
                   1196:                free_iofp(s);
                   1197: #endif
1.16      noro     1198: #if !MPI && !defined(VISUAL)
                   1199:                if ( m_c_tab[index].af_unix )
                   1200:                        wait(&status);
                   1201: #endif
                   1202:                m_c_tab[index].m = 0; m_c_tab[index].c = 0;
                   1203:                m_c_tab[index].af_unix = 0;
                   1204:        }
                   1205: }

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