This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

1.5.12-1: poll bug (Windows 2000)


Cygwin v1.5.12-1/Windows 2000

Cygwin poll() uses POLLPRI as the flag for detecting
exceptions, POLLPRI must be explicitly set (otherwise
socket exceptions aren't reported), and POLLERR is
only used when select() returns -1 but there was no
WSAENOTCONN. However, the Unix man page for poll()
says POLLPRI is for detecting urgent data to read,
POLLERR is for detecting exceptions, and POLLERR does
not need to be explicitly set in the pollfd.events
field. Why is POLLPRI used for detecting exceptions
instead of POLLERR? Why are exceptions only detected
when POLLPRI is set instead of being detected
automatically?

The following example shows how behavior differs
between Linux and Cygwin. On Linux poll() gives
readable and exception, but on Cygwin poll() only
gives writable.


#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>

int my_connect(const char * a, int p) {
  int s;
  struct sockaddr_in dest;
  struct hostent * h;

  if((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    return -1;

  if ((h = (struct hostent *)gethostbyname(a)))
    dest.sin_addr = *((struct in_addr *)h->h_addr);
  else
    dest.sin_addr.s_addr = inet_addr(a);

  dest.sin_family = AF_INET;
  dest.sin_port = htons(p);

  memset(&(dest.sin_zero), 0, 8);

  fcntl(s, F_SETFL, O_NONBLOCK);

  connect(s, (struct sockaddr *) &dest, sizeof (struct
sockaddr));

  fcntl(s, F_SETFL, 0);

  return s;
}

int pollsd(int sd) {
  int rd, wr, ex;
  struct pollfd p;
  short ret;

  p.fd = sd;
  /* poll() man page says exceptions are reported
automatically */
  p.events = POLLIN | POLLOUT;

  if (poll(&p, 1, 1000) == -1)
    return -1;

  rd = p.revents & POLLIN;
  wr = p.revents & POLLOUT;
  ex = p.revents & POLLERR;

  printf("rd: %s\twr: %s\tex: %s\n",
	 rd ? "YES" : "NO",
	 wr ? "YES" : "NO",
	 ex ? "YES" : "NO");
  return 0;
}

int main(void) {
  int sd, i;

  if((sd = my_connect("12.107.209.250",12321)) == -1)
  {
    printf("CONNECT ERROR\n");
    return -1;
  }

  for (i = 0; i < 32; i++)
  {
    if(pollsd(sd) == -1)
    {
      printf("POLL ERROR\n");
      return -1;
    }
  }

  close(sd);

  return 0;
}



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]