From: "Jason M. Heyd" <heyd () harry ! cis ! pitt ! edu>
To: tru64-unix-managers
Subject: HELP -- OSF OS bug? (fwd)
Date: Tue, 26 Mar 1996 21:43:41 +0000 [thread overview]
Message-ID: <96076330121569.tru64-unix-managers.marc@archive.invalid> (raw)
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 <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#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);
}
}
}
reply other threads:[~1996-03-26 21:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox