Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ucbvax!fiamass.ie!fiamass From: fiamass@fiamass.ie (fiamass) Newsgroups: comp.protocols.tcp-ip Subject: select() call weirdness Message-ID: <9101171257.AA13517@fiamass.ie> Date: 17 Jan 91 12:57:45 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 74 We are having a problem with the select() system call on a Sun Sparc 4/65 running SunOS 4.1. We have a non blocking socket which we use to issue a connect(). This call returns EINPROGRESS as per the documentation. The documentation states that under these circumstatances a select() call for write on that socket can be done to determine when the socket is fully connected. Now here is our problem, we make a select() call which always seems to return telling me that the socket is now connected. So on I go and issue a write() which causes the program to bomb out! It is as if the write call does not return. Here us the code. Has anyone any ideas? #include #include #include #include #include #include #include #include main() { char hostname[128]; struct sockaddr_in sockaddr_in_struct; int sockid; struct sockaddr_in server; int retval,length,a,b,c; char x; struct fd_set readfds,writefds,exceptfds; struct timeval timeout; struct hostent *hp,*gethostbyname(); /* Get a socket */ sockid = socket(AF_INET,SOCK_STREAM,0); /* make in NONBLOCKING */ x=1; if(ioctl(sockid,FIONBIO,&x)==-1) printf("Cannot unblock sock socket"); server.sin_family = AF_INET; /* fill in server details */ hp = gethostbyname ("server"); if(hp==0) perror("gethostbyname"); (void)bcopy((char *)hp->h_addr,(char *)&server.sin_addr,hp->h_length); /* set up the servers port number */ server.sin_port = (unsigned short)htons(1395); /* connect up the socket */ /* this call returns with EINPROGRESS */ if(connect(sockid,(struct sockaddr *)&server,sizeof(server))==-1) perror("Connect returns "); /* set up the select call */ timeout.tv_sec=0; timeout.tv_usec=0; FD_ZERO(&writefds); FD_SET(sockid,&writefds); select(FD_SETSIZE,(fd_set *)NULL,&writefds,(fd_set *)NULL,&timeout); /* now see if we can legally write in this socket */ if(FD_ISSET(sockid,&writefds)){ printf("Select says OK to write\n"); /* we get as far as here and then we are bombed back to SUNOS*/ if(write(sockid,"abcdefghij",10) == -1){ perror("Write failed !!"); printf("Explain that one !!\n"); } } printf ("This line never gets printed because the write() call never returns"); }