=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/mytcpio.c,v retrieving revision 1.2 retrieving revision 1.14 diff -u -p -r1.2 -r1.14 --- OpenXM/src/kan96xx/plugin/mytcpio.c 1999/10/30 02:22:16 1.2 +++ OpenXM/src/kan96xx/plugin/mytcpio.c 2004/02/28 13:39:42 1.14 @@ -1,4 +1,4 @@ -/* $OpenXM$ */ +/* $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,15 +16,21 @@ #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); } -FILE *TcpioError = stdout; +#define SET_TCPIOERROR { if (TcpioError == NULL) TcpioError = stdout; } +FILE *TcpioError = NULL; int OpenedSocket = 0; extern int Quiet; @@ -32,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; - - fprintf(TcpioError,"Hello from open. serverName is %s and portnumber is %d\n", - serverName,portNumber); + SET_TCPIOERROR; + 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); @@ -46,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."); @@ -68,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); } @@ -81,13 +87,18 @@ socketOpen(char *serverName,int portNumber) { socketAccept(int snum) { int s, news; + 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); @@ -100,33 +111,38 @@ socketAcceptLocal(int snum) { struct sockaddr peer; int len; int i; - + + 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"); @@ -250,7 +307,10 @@ socketConnectWithPass(char *servername,int port,char * { int fd; 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) {