From b612edb0d753879618ea523b54600cd3268ae22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 1 Nov 2002 03:03:12 +0000 Subject: [PATCH] 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 --- src/kernel/apps/select_test.c | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/kernel/apps/select_test.c diff --git a/src/kernel/apps/select_test.c b/src/kernel/apps/select_test.c new file mode 100644 index 0000000000..91588a5e03 --- /dev/null +++ b/src/kernel/apps/select_test.c @@ -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 +#include + +#include +#include +#include +#include + +#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; +} +