Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 2 | * include/proto/fd.h |
| 3 | * File descriptors states. |
| 4 | * |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 5 | * Copyright (C) 2000-2014 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +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 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
| 22 | #ifndef _PROTO_FD_H |
| 23 | #define _PROTO_FD_H |
| 24 | |
Willy Tarreau | 2ff7622 | 2007-04-09 19:29:56 +0200 | [diff] [blame] | 25 | #include <stdio.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 26 | #include <sys/time.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <unistd.h> |
| 29 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 30 | #include <common/config.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | #include <types/fd.h> |
| 32 | |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 33 | /* public variables */ |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 34 | extern unsigned int *fd_cache; // FD events cache |
| 35 | extern unsigned int *fd_updt; // FD updates list |
| 36 | extern int fd_cache_num; // number of events in the cache |
| 37 | extern int fd_nbupdt; // number of updates in the list |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 38 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | /* Deletes an FD from the fdsets, and recomputes the maxfd limit. |
| 40 | * The file descriptor is also closed. |
| 41 | */ |
| 42 | void fd_delete(int fd); |
| 43 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 44 | /* disable the specified poller */ |
| 45 | void disable_poller(const char *poller_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 46 | |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 47 | /* |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 48 | * Initialize the pollers till the best one is found. |
| 49 | * If none works, returns 0, otherwise 1. |
Willy Tarreau | ef1d1f8 | 2007-04-16 00:25:25 +0200 | [diff] [blame] | 50 | * The pollers register themselves just before main() is called. |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 51 | */ |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 52 | int init_pollers(); |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 53 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 54 | /* |
Krzysztof Piotr Oledzki | a643baf | 2008-05-29 23:53:44 +0200 | [diff] [blame] | 55 | * Deinitialize the pollers. |
| 56 | */ |
| 57 | void deinit_pollers(); |
| 58 | |
| 59 | /* |
Willy Tarreau | 2ff7622 | 2007-04-09 19:29:56 +0200 | [diff] [blame] | 60 | * Some pollers may lose their connection after a fork(). It may be necessary |
| 61 | * to create initialize part of them again. Returns 0 in case of failure, |
| 62 | * otherwise 1. The fork() function may be NULL if unused. In case of error, |
| 63 | * the the current poller is destroyed and the caller is responsible for trying |
| 64 | * another one by calling init_pollers() again. |
| 65 | */ |
| 66 | int fork_poller(); |
| 67 | |
| 68 | /* |
| 69 | * Lists the known pollers on <out>. |
| 70 | * Should be performed only before initialization. |
| 71 | */ |
| 72 | int list_pollers(FILE *out); |
| 73 | |
| 74 | /* |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 75 | * Runs the polling loop |
| 76 | */ |
| 77 | void run_poller(); |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 78 | |
Willy Tarreau | 033cd9d | 2014-01-25 19:24:15 +0100 | [diff] [blame] | 79 | /* Scan and process the cached events. This should be called right after |
Willy Tarreau | 09f2456 | 2012-11-11 16:43:45 +0100 | [diff] [blame] | 80 | * the poller. |
| 81 | */ |
Willy Tarreau | 033cd9d | 2014-01-25 19:24:15 +0100 | [diff] [blame] | 82 | void fd_process_cached_events(); |
Willy Tarreau | 09f2456 | 2012-11-11 16:43:45 +0100 | [diff] [blame] | 83 | |
Willy Tarreau | e852545 | 2014-01-25 09:58:06 +0100 | [diff] [blame] | 84 | /* Check the events attached to a file descriptor, update its cache |
| 85 | * accordingly, and call the associated I/O callback. If new updates are |
| 86 | * detected, the function tries to process them as well in order to save |
| 87 | * wakeups after accept(). |
| 88 | */ |
| 89 | void fd_process_polled_events(int fd); |
| 90 | |
| 91 | |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 92 | /* Mark fd <fd> as updated and allocate an entry in the update list for this if |
| 93 | * it was not already there. This can be done at any time. |
| 94 | */ |
| 95 | static inline void updt_fd(const int fd) |
| 96 | { |
| 97 | if (fdtab[fd].updated) |
| 98 | /* already scheduled for update */ |
| 99 | return; |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 100 | fdtab[fd].updated = 1; |
Willy Tarreau | 4a29144 | 2012-12-13 23:34:18 +0100 | [diff] [blame] | 101 | fd_updt[fd_nbupdt++] = fd; |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | |
Willy Tarreau | 899d957 | 2014-01-25 19:20:35 +0100 | [diff] [blame] | 105 | /* Allocates a cache entry for a file descriptor if it does not yet have one. |
| 106 | * This can be done at any time. |
| 107 | */ |
| 108 | static inline void fd_alloc_cache_entry(const int fd) |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 109 | { |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 110 | if (fdtab[fd].cache) |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 111 | return; |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 112 | fd_cache_num++; |
| 113 | fdtab[fd].cache = fd_cache_num; |
| 114 | fd_cache[fd_cache_num-1] = fd; |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 115 | } |
| 116 | |
Willy Tarreau | 899d957 | 2014-01-25 19:20:35 +0100 | [diff] [blame] | 117 | /* Removes entry used by fd <fd> from the FD cache and replaces it with the |
| 118 | * last one. The fdtab.cache is adjusted to match the back reference if needed. |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 119 | * If the fd has no entry assigned, return immediately. |
| 120 | */ |
Willy Tarreau | 899d957 | 2014-01-25 19:20:35 +0100 | [diff] [blame] | 121 | static inline void fd_release_cache_entry(int fd) |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 122 | { |
| 123 | unsigned int pos; |
| 124 | |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 125 | pos = fdtab[fd].cache; |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 126 | if (!pos) |
| 127 | return; |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 128 | fdtab[fd].cache = 0; |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 129 | fd_cache_num--; |
| 130 | if (likely(pos <= fd_cache_num)) { |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 131 | /* was not the last entry */ |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 132 | fd = fd_cache[fd_cache_num]; |
| 133 | fd_cache[pos - 1] = fd; |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 134 | fdtab[fd].cache = pos; |
Willy Tarreau | 7be79a4 | 2012-11-11 15:02:54 +0100 | [diff] [blame] | 135 | } |
| 136 | } |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 137 | |
Willy Tarreau | 25002d2 | 2014-01-25 10:32:56 +0100 | [diff] [blame] | 138 | /* Computes the new polled status based on the active and ready statuses, for |
| 139 | * each direction. This is meant to be used by pollers while processing updates. |
| 140 | */ |
| 141 | static inline int fd_compute_new_polled_status(int state) |
| 142 | { |
| 143 | if (state & FD_EV_ACTIVE_R) { |
| 144 | if (!(state & FD_EV_READY_R)) |
| 145 | state |= FD_EV_POLLED_R; |
| 146 | } |
| 147 | else |
| 148 | state &= ~FD_EV_POLLED_R; |
| 149 | |
| 150 | if (state & FD_EV_ACTIVE_W) { |
| 151 | if (!(state & FD_EV_READY_W)) |
| 152 | state |= FD_EV_POLLED_W; |
| 153 | } |
| 154 | else |
| 155 | state &= ~FD_EV_POLLED_W; |
| 156 | |
| 157 | return state; |
| 158 | } |
| 159 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 160 | /* Automatically allocates or releases a cache entry for fd <fd> depending on |
| 161 | * its new state. This is meant to be used by pollers while processing updates. |
| 162 | */ |
| 163 | static inline void fd_alloc_or_release_cache_entry(int fd, int new_state) |
| 164 | { |
| 165 | /* READY and ACTIVE states (the two with both flags set) require a cache entry */ |
| 166 | |
| 167 | if (((new_state & (FD_EV_READY_R | FD_EV_ACTIVE_R)) == (FD_EV_READY_R | FD_EV_ACTIVE_R)) || |
| 168 | ((new_state & (FD_EV_READY_W | FD_EV_ACTIVE_W)) == (FD_EV_READY_W | FD_EV_ACTIVE_W))) { |
| 169 | fd_alloc_cache_entry(fd); |
| 170 | } |
| 171 | else { |
| 172 | fd_release_cache_entry(fd); |
| 173 | } |
| 174 | } |
| 175 | |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 176 | /* |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 177 | * returns the FD's recv state (FD_EV_*) |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 178 | */ |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 179 | static inline int fd_recv_state(const int fd) |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 180 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 181 | return ((unsigned)fdtab[fd].state >> (4 * DIR_RD)) & FD_EV_STATUS; |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 184 | /* |
| 185 | * returns true if the FD is active for recv |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 186 | */ |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 187 | static inline int fd_recv_active(const int fd) |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 188 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 189 | return (unsigned)fdtab[fd].state & FD_EV_ACTIVE_R; |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 192 | /* |
| 193 | * returns true if the FD is ready for recv |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 194 | */ |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 195 | static inline int fd_recv_ready(const int fd) |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 196 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 197 | return (unsigned)fdtab[fd].state & FD_EV_READY_R; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * returns true if the FD is polled for recv |
| 202 | */ |
| 203 | static inline int fd_recv_polled(const int fd) |
| 204 | { |
| 205 | return (unsigned)fdtab[fd].state & FD_EV_POLLED_R; |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * returns the FD's send state (FD_EV_*) |
| 210 | */ |
| 211 | static inline int fd_send_state(const int fd) |
| 212 | { |
| 213 | return ((unsigned)fdtab[fd].state >> (4 * DIR_WR)) & FD_EV_STATUS; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * returns true if the FD is active for send |
| 218 | */ |
| 219 | static inline int fd_send_active(const int fd) |
| 220 | { |
| 221 | return (unsigned)fdtab[fd].state & FD_EV_ACTIVE_W; |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 224 | /* |
| 225 | * returns true if the FD is ready for send |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 226 | */ |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 227 | static inline int fd_send_ready(const int fd) |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 228 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 229 | return (unsigned)fdtab[fd].state & FD_EV_READY_W; |
| 230 | } |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 231 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 232 | /* |
| 233 | * returns true if the FD is polled for send |
| 234 | */ |
| 235 | static inline int fd_send_polled(const int fd) |
| 236 | { |
| 237 | return (unsigned)fdtab[fd].state & FD_EV_POLLED_W; |
| 238 | } |
| 239 | |
| 240 | /* Disable processing recv events on fd <fd> */ |
| 241 | static inline void fd_stop_recv(int fd) |
| 242 | { |
| 243 | if (!((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_R)) |
| 244 | return; /* already disabled */ |
| 245 | fdtab[fd].state &= ~FD_EV_ACTIVE_R; |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 246 | updt_fd(fd); /* need an update entry to change the state */ |
| 247 | } |
| 248 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 249 | /* Disable processing send events on fd <fd> */ |
| 250 | static inline void fd_stop_send(int fd) |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 251 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 252 | if (!((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_W)) |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 253 | return; /* already disabled */ |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 254 | fdtab[fd].state &= ~FD_EV_ACTIVE_W; |
Willy Tarreau | 6ea20b1 | 2012-11-11 16:05:19 +0100 | [diff] [blame] | 255 | updt_fd(fd); /* need an update entry to change the state */ |
| 256 | } |
| 257 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 258 | /* Disable processing of events on fd <fd> for both directions. */ |
| 259 | static inline void fd_stop_both(int fd) |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 260 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 261 | if (!((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_RW)) |
| 262 | return; /* already disabled */ |
| 263 | fdtab[fd].state &= ~FD_EV_ACTIVE_RW; |
| 264 | updt_fd(fd); /* need an update entry to change the state */ |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 265 | } |
| 266 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 267 | /* Report that FD <fd> cannot receive anymore without polling (EAGAIN detected). */ |
| 268 | static inline void fd_cant_recv(const int fd) |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 269 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 270 | if (!(((unsigned int)fdtab[fd].state) & FD_EV_READY_R)) |
| 271 | return; /* already marked as blocked */ |
| 272 | fdtab[fd].state &= ~FD_EV_READY_R; |
| 273 | updt_fd(fd); |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 276 | /* Report that FD <fd> can receive anymore without polling. */ |
| 277 | static inline void fd_may_recv(const int fd) |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 278 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 279 | if (((unsigned int)fdtab[fd].state) & FD_EV_READY_R) |
| 280 | return; /* already marked as blocked */ |
| 281 | fdtab[fd].state |= FD_EV_READY_R; |
| 282 | updt_fd(fd); |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 283 | } |
| 284 | |
Willy Tarreau | 6c11bd2 | 2014-01-24 00:54:27 +0100 | [diff] [blame] | 285 | /* Disable readiness when polled. This is useful to interrupt reading when it |
| 286 | * is suspected that the end of data might have been reached (eg: short read). |
| 287 | * This can only be done using level-triggered pollers, so if any edge-triggered |
| 288 | * is ever implemented, a test will have to be added here. |
| 289 | */ |
| 290 | static inline void fd_done_recv(const int fd) |
| 291 | { |
| 292 | if (fd_recv_polled(fd)) |
| 293 | fd_cant_recv(fd); |
| 294 | } |
| 295 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 296 | /* Report that FD <fd> cannot send anymore without polling (EAGAIN detected). */ |
| 297 | static inline void fd_cant_send(const int fd) |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 298 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 299 | if (!(((unsigned int)fdtab[fd].state) & FD_EV_READY_W)) |
| 300 | return; /* already marked as blocked */ |
| 301 | fdtab[fd].state &= ~FD_EV_READY_W; |
| 302 | updt_fd(fd); |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 305 | /* Report that FD <fd> can send anymore without polling (EAGAIN detected). */ |
| 306 | static inline void fd_may_send(const int fd) |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 307 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 308 | if (((unsigned int)fdtab[fd].state) & FD_EV_READY_W) |
| 309 | return; /* already marked as blocked */ |
| 310 | fdtab[fd].state |= FD_EV_READY_W; |
| 311 | updt_fd(fd); |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 312 | } |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 313 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 314 | /* Prepare FD <fd> to try to receive */ |
| 315 | static inline void fd_want_recv(int fd) |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 316 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 317 | if (((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_R)) |
| 318 | return; /* already enabled */ |
| 319 | fdtab[fd].state |= FD_EV_ACTIVE_R; |
| 320 | updt_fd(fd); /* need an update entry to change the state */ |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 323 | /* Prepare FD <fd> to try to send */ |
| 324 | static inline void fd_want_send(int fd) |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 325 | { |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 326 | if (((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_W)) |
| 327 | return; /* already enabled */ |
| 328 | fdtab[fd].state |= FD_EV_ACTIVE_W; |
| 329 | updt_fd(fd); /* need an update entry to change the state */ |
Willy Tarreau | 49b046d | 2012-08-09 12:11:58 +0200 | [diff] [blame] | 330 | } |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 331 | |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 332 | /* Prepares <fd> for being polled */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 333 | static inline void fd_insert(int fd) |
| 334 | { |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 335 | fdtab[fd].ev = 0; |
Willy Tarreau | 037d2c1 | 2012-11-06 02:34:46 +0100 | [diff] [blame] | 336 | fdtab[fd].new = 1; |
Willy Tarreau | ad38ace | 2013-12-15 14:19:38 +0100 | [diff] [blame] | 337 | fdtab[fd].linger_risk = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 338 | if (fd + 1 > maxfd) |
| 339 | maxfd = fd + 1; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | #endif /* _PROTO_FD_H */ |
| 344 | |
| 345 | /* |
| 346 | * Local variables: |
| 347 | * c-indent-level: 8 |
| 348 | * c-basic-offset: 8 |
| 349 | * End: |
| 350 | */ |