1 /* 2 * aprsc 3 * 4 * (c) Heikki Hannikainen, OH7LZB <hessu@hes.iki.fi> 5 * 6 * This program is licensed under the BSD license, which can be found 7 * in the file LICENSE. 8 * 9 */ 10 11 #ifndef XPOLL_H 12 #define XPOLL_H 13 14 // Lots of subsystems use poll(2) call for short timeouts 15 #include <poll.h> 16 17 #include "ac-hdrs.h" 18 19 #ifdef HAVE_SYS_EPOLL_H 20 // Have Linux <sys/epoll.h> 21 #define XP_USE_EPOLL 1 22 #include <sys/epoll.h> 23 24 #else 25 26 #define XP_USE_POLL 1 27 #define XP_INCREMENT 64 // The "struct pollfd" is _small_, avoid mem fragment 28 #endif 29 30 31 #define XP_IN 1 32 #define XP_OUT 2 33 #define XP_ERR 4 34 35 struct xpoll_fd_t { 36 int fd; 37 void *p; /* a fd-specific pointer, which will be passed to handlers */ 38 39 int result; 40 41 #ifdef XP_USE_EPOLL 42 struct epoll_event ev; // event flags for this fd. 43 #else 44 #ifdef XP_USE_POLL 45 int pollfd_n; /* index to xp->pollfd[] */ 46 #endif 47 #endif 48 49 struct xpoll_fd_t *next; 50 struct xpoll_fd_t **prevp; 51 }; 52 53 struct xpoll_t { 54 void *tp; /* an xpoll_t-specific pointer, which will be passed to handlers */ 55 struct xpoll_fd_t *fds; 56 57 int (*handler) (struct xpoll_t *xp, struct xpoll_fd_t *xfd); 58 59 #ifdef XP_USE_EPOLL 60 int epollfd; 61 // #define MAX_EPOLL_EVENTS 32 62 // struct epoll_event events[MAX_EPOLL_EVENTS]; 63 64 #else 65 #ifdef XP_USE_POLL 66 struct pollfd *pollfd; 67 int pollfd_len; 68 #endif 69 #endif 70 int pollfd_used; 71 }; 72 73 extern struct xpoll_t *xpoll_initialize(struct xpoll_t *xp, void *tp, int (*handler) (struct xpoll_t *xp, struct xpoll_fd_t *xfd)); 74 extern int xpoll_free(struct xpoll_t *xp); 75 extern struct xpoll_fd_t *xpoll_add(struct xpoll_t *xp, int fd, void *p); 76 extern int xpoll_remove(struct xpoll_t *xp, struct xpoll_fd_t *xfd); 77 extern void xpoll_outgoing(struct xpoll_t *xp, struct xpoll_fd_t *xfd, int have_outgoing); 78 extern int xpoll(struct xpoll_t *xp, int timeout); 79 extern void xpoll_init(void); 80 81 extern const char xpoll_implementation[]; 82 83 #endif 84