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

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

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