=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/mytcpio.c,v retrieving revision 1.4 retrieving revision 1.14 diff -u -p -r1.4 -r1.14 --- OpenXM/src/kan96xx/plugin/mytcpio.c 2000/09/08 16:08:42 1.4 +++ OpenXM/src/kan96xx/plugin/mytcpio.c 2004/02/28 13:39:42 1.14 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/plugin/mytcpio.c,v 1.3 2000/03/20 01:53:47 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/plugin/mytcpio.c,v 1.13 2004/02/25 23:14:35 takayama Exp $ */ #include #include #include @@ -6,6 +6,7 @@ #include #include #include +#include /* -lnsl -lsocket /usr/ucblib/libucb.a */ #include "ox_kan.h" /* @@ -15,10 +16,15 @@ #if defined(sun) int MyEnv_oxmisc[2000]; #else +#if defined(__CYGWIN__) +sigjmp_buf MyEnv_oxmisc; /* may cause a trouble in Solaris. */ +#else jmp_buf MyEnv_oxmisc; /* may cause a trouble in Solaris. */ #endif +#endif #define READBUFSIZE 10000 +#define MAX_LISTEN_QUEUE 3 static void errorMsg1s(char *s) { fprintf(stderr,"%s\n",s); } @@ -33,12 +39,11 @@ 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", - serverName,portNumber); + 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."); return(-1); @@ -47,7 +52,7 @@ socketOpen(char *serverName,int portNumber) { me.sin_family = AF_INET; me.sin_port = htons(portNumber); bcopy(myhost->h_addr, - &me.sin_addr,myhost->h_length); + &me.sin_addr,myhost->h_length); if ((s_waiting = socket(AF_INET,SOCK_STREAM,0)) < 0) { errorMsg1s("Socket allocation is failed."); @@ -69,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); } @@ -84,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); @@ -105,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; ih_addr, - (char *)&server.sin_addr,servhost->h_length); + (char *)&server.sin_addr,servhost->h_length); if ((socketid = socket(AF_INET,SOCK_STREAM,0)) <0) { errorMsg1s("socket allocation is failed.\n"); @@ -258,6 +309,8 @@ socketConnectWithPass(char *servername,int port,char * int m; SET_TCPIOERROR; fd = socketConnect(servername,port); + if ((pass == NULL) && (fd >= 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) {