=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/tcpf.c,v retrieving revision 1.51 retrieving revision 1.58 diff -u -p -r1.51 -r1.58 --- OpenXM_contrib2/asir2000/io/tcpf.c 2004/03/05 06:14:50 1.51 +++ OpenXM_contrib2/asir2000/io/tcpf.c 2010/09/01 08:01:09 1.58 @@ -44,7 +44,7 @@ * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. - * $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.50 2003/12/13 08:03:56 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/tcpf.c,v 1.57 2010/04/23 04:44:52 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -89,10 +89,10 @@ if((ind)<0||(ind)>=mpi_nprocs){error("invalid server i if((ind)<0||(ind)>=mpi_nprocs){(ind)=-1;} #else #define valid_mctab_index(ind)\ -if((ind)<0||(ind)>=m_c_i||\ +if((ind)=m_c_i||\ ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){error("invalid server id");} #define check_valid_mctab_index(ind)\ -if((ind)<0||(ind)>=m_c_i||\ +if((ind)=m_c_i||\ ((m_c_tab[ind].m<0)&&(m_c_tab[ind].c<0))){(ind)=-1;} #endif @@ -490,6 +490,49 @@ void Pregister_server(NODE arg,Q *rp) STOQ(ind,*rp); } +#if !defined(VISUAL) +#include +#include +#include +#include + +static int find_executable(char *); +static int find_executable_main(char *); + +static int find_executable(char *com) +{ + char *c,*s; + int len; + char dir[BUFSIZ],path[BUFSIZ]; + + for ( s = (char *)getenv("PATH"); s; ) { + c = (char *)index(s,':'); + if ( c ) { + len = c-s; + strncpy(dir,s,len); s = c+1; dir[len] = 0; + } else { + strcpy(dir,s); s = 0; + } + sprintf(path,"%s/%s",dir,com); + if ( find_executable_main(path) ) + return 1; + } + return 0; +} + +static int find_executable_main(char *file) +{ + struct stat buf; + + if ( stat(file,&buf) || (buf.st_mode & S_IFDIR) ) + return 0; + if ( access(file,X_OK) ) + return 0; + else + return 1; +} + +#endif /* ox_launch_generic(host,launcher,server,use_unix,use_ssh,use_x,conn_to_serv) @@ -523,6 +566,45 @@ void Pox_launch_generic(NODE arg,Q *rp) *rp = ret; } +#if 0 +void ox_launcher_101_generic(char *host,char *launcher, + int use_unix,int use_ssh,int use_x,int conn_to_serv,Q *rp) +{ + int cs,cn,ind,id; + char control_port_str[BUFSIZ]; + Obj obj; + +#if !defined(VISUAL) + if ( use_unix && !find_executable("xterm") ) use_x = 0; +#endif + control_port_str[0] = 0; + do { + generate_port(use_unix,control_port_str); + if ( conn_to_serv ) { + spawn_server_101(host,launcher, + use_unix,use_ssh,use_x,conn_to_serv, + control_port_str); + cs = try_connect(use_unix,host,control_port_str); + } else { + cs = try_bind_listen(use_unix,control_port_str); + if ( cs < 0 ) continue; + spawn_laucher_101(host,launcher, + use_unix,use_ssh,use_x,conn_to_serv, + control_port_str); + cs = try_accept(use_unix,cs); + } + } while ( cs < 0 ); + + /* client mode */ + cn = get_iofp(cs,control_port_str,0); + + /* register server to the server list */ + ind = register_server_101(use_unix,cn); + + STOQ(ind,*rp); +} +#endif + void ox_launch_generic(char *host,char *launcher,char *server, int use_unix,int use_ssh,int use_x,int conn_to_serv,Q *rp) { @@ -532,6 +614,9 @@ void ox_launch_generic(char *host,char *launcher,char Obj obj; MATHCAP server_mathcap; +#if !defined(VISUAL) + if ( use_unix && !find_executable("xterm") ) use_x = 0; +#endif control_port_str[0] = 0; server_port_str[0] = 0; do { @@ -741,7 +826,7 @@ void spawn_server(char *host,char *launcher,char *serv setpgid(0,getpid()); execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname, "-geometry","60x10","-xrm","XTerm*locale:false","-e",launcher,use_unix?".":"127.1",conn_str, - control_port_str,server_port_str,server,dname,0); + control_port_str,server_port_str,server,dname,(char *)0); } } else if ( dname && get_start_path(win_start) ) { sprintf(cmd,"%s %s %s %s %s %s %s 1", @@ -752,7 +837,7 @@ void spawn_server(char *host,char *launcher,char *serv if ( !fork() ) { setpgid(0,getpid()); execlp(launcher,launcher,use_unix?".":"127.1",conn_str, - control_port_str,server_port_str,server,dname0,"-nolog",0); + control_port_str,server_port_str,server,dname0,"-nolog",(char *)0); } } #else @@ -761,10 +846,10 @@ void spawn_server(char *host,char *launcher,char *serv if ( dname ) execlp("xterm","xterm","-name",OX_XTERM,"-T","ox_launch:local","-display",dname, "-geometry","60x10","-xrm","XTerm*locale:false","-e",launcher,use_unix?".":"127.1",conn_str, - control_port_str,server_port_str,server,dname,0); + control_port_str,server_port_str,server,dname,(char *)0); else execlp(launcher,launcher,use_unix?".":"127.1",conn_str, - control_port_str,server_port_str,server,dname0,"-nolog",0); + control_port_str,server_port_str,server,dname0,"-nolog",(char *)0); } #endif } else if ( conn_to_serv == 2 ) { @@ -932,9 +1017,9 @@ int get_mcindex(int i) void Pox_select(NODE arg,LIST *rp) { - int fd,n,i,index,mcind; + int fd,n,i,index,mcind,s; fd_set r,w,e; - NODE list,t,t1; + NODE list,t,t1,t0; Q q; double max; struct timeval interval; @@ -950,11 +1035,20 @@ void Pox_select(NODE arg,LIST *rp) tvp = 0; FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e); - for ( t = list; t; t = NEXT(t) ) { + for ( t = list, t0 = 0; t; t = NEXT(t) ) { index = QTOS((Q)BDY(t)); valid_mctab_index(index); - fd = get_fd(m_c_tab[index].c); FD_SET((unsigned int)fd,&r); + s = m_c_tab[index].c; + if ( ox_data_is_available(s) ) { + MKNODE(t1,(Q)BDY(t),t0); t0 = t1; + } else { + fd = get_fd(s); FD_SET((unsigned int)fd,&r); + } } + if ( t0 ) { + MKLIST(*rp,t0); return; + } + n = select(FD_SETSIZE,&r,&w,&e,tvp); for ( i = 0, t = 0; n && i < FD_SETSIZE; i++ ) if ( FD_ISSET(i,&r) ) { @@ -1237,6 +1331,7 @@ void Pox_execute_string(NODE arg,Obj *rp) int s; int index = QTOS((Q)ARG0(arg)); + asir_assert(ARG1(arg),O_STR,"ox_execute_string"); valid_mctab_index(index); s = m_c_tab[index].c; ox_send_data(s,ARG1(arg)); @@ -1278,9 +1373,12 @@ void Pox_cmo_rpc(NODE arg,Obj *rp) STRING f; USINT ui; NODE t; + Obj dmy; pointer *w; int index = QTOS((Q)ARG0(arg)); + int sync,find; + find = get_opt("sync",&sync); valid_mctab_index(index); s = m_c_tab[index].c; arg = NEXT(arg); f = (STRING)BDY(arg); arg = NEXT(arg); @@ -1293,7 +1391,11 @@ void Pox_cmo_rpc(NODE arg,Obj *rp) MKUSINT(ui,n); ox_send_data(s,ui); ox_send_data(s,f); - ox_send_cmd(s,SM_executeFunction); + if ( find && sync ) { + ox_send_cmd(s,SM_executeFunctionSync); + ox_get_result(s,&dmy); + } else + ox_send_cmd(s,SM_executeFunction); *rp = 0; }