=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/mytcpio.c,v retrieving revision 1.6 retrieving revision 1.15 diff -u -p -r1.6 -r1.15 --- OpenXM/src/kan96xx/plugin/mytcpio.c 2002/02/24 10:27:20 1.6 +++ OpenXM/src/kan96xx/plugin/mytcpio.c 2004/11/23 05:28:19 1.15 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/plugin/mytcpio.c,v 1.5 2001/05/04 01:06:30 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/plugin/mytcpio.c,v 1.14 2004/02/28 13:39:42 takayama Exp $ */ #include #include #include @@ -6,6 +6,7 @@ #include #include #include +#include /* -lnsl -lsocket /usr/ucblib/libucb.a */ #include "ox_kan.h" /* @@ -23,6 +24,7 @@ jmp_buf MyEnv_oxmisc; /* may cause a trouble in Solari #endif #define READBUFSIZE 10000 +#define MAX_LISTEN_QUEUE 3 static void errorMsg1s(char *s) { fprintf(stderr,"%s\n",s); } @@ -37,11 +39,10 @@ socketOpen(char *serverName,int portNumber) { static struct sockaddr_in me; static int s_waiting; static int on; - extern int errno; int tt; SET_TCPIOERROR; - fprintf(TcpioError,"Hello from open. serverName is %s and portnumber is %d\n", + if (!Quiet) fprintf(TcpioError,"Hello from open. serverName is %s and portnumber is %d\n", serverName,portNumber); if ((myhost = gethostbyname(serverName)) == NULL) { errorMsg1s("Bad server name."); @@ -73,11 +74,11 @@ socketOpen(char *serverName,int portNumber) { return(-1); } - if (listen(s_waiting,1) < 0) { + if (listen(s_waiting,MAX_LISTEN_QUEUE) < 0) { errorMsg1s("Listen failed"); return(-1); } - fprintf(TcpioError,"Done the initialization. port =%d\n",ntohs(me.sin_port)); + if (!Quiet) fprintf(TcpioError,"Done the initialization. port =%d\n",ntohs(me.sin_port)); OpenedSocket = ntohs(me.sin_port); return(s_waiting); } @@ -88,12 +89,16 @@ socketAccept(int snum) { SET_TCPIOERROR; s = snum; - fprintf(TcpioError,"Trying to accept... "); fflush(TcpioError); + if (!Quiet) {fprintf(TcpioError,"Trying to accept... "); fflush(TcpioError);} if ((news = accept(s,NULL,NULL)) < 0) { - errorMsg1s("Error in accept."); - return(-1); + errorMsg1s("Error in accept. Retrying (socketAccept)."); + /* Code added for strange behavior on cygwin. */ + if ((news = accept(s,NULL,NULL)) < 0) { + errorMsg1s("Error in accept. Retry failed."); + return (-1); + } } - fprintf(TcpioError,"Accepted.\n"); fflush(TcpioError); + if (!Quiet) {fprintf(TcpioError,"Accepted.\n"); fflush(TcpioError);} if (close(s) < 0) { errorMsg1s("Error in closing the old socket."); return(-1); @@ -109,23 +114,27 @@ socketAcceptLocal(int snum) { SET_TCPIOERROR; s = snum; - fprintf(TcpioError,"Trying to accept from localhost... "); fflush(TcpioError); + if (!Quiet) {fprintf(TcpioError,"Trying to accept from localhost... "); fflush(TcpioError);} len = sizeof(struct sockaddr); if ((news = accept(s,&peer,&len)) < 0) { - errorMsg1s("Error in accept."); - return(-1); + errorMsg1s("Error in accept. Retrying"); + /* Code added for strange behavior on cygwin. */ + if ((news = accept(s,&peer,&len)) < 0) { + errorMsg1s("Error in accept. Retry failed."); + return (-1); + } } len = sizeof(struct sockaddr); getpeername(news,&peer,&len); - printf("len= %d\n",len); + if (!Quiet) printf("len= %d\n",len); for (i=0; i= 0)) return fd; + if ((pass == NULL) && (fd < 0)) return -1; if (fd >= 0) { m = write(fd,pass,strlen(pass)+1); if (m != strlen(pass)+1) {