tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* HELP -- OSF OS bug? (fwd)
@ 1996-03-26 21:43 Jason M. Heyd
  0 siblings, 0 replies; only message in thread
From: Jason M. Heyd @ 1996-03-26 21:43 UTC (permalink / raw)
  To: tru64-unix-managers

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);
    }
  }
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-03-26 21:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-03-26 21:43 HELP -- OSF OS bug? (fwd) Jason M. Heyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox