aboutsummaryrefslogtreecommitdiff
path: root/example/poll_client.c
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-09 19:50:51 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-09 22:03:07 -0700
commitbcad1a6f22662ff0d04a6ae417adb30550252d97 (patch)
tree2c73c2278eca7d7062ffef178669616c3afb1410 /example/poll_client.c
parent463189cd121ce9a9f79d24c207e7c6c31898ea06 (diff)
Renamed ioctl and poll examples
The new names should make it more obvious at first glance what each example demonstrates.
Diffstat (limited to 'example/poll_client.c')
-rw-r--r--example/poll_client.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/example/poll_client.c b/example/poll_client.c
new file mode 100644
index 0000000..5c04fea
--- /dev/null
+++ b/example/poll_client.c
@@ -0,0 +1,87 @@
+/*
+ FUSE fselclient: FUSE select example client
+ Copyright (C) 2008 SUSE Linux Products GmbH
+ Copyright (C) 2008 Tejun Heo <teheo@suse.de>
+
+ This program can be distributed under the terms of the GNU GPL.
+ See the file COPYING.
+*/
+
+/** @file
+ * @tableofcontents
+ *
+ * poll_client.c
+ *
+ * This program tests the poll.c example file systsem.
+ *
+ * \section section_compile compiling this example
+ *
+ * gcc -Wall poll_client.c -o poll_client
+ *
+ * \section section_source the complete source
+ * \include poll_client.c
+ */
+
+#include <config.h>
+
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#define FSEL_FILES 16
+
+int main(void)
+{
+ static const char hex_map[FSEL_FILES] = "0123456789ABCDEF";
+ int fds[FSEL_FILES];
+ int i, nfds, tries;
+
+ for (i = 0; i < FSEL_FILES; i++) {
+ char name[] = { hex_map[i], '\0' };
+ fds[i] = open(name, O_RDONLY);
+ if (fds[i] < 0) {
+ perror("open");
+ return 1;
+ }
+ }
+ nfds = fds[FSEL_FILES - 1] + 1;
+
+ for(tries=0; tries < 16; tries++) {
+ static char buf[4096];
+ fd_set rfds;
+ int rc;
+
+ FD_ZERO(&rfds);
+ for (i = 0; i < FSEL_FILES; i++)
+ FD_SET(fds[i], &rfds);
+
+ rc = select(nfds, &rfds, NULL, NULL, NULL);
+
+ if (rc < 0) {
+ perror("select");
+ return 1;
+ }
+
+ for (i = 0; i < FSEL_FILES; i++) {
+ if (!FD_ISSET(fds[i], &rfds)) {
+ printf("_: ");
+ continue;
+ }
+ printf("%X:", i);
+ rc = read(fds[i], buf, sizeof(buf));
+ if (rc < 0) {
+ perror("read");
+ return 1;
+ }
+ printf("%02d ", rc);
+ }
+ printf("\n");
+ }
+}