From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96076330121569.tru64-unix-managers.marc@archive.invalid> From: "Jason M. Heyd" Date: Tue, 26 Mar 1996 21:43:41 +0000 To: tru64-unix-managers Subject: HELP -- OSF OS bug? (fwd) X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96076330121569 Can someone help me explain why the following program exits where it does on a Digital UNIX box in violation (I would say) of the manual entry as well as the Sun and BSDI behavior? Subsequent writing from the socket that select reports is okay get a Broken Pipe error. Jason ------------------------------------------------ /* * Possible bug in non-blocking connect handling. */ #include #include #include #include #include #include #include #include #include #include #include #define PORT 12037 /* port with nothing bound */ int main() { struct sockaddr_in sadr; struct hostent *hostp; struct timeval timeout; fd_set fds; char **addrp; int sock, ret; /* locate host */ hostp = gethostbyname("localhost"); if (hostp == NULL) { perror("gethostbyname"); exit(1); } /* setup internet port */ sadr.sin_family = (u_short)AF_INET; sadr.sin_port = htons(PORT); sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) { perror("socket"); exit(1); } /* make the fd non-blocking */ (void)fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK); (void)memcpy((void *)&sadr.sin_addr, *hostp->h_addr_list, sizeof(sadr.sin_addr)); /* connect or start the connection */ if (connect(sock, (void *)&sadr, sizeof(sadr)) == 0) { (void)printf("Connected\n"); exit(0); } /* not waiting for connection? */ if (errno != EINPROGRESS && errno != EWOULDBLOCK) { perror("socket"); /* * THIS IS THE PROPER ERROR */ exit(1); } FD_ZERO(&fds); timeout.tv_sec = 10; timeout.tv_usec = 0; for (;;) { FD_SET(sock, &fds); ret = select(sock + 1, 0L, &fds, 0L, &timeout); if (ret > 0 && FD_ISSET(sock, &fds)) { (void)printf("Huh? Connected to what????\n"); /* * THIS IS NOT!! PROPER */ exit(0); } if (ret == 0) { (void)printf("Timeout\n"); exit(1); } if (ret < 0 && errno != EINTR) { perror("select"); exit(1); } } }