| 1 | /* |
| 2 | * Abstraction API/layer for the various ways PvPGN can inspect sockets state |
| 3 | * 2003 (C) |
| 4 | * |
| 5 | * Code is based on the ideas found in thttpd project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #ifndef __FDWATCH_INCLUDED__ |
| 23 | #define __FDWATCH_INCLUDED__ |
| 24 | |
| 25 | #include "common/elist.h" |
| 26 | |
| 27 | namespace pvpgn |
| 28 | { |
| 29 | |
| 30 | typedef enum { |
| 31 | fdwatch_type_none = 0, |
| 32 | fdwatch_type_read = 1, |
| 33 | fdwatch_type_write = 2 |
| 34 | } t_fdwatch_type; |
| 35 | |
| 36 | typedef int(*fdwatch_handler)(void *data, t_fdwatch_type); |
| 37 | |
| 38 | struct t_fdwatch_fd { |
| 39 | int fd; |
| 40 | int rw; |
| 41 | fdwatch_handler hnd; |
| 42 | void *data; |
| 43 | |
| 44 | elist_node<t_fdwatch_fd> uselist; |
| 45 | elist_node<t_fdwatch_fd> freelist; |
| 46 | |
| 47 | t_fdwatch_fd() :fd(0), rw(0), hnd(0), data(0), uselist(), freelist() {} |
| 48 | }; |
| 49 | |
| 50 | typedef int(*t_fdw_cb)(t_fdwatch_fd *cfd, void *data); |
| 51 | |
| 52 | extern unsigned fdw_maxcons; |
| 53 | extern t_fdwatch_fd *fdw_fds; |
| 54 | |
| 55 | #define fdw_idx(ptr) ((ptr) - fdw_fds) |
| 56 | #define fdw_fd(ptr) ((ptr)->fd) |
| 57 | #define fdw_rw(ptr) ((ptr)->rw) |
| 58 | #define fdw_data(ptr) ((ptr)->data) |
| 59 | #define fdw_hnd(ptr) ((ptr)->hnd) |
| 60 | extern int fdwatch_init(int maxcons); |
| 61 | extern int fdwatch_close(void); |
| 62 | extern int fdwatch_add_fd(int fd, unsigned rw, fdwatch_handler h, void *data); |
| 63 | extern int fdwatch_update_fd(int idx, unsigned rw); |
| 64 | extern int fdwatch_del_fd(int idx); |
| 65 | extern int fdwatch(long timeout_msecs); |
| 66 | extern void fdwatch_handle(void); |
| 67 | extern void fdwatch_traverse(t_fdw_cb cb, void *data); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | #endif /* __FDWATCH_INCLUDED__ */ |