Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/proto/fd.h |
| 3 | File descriptors states. |
| 4 | |
| 5 | Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu |
| 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 | |
| 37 | |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 38 | /* |
| 39 | * Benchmarks performed on a Pentium-M notebook show that using functions |
| 40 | * instead of the usual macros improve the FD_* performance by about 80%, |
| 41 | * and that marking them regparm(2) adds another 20%. |
| 42 | */ |
| 43 | #if defined(CONFIG_HAP_INLINE_FD_SET) |
| 44 | |
| 45 | # define MY_FD_SET FD_SET |
| 46 | # define MY_FD_CLR FD_CLR |
| 47 | # define MY_FD_ISSET FD_ISSET |
| 48 | |
| 49 | #else |
| 50 | |
| 51 | # define MY_FD_SET my_fd_set |
| 52 | # define MY_FD_CLR my_fd_clr |
| 53 | # define MY_FD_ISSET my_fd_isset |
| 54 | |
Willy Tarreau | fddaec0 | 2006-10-15 22:56:02 +0200 | [diff] [blame] | 55 | REGPRM2 void my_fd_set(const int fd, fd_set *ev); |
| 56 | REGPRM2 void my_fd_clr(const int fd, fd_set *ev); |
| 57 | REGPRM2 int my_fd_isset(const int fd, const fd_set *ev); |
Willy Tarreau | 2a42950 | 2006-10-15 14:52:29 +0200 | [diff] [blame] | 58 | |
| 59 | #endif |
| 60 | |
| 61 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | /* recomputes the maxfd limit from the fd */ |
| 63 | static inline void fd_insert(int fd) |
| 64 | { |
| 65 | if (fd + 1 > maxfd) |
| 66 | maxfd = fd + 1; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | #endif /* _PROTO_FD_H */ |
| 71 | |
| 72 | /* |
| 73 | * Local variables: |
| 74 | * c-indent-level: 8 |
| 75 | * c-basic-offset: 8 |
| 76 | * End: |
| 77 | */ |