Added a simple select() and poll() test application - it's not yet added

to the build because I still need to look into those build issues...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1812 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2002-11-01 03:03:12 +00:00
parent 41aff81700
commit b612edb0d7

View File

@ -0,0 +1,48 @@
/* tests basic select() and poll() functionality */
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <sys/select.h>
#include <poll.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define FILE_NAME "/boot"
int
main(int argc, char **argv)
{
fd_set readSet;
struct pollfd pollfd;
int count;
int file = open(FILE_NAME, O_RDONLY);
if (file < 0) {
fprintf(stderr, "Could not open \"%s\": %s\n", FILE_NAME, strerror(file));
return -1;
}
FD_ZERO(&readSet);
FD_SET(file, &readSet);
puts("selecting...");
count = select(file + 1, &readSet, NULL, NULL, NULL);
printf("\tselect returned: %d (read set = %ld)\n", count, FD_ISSET(file, &readSet));
pollfd.fd = file;
pollfd.events = POLLOUT | POLLERR;
puts("polling...");
count = poll(&pollfd, 1, -1);
printf("\tpoll returned: %d (revents = 0x%x)\n", count, pollfd.revents);
close(file);
return 0;
}