Re: poll() incompatability with POSIX.1-2001

Jogchem de Groot (bighawk@kryptology.org)
Tue, 15 Oct 2002 09:47:00 +0200


On Tuesday 15 October 2002 05:36, you wrote:

> This is the result on a return from poll().
>
> glee@orion ~/tmp $ ./poll-new -h xx.xx.xx.xx -p 80
> connect
> connect: INPROGRESS
> poll: POLLOUT is set
> terminating
> glee@orion ~/tmp $
>
>
> So, POLLOUT is set.
>
>
> Now, we try to connect to an invalid port.
>
> n ~/tmp $ ./poll-new -h xx.xx.xx.xx -p 4
> connect
> connect: INPROGRESS
> poll: POLLERR set
> poll: POLLHUP set
> poll: POLLOUT is set
> terminating
> glee@orion ~/tmp $
>
>
> So, POLLOUT is set.

Hello, on what version did you try this? I've tried this now on
Linux-2.4.18 and Linux-2.4.19 and both give the behaviour i described
previously (No POLLOUT set).

The simple test program i used is as follows:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <sys/select.h>
#include <errno.h>

main(int argc, char **argv) {
int sd,flags,stat,len=sizeof(int);
struct sockaddr_in sin;
struct pollfd pfd;

memset(&sin, 0, sizeof(sin));

sd = socket(AF_INET, SOCK_STREAM, 0);
fcntl(sd, F_SETFL, fcntl(sd, F_GETFL, 0) | O_NONBLOCK);

sin.sin_addr.s_addr = htonl(0x7f000001);
sin.sin_port = htons(atoi(argv[1]));
sin.sin_family = AF_INET;

if(connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1 && errno ==
EINPROGRESS)
printf("connect returned EINPROGRESS\n");

pfd.fd = sd;
pfd.events = POLLIN | POLLOUT;
pfd.revents = 0;

poll(&pfd, 1, -1);
getsockopt(sd, SOL_SOCKET, SO_ERROR, &stat, &len);
printf("%s\n", stat ? "failed" : "succeeded");
printf("returned events: %hd\n", pfd.revents);
}

bighawk

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/