delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/04/16/01:45:30

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <20050416054513.24152.qmail@web32214.mail.mud.yahoo.com>
Date: Fri, 15 Apr 2005 22:45:13 -0700 (PDT)
From: Tony Jaa <tonyjaa12321 AT yahoo DOT com>
Subject: 1.5.12-1: poll bug (Windows 2000)
To: cygwin AT cygwin DOT com
MIME-Version: 1.0

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019