bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in select()?


From: Nick Nassar
Subject: Bug in select()?
Date: Sat, 9 Dec 2000 12:58:03 -0500 (EST)

Hi,

I recently tried to get CAIM working under Hurd (from the 20001204 .deb
package) and I found a strange issue with select() and sockets.  It
appears that selects with small timeout values return 0, even when file
descriptors should have changed status.

I've managed to recreate the bug in a little snippet of code that
sends an auth request to the aim server, sleeps five seconds (plenty
of time for the response to come back, even on the slowest
connection), and then runs select on the file descriptor.

Under Linux, the program prints out:
Trying select with 0 delay...
Select responded.  Everything is normal
Trying select with 1000 usec delay...
Select responded.  Everything is normal

Under Hurd, it prints out:
Trying select with 0 delay...
Select did not respond but read returns immediately!
Trying select with 1000 usec delay...
Select responded.  Everything is normal

**** Code Begins Here ****
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <unistd.h>

int main(int argc, char **argv)
{
  struct sockaddr_in sa;
  struct hostent *hp;
  fd_set fds;
  struct timeval tv;
  short port=5190;
  int fd;
  char buf[2];

  hp = gethostbyname2("login.oscar.aol.com", AF_INET);

  memset(&sa.sin_zero, 0, sizeof(sa.sin_zero));
  sa.sin_port = htons(port);
  memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
  sa.sin_family = hp->h_addrtype;

  fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
  connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));

  FD_ZERO(&fds);
  FD_SET(fd, &fds);
  tv.tv_sec = 0;
  tv.tv_usec = 0;

  printf("Trying select with 0 delay...\n");
  fflush(stdout);

  write(fd, 
"*\1\0\1\0O\0\0\0\1\0\1\0\nLinuxBoy42\0\2\0\7\203\322\37\352\342M\310\0\3\0\4\0\0\0\0\0\26\0\2\0\1\0\27\0\2\0\1\0\30\0\2\0\1\0\32\0\2\0\23\0\16\0\2us\0\17\0\2en\0\t\0\2\0\25",85);

  sleep(5);

  if (!select(fd+1, &fds, NULL, &fds, &tv))
    {
      printf("Select did not respond ");
      fflush(stdout);
      if (read(fd,buf,1))
        {
          printf("but read returns immediately!\n");
        }
    }
  else
    {
      printf("Select responded.  Everything is normal\n");
    }

  close(fd);

  fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
  connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));

  FD_ZERO(&fds);
  FD_SET(fd, &fds);
  tv.tv_sec = 0;
  tv.tv_usec = 1000;

  printf("Trying select with 1000 usec delay...\n");
  fflush(stdout);

  write(fd, 
"*\1\0\1\0O\0\0\0\1\0\1\0\nLinuxBoy42\0\2\0\7\203\322\37\352\342M\310\0\3\0\4\0\0\0\0\0\26\0\2\0\1\0\27\0\2\0\1\0\30\0\2\0\1\0\32\0\2\0\23\0\16\0\2us\0\17\0\2en\0\t\0\2\0\25",85);

  sleep(5);

  if (!select(fd+1, &fds, NULL, &fds, &tv))
    {
      printf("Select did not respond ");
      fflush(stdout);
      if (read(fd,buf,1))
        {
          printf("but read returns immediately!\n");
        }
    }
  else
    {
      printf("Select responded.  Everything is normal\n");
    }

  close(fd);


  return 0;
}
**** Code Ends Here ****

Hope this helps,
Nick





reply via email to

[Prev in Thread] Current Thread [Next in Thread]