Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/proto/fd.h |
| 3 | File descriptors states. |
| 4 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 5 | Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6 | |
| 7 | This library is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU Lesser General Public |
| 9 | License as published by the Free Software Foundation, version 2.1 |
| 10 | exclusively. |
| 11 | |
| 12 | This library 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 GNU |
| 15 | Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with this library; if not, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _PROTO_FD_H |
| 23 | #define _PROTO_FD_H |
| 24 | |
| 25 | #include <sys/time.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <unistd.h> |
| 28 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 29 | #include <common/config.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | #include <types/fd.h> |
| 31 | |
| 32 | /* Deletes an FD from the fdsets, and recomputes the maxfd limit. |
| 33 | * The file descriptor is also closed. |
| 34 | */ |
| 35 | void fd_delete(int fd); |
| 36 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 37 | /* registers all known pollers */ |
| 38 | void register_pollers(); |
| 39 | |
| 40 | /* disable the specified poller */ |
| 41 | void disable_poller(const char *poller_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 43 | /* |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 44 | * Initialize the pollers till the best one is found. |
| 45 | * If none works, returns 0, otherwise 1. |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 46 | */ |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 47 | int init_pollers(); |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 48 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 49 | /* |
| 50 | * Runs the polling loop |
| 51 | */ |
| 52 | void run_poller(); |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 53 | |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 54 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 55 | /* FIXME: dirty hack during code transition */ |
| 56 | #define dir_StaticWriteEvent DIR_WR |
| 57 | #define dir_StaticReadEvent DIR_RD |
| 58 | #define dir_DIR_RD DIR_RD |
| 59 | #define dir_DIR_WR DIR_WR |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 60 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 61 | #define MY_FD_SET(fd, ev) (cur_poller.set((fd), dir_##ev)) |
| 62 | #define MY_FD_CLR(fd, ev) (cur_poller.clr((fd), dir_##ev)) |
| 63 | #define MY_FD_ISSET(fd, ev) (cur_poller.isset((fd), dir_##ev)) |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 64 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame^] | 65 | #define EV_FD_SET(fd, ev) (cur_poller.set((fd), dir_##ev)) |
| 66 | #define EV_FD_CLR(fd, ev) (cur_poller.clr((fd), dir_##ev)) |
| 67 | #define EV_FD_ISSET(fd, ev) (cur_poller.isset((fd), dir_##ev)) |
| 68 | #define EV_FD_COND_S(fd, ev) (cur_poller.cond_s((fd), dir_##ev)) |
| 69 | #define EV_FD_COND_C(fd, ev) (cur_poller.cond_c((fd), dir_##ev)) |
| 70 | #define EV_FD_REM(fd) (cur_poller.rem(fd)) |
| 71 | #define EV_FD_CLO(fd) (cur_poller.clo(fd)) |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 72 | |
| 73 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 74 | /* recomputes the maxfd limit from the fd */ |
| 75 | static inline void fd_insert(int fd) |
| 76 | { |
| 77 | if (fd + 1 > maxfd) |
| 78 | maxfd = fd + 1; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | #endif /* _PROTO_FD_H */ |
| 83 | |
| 84 | /* |
| 85 | * Local variables: |
| 86 | * c-indent-level: 8 |
| 87 | * c-basic-offset: 8 |
| 88 | * End: |
| 89 | */ |