blob: 1cba33b7f1edc913de1dbe0f12db2ddba3edef5d [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/proto/fd.h
3 File descriptors states.
4
Willy Tarreau4f60f162007-04-08 16:39:58 +02005 Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +02006
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
Willy Tarreau2ff76222007-04-09 19:29:56 +020025#include <stdio.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020026#include <sys/time.h>
27#include <sys/types.h>
28#include <unistd.h>
29
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020030#include <common/config.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031#include <types/fd.h>
32
33/* Deletes an FD from the fdsets, and recomputes the maxfd limit.
34 * The file descriptor is also closed.
35 */
36void fd_delete(int fd);
37
Willy Tarreau4f60f162007-04-08 16:39:58 +020038/* disable the specified poller */
39void disable_poller(const char *poller_name);
Willy Tarreaubaaee002006-06-26 02:48:02 +020040
Willy Tarreau2a429502006-10-15 14:52:29 +020041/*
Willy Tarreau4f60f162007-04-08 16:39:58 +020042 * Initialize the pollers till the best one is found.
43 * If none works, returns 0, otherwise 1.
Willy Tarreauef1d1f82007-04-16 00:25:25 +020044 * The pollers register themselves just before main() is called.
Willy Tarreau2a429502006-10-15 14:52:29 +020045 */
Willy Tarreau4f60f162007-04-08 16:39:58 +020046int init_pollers();
Willy Tarreau2a429502006-10-15 14:52:29 +020047
Willy Tarreau4f60f162007-04-08 16:39:58 +020048/*
Krzysztof Piotr Oledzkia643baf2008-05-29 23:53:44 +020049 * Deinitialize the pollers.
50 */
51void deinit_pollers();
52
53/*
Willy Tarreau2ff76222007-04-09 19:29:56 +020054 * Some pollers may lose their connection after a fork(). It may be necessary
55 * to create initialize part of them again. Returns 0 in case of failure,
56 * otherwise 1. The fork() function may be NULL if unused. In case of error,
57 * the the current poller is destroyed and the caller is responsible for trying
58 * another one by calling init_pollers() again.
59 */
60int fork_poller();
61
62/*
63 * Lists the known pollers on <out>.
64 * Should be performed only before initialization.
65 */
66int list_pollers(FILE *out);
67
68/*
Willy Tarreau4f60f162007-04-08 16:39:58 +020069 * Runs the polling loop
70 */
71void run_poller();
Willy Tarreau2a429502006-10-15 14:52:29 +020072
Willy Tarreauf161a342007-04-08 16:59:42 +020073#define EV_FD_SET(fd, ev) (cur_poller.set((fd), (ev)))
74#define EV_FD_CLR(fd, ev) (cur_poller.clr((fd), (ev)))
Willy Tarreau63455a92007-04-09 15:34:49 +020075#define EV_FD_ISSET(fd, ev) (cur_poller.is_set((fd), (ev)))
Willy Tarreauf161a342007-04-08 16:59:42 +020076#define EV_FD_COND_S(fd, ev) (cur_poller.cond_s((fd), (ev)))
77#define EV_FD_COND_C(fd, ev) (cur_poller.cond_c((fd), (ev)))
Willy Tarreau4f60f162007-04-08 16:39:58 +020078#define EV_FD_REM(fd) (cur_poller.rem(fd))
79#define EV_FD_CLO(fd) (cur_poller.clo(fd))
Willy Tarreau2a429502006-10-15 14:52:29 +020080
81
Willy Tarreaud6f087e2008-01-18 17:20:13 +010082/* Prepares <fd> for being polled */
Willy Tarreaubaaee002006-06-26 02:48:02 +020083static inline void fd_insert(int fd)
84{
Willy Tarreaud6f087e2008-01-18 17:20:13 +010085 fdtab[fd].ev = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +020086 if (fd + 1 > maxfd)
87 maxfd = fd + 1;
88}
89
90
91#endif /* _PROTO_FD_H */
92
93/*
94 * Local variables:
95 * c-indent-level: 8
96 * c-basic-offset: 8
97 * End:
98 */