Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

poll and stdin



Dear all,

file descriptor 0 (for stdin) can be used in the poll system call on
Panther, but on Tiger poll immediately returns with revents=POLLNVAL.

The following program show the difference when running on Panther and
Tiger.

On Panther it poll times out every 1000ms and if you enter something
poll returns and read reads the input.

In Tiger, poll immediately returns and you call read which blocks.

Is it a feature or a bug of Tiger that poll() does not support stdin?

Best regards
Michael

#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <stdio.h>
#include <poll.h>

#define BUFFERSIZE 1024

int main()
{
	struct pollfd input;
	char buffer[BUFFERSIZE];
	int n, m;
	
	input.fd      = 0;
	input.events  = POLLIN | POLLPRI;
	input.revents = 0;
	
	while (1) {
		n = poll(&input, 1, 1000);
		printf("poll returned with result = %d and revents = %d.\n",
		       n, input.revents);
		if (n > 0) {
			m = read(0, buffer, sizeof(buffer));
			printf("read returned %d.\n", m);
			if  (m == 0)
				break;
		}
	}
	return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.