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

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

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