blob: c238bc880f5f19dfe11815ae29f186f02c97709a [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * File descriptors management functions.
3 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +01004 * Copyright 2000-2014 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010011 * This code implements an events cache for file descriptors. It remembers the
12 * readiness of a file descriptor after a return from poll() and the fact that
13 * an I/O attempt failed on EAGAIN. Events in the cache which are still marked
14 * ready and active are processed just as if they were reported by poll().
Willy Tarreau7be79a42012-11-11 15:02:54 +010015 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010016 * This serves multiple purposes. First, it significantly improves performance
17 * by avoiding to subscribe to polling unless absolutely necessary, so most
18 * events are processed without polling at all, especially send() which
19 * benefits from the socket buffers. Second, it is the only way to support
20 * edge-triggered pollers (eg: EPOLL_ET). And third, it enables I/O operations
21 * that are backed by invisible buffers. For example, SSL is able to read a
22 * whole socket buffer and not deliver it to the application buffer because
23 * it's full. Unfortunately, it won't be reported by a poller anymore until
24 * some new activity happens. The only way to call it again thus is to keep
25 * this readiness information in the cache and to access it without polling
26 * once the FD is enabled again.
Willy Tarreau7be79a42012-11-11 15:02:54 +010027 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010028 * One interesting feature of the cache is that it maintains the principle
29 * of speculative I/O introduced in haproxy 1.3 : the first time an event is
30 * enabled, the FD is considered as ready so that the I/O attempt is performed
31 * via the cache without polling. And the polling happens only when EAGAIN is
32 * first met. This avoids polling for HTTP requests, especially when the
33 * defer-accept mode is used. It also avoids polling for sending short data
34 * such as requests to servers or short responses to clients.
35 *
36 * The cache consists in a list of active events and a list of updates.
37 * Active events are events that are expected to come and that we must report
38 * to the application until it asks to stop or asks to poll. Updates are new
39 * requests for changing an FD state. Updates are the only way to create new
40 * events. This is important because it means that the number of cached events
41 * cannot increase between updates and will only grow one at a time while
42 * processing updates. All updates must always be processed, though events
43 * might be processed by small batches if required.
Willy Tarreau7be79a42012-11-11 15:02:54 +010044 *
45 * There is no direct link between the FD and the updates list. There is only a
46 * bit in the fdtab[] to indicate than a file descriptor is already present in
47 * the updates list. Once an fd is present in the updates list, it will have to
48 * be considered even if its changes are reverted in the middle or if the fd is
49 * replaced.
50 *
51 * It is important to understand that as long as all expected events are
52 * processed, they might starve the polled events, especially because polled
Willy Tarreauf817e9f2014-01-10 16:58:45 +010053 * I/O starvation quickly induces more cached I/O. One solution to this
Willy Tarreau7be79a42012-11-11 15:02:54 +010054 * consists in only processing a part of the events at once, but one drawback
Willy Tarreauf817e9f2014-01-10 16:58:45 +010055 * is that unhandled events will still wake the poller up. Using an edge-
56 * triggered poller such as EPOLL_ET will solve this issue though.
Willy Tarreau7be79a42012-11-11 15:02:54 +010057 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010058 * Since we do not want to scan all the FD list to find cached I/O events,
59 * we store them in a list consisting in a linear array holding only the FD
60 * indexes right now. Note that a closed FD cannot exist in the cache, because
61 * it is closed by fd_delete() which in turn calls fd_release_cache_entry()
62 * which always removes it from the list.
Willy Tarreau7be79a42012-11-11 15:02:54 +010063 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010064 * The FD array has to hold a back reference to the cache. This reference is
65 * always valid unless the FD is not in the cache and is not updated, in which
66 * case the reference points to index 0.
Willy Tarreau7be79a42012-11-11 15:02:54 +010067 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010068 * The event state for an FD, as found in fdtab[].state, is maintained for each
69 * direction. The state field is built this way, with R bits in the low nibble
70 * and W bits in the high nibble for ease of access and debugging :
Willy Tarreau7be79a42012-11-11 15:02:54 +010071 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010072 * 7 6 5 4 3 2 1 0
73 * [ 0 | PW | RW | AW | 0 | PR | RR | AR ]
74 *
75 * A* = active *R = read
76 * P* = polled *W = write
77 * R* = ready
78 *
79 * An FD is marked "active" when there is a desire to use it.
80 * An FD is marked "polled" when it is registered in the polling.
81 * An FD is marked "ready" when it has not faced a new EAGAIN since last wake-up
82 * (it is a cache of the last EAGAIN regardless of polling changes).
Willy Tarreau7be79a42012-11-11 15:02:54 +010083 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010084 * We have 8 possible states for each direction based on these 3 flags :
Willy Tarreau7be79a42012-11-11 15:02:54 +010085 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010086 * +---+---+---+----------+---------------------------------------------+
87 * | P | R | A | State | Description |
88 * +---+---+---+----------+---------------------------------------------+
89 * | 0 | 0 | 0 | DISABLED | No activity desired, not ready. |
90 * | 0 | 0 | 1 | MUSTPOLL | Activity desired via polling. |
91 * | 0 | 1 | 0 | STOPPED | End of activity without polling. |
92 * | 0 | 1 | 1 | ACTIVE | Activity desired without polling. |
93 * | 1 | 0 | 0 | ABORT | Aborted poll(). Not frequently seen. |
94 * | 1 | 0 | 1 | POLLED | FD is being polled. |
95 * | 1 | 1 | 0 | PAUSED | FD was paused while ready (eg: buffer full) |
96 * | 1 | 1 | 1 | READY | FD was marked ready by poll() |
97 * +---+---+---+----------+---------------------------------------------+
Willy Tarreau7be79a42012-11-11 15:02:54 +010098 *
Willy Tarreauf817e9f2014-01-10 16:58:45 +010099 * The transitions are pretty simple :
100 * - fd_want_*() : set flag A
101 * - fd_stop_*() : clear flag A
102 * - fd_cant_*() : clear flag R (when facing EAGAIN)
103 * - fd_may_*() : set flag R (upon return from poll())
104 * - sync() : if (A) { if (!R) P := 1 } else { P := 0 }
105 *
106 * The PAUSED, ABORT and MUSTPOLL states are transient for level-trigerred
107 * pollers and are fixed by the sync() which happens at the beginning of the
108 * poller. For event-triggered pollers, only the MUSTPOLL state will be
109 * transient and ABORT will lead to PAUSED. The ACTIVE state is the only stable
110 * one which has P != A.
111 *
112 * The READY state is a bit special as activity on the FD might be notified
113 * both by the poller or by the cache. But it is needed for some multi-layer
114 * protocols (eg: SSL) where connection activity is not 100% linked to FD
115 * activity. Also some pollers might prefer to implement it as ACTIVE if
116 * enabling/disabling the FD is cheap. The READY and ACTIVE states are the
117 * two states for which a cache entry is allocated.
118 *
119 * The state transitions look like the diagram below. Only the 4 right states
120 * have polling enabled :
121 *
122 * (POLLED=0) (POLLED=1)
123 *
124 * +----------+ sync +-------+
125 * | DISABLED | <----- | ABORT | (READY=0, ACTIVE=0)
126 * +----------+ +-------+
127 * clr | ^ set | ^
128 * | | | |
129 * v | set v | clr
130 * +----------+ sync +--------+
131 * | MUSTPOLL | -----> | POLLED | (READY=0, ACTIVE=1)
132 * +----------+ +--------+
133 * ^ poll | ^
134 * | | |
135 * | EAGAIN v | EAGAIN
136 * +--------+ +-------+
137 * | ACTIVE | | READY | (READY=1, ACTIVE=1)
138 * +--------+ +-------+
139 * clr | ^ set | ^
140 * | | | |
141 * v | set v | clr
142 * +---------+ sync +--------+
143 * | STOPPED | <------ | PAUSED | (READY=1, ACTIVE=0)
144 * +---------+ +--------+
Willy Tarreaubaaee002006-06-26 02:48:02 +0200145 */
146
Willy Tarreau2ff76222007-04-09 19:29:56 +0200147#include <stdio.h>
Willy Tarreau4f60f162007-04-08 16:39:58 +0200148#include <string.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +0200149#include <unistd.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +0200150#include <sys/types.h>
151
Willy Tarreau2dd0d472006-06-29 17:53:05 +0200152#include <common/compat.h>
153#include <common/config.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +0200154
Willy Tarreau7be79a42012-11-11 15:02:54 +0100155#include <types/global.h>
156
Willy Tarreau2a429502006-10-15 14:52:29 +0200157#include <proto/fd.h>
Willy Tarreauc6f4ce82009-06-10 11:09:37 +0200158#include <proto/port_range.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +0200159
160struct fdtab *fdtab = NULL; /* array of all the file descriptors */
Willy Tarreau8d5d77e2009-10-18 07:25:52 +0200161struct fdinfo *fdinfo = NULL; /* less-often used infos for file descriptors */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200162int maxfd; /* # of the highest fd + 1 */
163int totalconn; /* total # of terminated sessions */
164int actconn; /* # of active sessions */
165
Willy Tarreau4f60f162007-04-08 16:39:58 +0200166struct poller pollers[MAX_POLLERS];
167struct poller cur_poller;
168int nbpollers = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200169
Willy Tarreau16f649c2014-01-25 19:10:48 +0100170unsigned int *fd_cache = NULL; // FD events cache
Willy Tarreau7be79a42012-11-11 15:02:54 +0100171unsigned int *fd_updt = NULL; // FD updates list
Willy Tarreau16f649c2014-01-25 19:10:48 +0100172int fd_cache_num = 0; // number of events in the cache
173int fd_nbupdt = 0; // number of updates in the list
Willy Tarreaubaaee002006-06-26 02:48:02 +0200174
Willy Tarreau4f60f162007-04-08 16:39:58 +0200175/* Deletes an FD from the fdsets, and recomputes the maxfd limit.
176 * The file descriptor is also closed.
177 */
178void fd_delete(int fd)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200179{
Willy Tarreauad38ace2013-12-15 14:19:38 +0100180 if (fdtab[fd].linger_risk) {
181 /* this is generally set when connecting to servers */
182 setsockopt(fd, SOL_SOCKET, SO_LINGER,
183 (struct linger *) &nolinger, sizeof(struct linger));
184 }
Willy Tarreau6ea20b12012-11-11 16:05:19 +0100185 if (cur_poller.clo)
186 cur_poller.clo(fd);
187
Willy Tarreau899d9572014-01-25 19:20:35 +0100188 fd_release_cache_entry(fd);
Willy Tarreauf817e9f2014-01-10 16:58:45 +0100189 fdtab[fd].state = 0;
Willy Tarreau6ea20b12012-11-11 16:05:19 +0100190
Willy Tarreau8d5d77e2009-10-18 07:25:52 +0200191 port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port);
192 fdinfo[fd].port_range = NULL;
Willy Tarreau4f60f162007-04-08 16:39:58 +0200193 close(fd);
Willy Tarreaudb3b3262012-07-05 23:19:22 +0200194 fdtab[fd].owner = NULL;
Willy Tarreau1720abd2012-11-11 17:08:32 +0100195 fdtab[fd].new = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200196
Willy Tarreaudb3b3262012-07-05 23:19:22 +0200197 while ((maxfd-1 >= 0) && !fdtab[maxfd-1].owner)
Willy Tarreau4f60f162007-04-08 16:39:58 +0200198 maxfd--;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200199}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200200
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100201/* Scan and process the cached events. This should be called right after
Willy Tarreau09f24562012-11-11 16:43:45 +0100202 * the poller.
203 */
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100204void fd_process_cached_events()
Willy Tarreau09f24562012-11-11 16:43:45 +0100205{
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100206 int fd, entry, e;
Willy Tarreau09f24562012-11-11 16:43:45 +0100207
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100208 for (entry = 0; entry < fd_cache_num; ) {
209 fd = fd_cache[entry];
Willy Tarreau69a41fa2014-01-20 11:02:59 +0100210 e = fdtab[fd].state;
Willy Tarreau09f24562012-11-11 16:43:45 +0100211
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100212 /* Principle: events which are marked FD_EV_ACTIVE are processed
Willy Tarreau09f24562012-11-11 16:43:45 +0100213 * with their usual I/O callback. The callback may remove the
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100214 * events from the cache or tag them for polling. Changes will be
215 * applied on next round. Cache entries with no more activity are
216 * automatically scheduled for removal.
Willy Tarreau09f24562012-11-11 16:43:45 +0100217 */
Willy Tarreau09f24562012-11-11 16:43:45 +0100218 fdtab[fd].ev &= FD_POLL_STICKY;
219
Willy Tarreauf817e9f2014-01-10 16:58:45 +0100220 if ((e & (FD_EV_READY_R | FD_EV_ACTIVE_R)) == (FD_EV_READY_R | FD_EV_ACTIVE_R))
Willy Tarreau09f24562012-11-11 16:43:45 +0100221 fdtab[fd].ev |= FD_POLL_IN;
222
Willy Tarreauf817e9f2014-01-10 16:58:45 +0100223 if ((e & (FD_EV_READY_W | FD_EV_ACTIVE_W)) == (FD_EV_READY_W | FD_EV_ACTIVE_W))
Willy Tarreau09f24562012-11-11 16:43:45 +0100224 fdtab[fd].ev |= FD_POLL_OUT;
225
226 if (fdtab[fd].iocb && fdtab[fd].owner && fdtab[fd].ev)
227 fdtab[fd].iocb(fd);
Willy Tarreaufa7fc952014-01-20 20:18:59 +0100228 else
229 updt_fd(fd);
Willy Tarreau09f24562012-11-11 16:43:45 +0100230
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100231 /* If the fd was removed from the cache, it has been
Willy Tarreau09f24562012-11-11 16:43:45 +0100232 * replaced by the next one that we don't want to skip !
233 */
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100234 if (entry < fd_cache_num && fd_cache[entry] != fd)
Willy Tarreau09f24562012-11-11 16:43:45 +0100235 continue;
Willy Tarreau033cd9d2014-01-25 19:24:15 +0100236 entry++;
Willy Tarreau09f24562012-11-11 16:43:45 +0100237 }
238}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200239
Willy Tarreaue8525452014-01-25 09:58:06 +0100240/* Check the events attached to a file descriptor, update its cache
241 * accordingly, and call the associated I/O callback. If new updates are
242 * detected, the function tries to process them as well in order to save
243 * wakeups after accept().
244 */
245void fd_process_polled_events(int fd)
246{
247 int new_updt, old_updt;
248
249 /* First thing to do is to mark the reported events as ready, in order
250 * for them to later be continued from the cache without polling if
251 * they have to be interrupted (eg: recv fills a buffer).
252 */
253 if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
254 fd_may_recv(fd);
255
256 if (fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR))
257 fd_may_send(fd);
258
259 if (fdtab[fd].cache) {
260 /* This fd is already cached, no need to process it now. */
261 return;
262 }
263
264 if (unlikely(!fdtab[fd].iocb || !fdtab[fd].ev)) {
265 /* nothing to do */
266 return;
267 }
268
269 /* Save number of updates to detect creation of new FDs. */
270 old_updt = fd_nbupdt;
271 fdtab[fd].iocb(fd);
272
273 /* One or more fd might have been created during the iocb().
274 * This mainly happens with new incoming connections that have
275 * just been accepted, so we'd like to process them immediately
276 * for better efficiency, as it saves one useless task wakeup.
277 * Second benefit, if at the end the fds are disabled again, we can
278 * safely destroy their update entry to reduce the scope of later
279 * scans. This is the reason we scan the new entries backwards.
280 */
281 for (new_updt = fd_nbupdt; new_updt > old_updt; new_updt--) {
282 fd = fd_updt[new_updt - 1];
283 if (!fdtab[fd].new)
284 continue;
285
286 fdtab[fd].new = 0;
287 fdtab[fd].ev &= FD_POLL_STICKY;
288
289 if ((fdtab[fd].state & FD_EV_STATUS_R) == (FD_EV_READY_R | FD_EV_ACTIVE_R))
290 fdtab[fd].ev |= FD_POLL_IN;
291
292 if ((fdtab[fd].state & FD_EV_STATUS_W) == (FD_EV_READY_W | FD_EV_ACTIVE_W))
293 fdtab[fd].ev |= FD_POLL_OUT;
294
295 if (fdtab[fd].ev && fdtab[fd].iocb && fdtab[fd].owner)
296 fdtab[fd].iocb(fd);
297
298 /* we can remove this update entry if it's the last one and is
299 * unused, otherwise we don't touch anything, especially given
300 * that the FD might have been closed already.
301 */
302 if (new_updt == fd_nbupdt && !fd_recv_active(fd) && !fd_send_active(fd)) {
303 fdtab[fd].updated = 0;
304 fd_nbupdt--;
305 }
306 }
307}
308
Willy Tarreau4f60f162007-04-08 16:39:58 +0200309/* disable the specified poller */
310void disable_poller(const char *poller_name)
311{
312 int p;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200313
Willy Tarreau4f60f162007-04-08 16:39:58 +0200314 for (p = 0; p < nbpollers; p++)
315 if (strcmp(pollers[p].name, poller_name) == 0)
316 pollers[p].pref = 0;
317}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200318
319/*
Willy Tarreau4f60f162007-04-08 16:39:58 +0200320 * Initialize the pollers till the best one is found.
321 * If none works, returns 0, otherwise 1.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200322 */
Willy Tarreau4f60f162007-04-08 16:39:58 +0200323int init_pollers()
Willy Tarreaubaaee002006-06-26 02:48:02 +0200324{
Willy Tarreau4f60f162007-04-08 16:39:58 +0200325 int p;
326 struct poller *bp;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200327
Willy Tarreau16f649c2014-01-25 19:10:48 +0100328 if ((fd_cache = (uint32_t *)calloc(1, sizeof(uint32_t) * global.maxsock)) == NULL)
329 goto fail_cache;
Willy Tarreau7be79a42012-11-11 15:02:54 +0100330
331 if ((fd_updt = (uint32_t *)calloc(1, sizeof(uint32_t) * global.maxsock)) == NULL)
332 goto fail_updt;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200333
Willy Tarreau4f60f162007-04-08 16:39:58 +0200334 do {
335 bp = NULL;
336 for (p = 0; p < nbpollers; p++)
337 if (!bp || (pollers[p].pref > bp->pref))
338 bp = &pollers[p];
Willy Tarreaubaaee002006-06-26 02:48:02 +0200339
Willy Tarreau4f60f162007-04-08 16:39:58 +0200340 if (!bp || bp->pref == 0)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200341 break;
342
Willy Tarreau4f60f162007-04-08 16:39:58 +0200343 if (bp->init(bp)) {
344 memcpy(&cur_poller, bp, sizeof(*bp));
345 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200346 }
Willy Tarreau4f60f162007-04-08 16:39:58 +0200347 } while (!bp || bp->pref == 0);
348 return 0;
Willy Tarreau7be79a42012-11-11 15:02:54 +0100349
350 fail_updt:
Willy Tarreau16f649c2014-01-25 19:10:48 +0100351 free(fd_cache);
352 fail_cache:
Willy Tarreau7be79a42012-11-11 15:02:54 +0100353 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200354}
355
Willy Tarreaubaaee002006-06-26 02:48:02 +0200356/*
Krzysztof Piotr Oledzkia643baf2008-05-29 23:53:44 +0200357 * Deinitialize the pollers.
358 */
359void deinit_pollers() {
360
361 struct poller *bp;
362 int p;
363
364 for (p = 0; p < nbpollers; p++) {
365 bp = &pollers[p];
366
367 if (bp && bp->pref)
368 bp->term(bp);
369 }
Willy Tarreau7be79a42012-11-11 15:02:54 +0100370
371 free(fd_updt);
Willy Tarreau16f649c2014-01-25 19:10:48 +0100372 free(fd_cache);
Willy Tarreau7be79a42012-11-11 15:02:54 +0100373 fd_updt = NULL;
Willy Tarreau16f649c2014-01-25 19:10:48 +0100374 fd_cache = NULL;
Krzysztof Piotr Oledzkia643baf2008-05-29 23:53:44 +0200375}
376
377/*
Willy Tarreau2ff76222007-04-09 19:29:56 +0200378 * Lists the known pollers on <out>.
379 * Should be performed only before initialization.
380 */
381int list_pollers(FILE *out)
382{
383 int p;
384 int last, next;
385 int usable;
386 struct poller *bp;
387
388 fprintf(out, "Available polling systems :\n");
389
390 usable = 0;
391 bp = NULL;
392 last = next = -1;
393 while (1) {
394 for (p = 0; p < nbpollers; p++) {
Willy Tarreau2ff76222007-04-09 19:29:56 +0200395 if ((next < 0 || pollers[p].pref > next)
Willy Tarreaue79c3b22010-11-19 10:20:36 +0100396 && (last < 0 || pollers[p].pref < last)) {
Willy Tarreau2ff76222007-04-09 19:29:56 +0200397 next = pollers[p].pref;
Willy Tarreaue79c3b22010-11-19 10:20:36 +0100398 if (!bp || (pollers[p].pref > bp->pref))
399 bp = &pollers[p];
400 }
Willy Tarreau2ff76222007-04-09 19:29:56 +0200401 }
402
403 if (next == -1)
404 break;
405
406 for (p = 0; p < nbpollers; p++) {
407 if (pollers[p].pref == next) {
408 fprintf(out, " %10s : ", pollers[p].name);
409 if (pollers[p].pref == 0)
410 fprintf(out, "disabled, ");
411 else
412 fprintf(out, "pref=%3d, ", pollers[p].pref);
413 if (pollers[p].test(&pollers[p])) {
414 fprintf(out, " test result OK");
415 if (next > 0)
416 usable++;
Willy Tarreaue79c3b22010-11-19 10:20:36 +0100417 } else {
Willy Tarreau2ff76222007-04-09 19:29:56 +0200418 fprintf(out, " test result FAILED");
Willy Tarreaue79c3b22010-11-19 10:20:36 +0100419 if (bp == &pollers[p])
420 bp = NULL;
421 }
Willy Tarreau2ff76222007-04-09 19:29:56 +0200422 fprintf(out, "\n");
423 }
424 }
425 last = next;
426 next = -1;
427 };
428 fprintf(out, "Total: %d (%d usable), will use %s.\n", nbpollers, usable, bp ? bp->name : "none");
429 return 0;
430}
431
432/*
433 * Some pollers may lose their connection after a fork(). It may be necessary
434 * to create initialize part of them again. Returns 0 in case of failure,
435 * otherwise 1. The fork() function may be NULL if unused. In case of error,
436 * the the current poller is destroyed and the caller is responsible for trying
437 * another one by calling init_pollers() again.
438 */
439int fork_poller()
440{
Conrad Hoffmann041751c2014-05-20 14:28:24 +0200441 int fd;
442 for (fd = 0; fd <= maxfd; fd++) {
443 if (fdtab[fd].owner) {
444 fdtab[fd].cloned = 1;
445 }
446 }
447
Willy Tarreau2ff76222007-04-09 19:29:56 +0200448 if (cur_poller.fork) {
449 if (cur_poller.fork(&cur_poller))
450 return 1;
451 cur_poller.term(&cur_poller);
452 return 0;
453 }
454 return 1;
455}
456
457/*
Willy Tarreaubaaee002006-06-26 02:48:02 +0200458 * Local variables:
459 * c-indent-level: 8
460 * c-basic-offset: 8
461 * End:
462 */