1 /* poller - front-end for waiting for I/O functions 2 Copyright (C) 2010 Marek Behun 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #include <stdint.h> 18 19 #ifdef HAVE_EPOLL_WAIT 20 21 # include <sys/epoll.h> 22 # define POLLERIN EPOLLIN 23 # define POLLERPRI EPOLLPRI 24 # define POLLEROUT EPOLLOUT 25 # define POLLERHUP EPOLLHUP 26 # define POLLERERR EPOLLERR 27 28 typedef epoll_data_t pollerdata_t; 29 typedef uint32_t pollerev_t; 30 31 #else /* not HAVE_EPOLL_WAIT */ 32 33 # include <poll.h> 34 # define POLLERIN POLLIN 35 # define POLLERPRI POLLPRI 36 # define POLLEROUT POLLOUT 37 # define POLLERHUP POLLHUP 38 # define POLLERERR POLLERR 39 40 union _pollerdata_union; 41 typedef union _pollerdata_union pollerdata_t; 42 43 union _pollerdata_union 44 { 45 void * ptr; 46 int fd; 47 uint32_t u32; 48 uint64_t u64; 49 }; 50 51 typedef short pollerev_t; 52 53 #endif /* not HAVE_EPOLL_WAIT */ 54 55 typedef void (*pollercb_t) (pollerdata_t data, pollerev_t events); 56 57 int poller_create (); 58 int poller_destroy (int inst); 59 int poller_add (int inst, int fd, pollerev_t events, pollerdata_t data); 60 int poller_modify (int inst, int fd, pollerev_t events, pollerdata_t data); 61 int poller_remove (int inst, int fd); 62 int poller_poll (int inst, int timeout, pollercb_t callback);