16881f68fSopenharmony_ci/* 26881f68fSopenharmony_ci FUSE fselclient: FUSE select example client 36881f68fSopenharmony_ci Copyright (C) 2008 SUSE Linux Products GmbH 46881f68fSopenharmony_ci Copyright (C) 2008 Tejun Heo <teheo@suse.de> 56881f68fSopenharmony_ci 66881f68fSopenharmony_ci This program can be distributed under the terms of the GNU GPLv2. 76881f68fSopenharmony_ci See the file COPYING. 86881f68fSopenharmony_ci*/ 96881f68fSopenharmony_ci 106881f68fSopenharmony_ci/** @file 116881f68fSopenharmony_ci * 126881f68fSopenharmony_ci * This program tests the poll.c example file systsem. 136881f68fSopenharmony_ci * 146881f68fSopenharmony_ci * Compile with: 156881f68fSopenharmony_ci * 166881f68fSopenharmony_ci * gcc -Wall poll_client.c -o poll_client 176881f68fSopenharmony_ci * 186881f68fSopenharmony_ci * ## Source code ## 196881f68fSopenharmony_ci * \include poll_client.c 206881f68fSopenharmony_ci */ 216881f68fSopenharmony_ci 226881f68fSopenharmony_ci#include <fuse_config.h> 236881f68fSopenharmony_ci 246881f68fSopenharmony_ci#include <sys/select.h> 256881f68fSopenharmony_ci#include <sys/time.h> 266881f68fSopenharmony_ci#include <sys/types.h> 276881f68fSopenharmony_ci#include <sys/stat.h> 286881f68fSopenharmony_ci#include <fcntl.h> 296881f68fSopenharmony_ci#include <unistd.h> 306881f68fSopenharmony_ci#include <ctype.h> 316881f68fSopenharmony_ci#include <stdio.h> 326881f68fSopenharmony_ci#include <stdlib.h> 336881f68fSopenharmony_ci#include <errno.h> 346881f68fSopenharmony_ci 356881f68fSopenharmony_ci#define FSEL_FILES 16 366881f68fSopenharmony_ci 376881f68fSopenharmony_ciint main(void) 386881f68fSopenharmony_ci{ 396881f68fSopenharmony_ci static const char hex_map[FSEL_FILES] = "0123456789ABCDEF"; 406881f68fSopenharmony_ci int fds[FSEL_FILES]; 416881f68fSopenharmony_ci int i, nfds, tries; 426881f68fSopenharmony_ci 436881f68fSopenharmony_ci for (i = 0; i < FSEL_FILES; i++) { 446881f68fSopenharmony_ci char name[] = { hex_map[i], '\0' }; 456881f68fSopenharmony_ci fds[i] = open(name, O_RDONLY); 466881f68fSopenharmony_ci if (fds[i] < 0) { 476881f68fSopenharmony_ci perror("open"); 486881f68fSopenharmony_ci return 1; 496881f68fSopenharmony_ci } 506881f68fSopenharmony_ci } 516881f68fSopenharmony_ci nfds = fds[FSEL_FILES - 1] + 1; 526881f68fSopenharmony_ci 536881f68fSopenharmony_ci for(tries=0; tries < 16; tries++) { 546881f68fSopenharmony_ci static char buf[4096]; 556881f68fSopenharmony_ci fd_set rfds; 566881f68fSopenharmony_ci int rc; 576881f68fSopenharmony_ci 586881f68fSopenharmony_ci FD_ZERO(&rfds); 596881f68fSopenharmony_ci for (i = 0; i < FSEL_FILES; i++) 606881f68fSopenharmony_ci FD_SET(fds[i], &rfds); 616881f68fSopenharmony_ci 626881f68fSopenharmony_ci rc = select(nfds, &rfds, NULL, NULL, NULL); 636881f68fSopenharmony_ci 646881f68fSopenharmony_ci if (rc < 0) { 656881f68fSopenharmony_ci perror("select"); 666881f68fSopenharmony_ci return 1; 676881f68fSopenharmony_ci } 686881f68fSopenharmony_ci 696881f68fSopenharmony_ci for (i = 0; i < FSEL_FILES; i++) { 706881f68fSopenharmony_ci if (!FD_ISSET(fds[i], &rfds)) { 716881f68fSopenharmony_ci printf("_: "); 726881f68fSopenharmony_ci continue; 736881f68fSopenharmony_ci } 746881f68fSopenharmony_ci printf("%X:", i); 756881f68fSopenharmony_ci rc = read(fds[i], buf, sizeof(buf)); 766881f68fSopenharmony_ci if (rc < 0) { 776881f68fSopenharmony_ci perror("read"); 786881f68fSopenharmony_ci return 1; 796881f68fSopenharmony_ci } 806881f68fSopenharmony_ci printf("%02d ", rc); 816881f68fSopenharmony_ci } 826881f68fSopenharmony_ci printf("\n"); 836881f68fSopenharmony_ci } 846881f68fSopenharmony_ci return 0; 856881f68fSopenharmony_ci} 86