~ubuntu-branches/ubuntu/oneiric/haproxy/oneiric-updates

« back to all changes in this revision

Viewing changes to src/ev_epoll.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2009-06-26 00:11:01 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090626001101-qo261ke2mjh3d8cn
Tags: 1.3.18-1
* New Upstream Version (Closes: #534583).
* Add contrib directory in docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * FD polling functions for linux epoll()
3
3
 *
4
 
 * Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
 
4
 * Copyright 2000-2008 Willy Tarreau <w@1wt.eu>
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU General Public License
17
17
#include <common/compat.h>
18
18
#include <common/config.h>
19
19
#include <common/standard.h>
 
20
#include <common/ticks.h>
20
21
#include <common/time.h>
21
22
#include <common/tools.h>
22
23
 
23
24
#include <types/fd.h>
24
25
#include <types/global.h>
25
26
 
26
 
#include <proto/fd.h>
 
27
#include <proto/signal.h>
27
28
#include <proto/task.h>
28
29
 
29
30
#if defined(USE_MY_EPOLL)
221
222
/*
222
223
 * epoll() poller
223
224
 */
224
 
REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
 
225
REGPRM2 static void _do_poll(struct poller *p, int exp)
225
226
{
226
227
        int status;
227
228
        int fd;
232
233
                fd_flush_changes();
233
234
 
234
235
        /* now let's wait for events */
235
 
        if (run_queue)
236
 
                wait_time = 0;
237
 
        else if (tv_iseternity(exp))
238
 
                wait_time = -1;
239
 
        else if (tv_isge(&now, exp))
240
 
                wait_time = 0;
241
 
        else
242
 
                wait_time = __tv_ms_elapsed(&now, exp) + 1;
 
236
        if (run_queue || signal_queue_len)
 
237
                wait_time = 0;
 
238
        else if (!exp)
 
239
                wait_time = MAX_DELAY_MS;
 
240
        else if (tick_is_expired(exp, now_ms))
 
241
                wait_time = 0;
 
242
        else {
 
243
                wait_time = TICKS_TO_MS(tick_remain(now_ms, exp)) + 1;
 
244
                if (wait_time > MAX_DELAY_MS)
 
245
                        wait_time = MAX_DELAY_MS;
 
246
        }
243
247
 
244
248
        fd = MIN(maxfd, global.tune.maxpollevents);
245
249
        status = epoll_wait(epoll_fd, epoll_events, fd, wait_time);
246
 
        tv_now(&now);
 
250
        tv_update_date(wait_time, status);
247
251
 
248
252
        for (count = 0; count < status; count++) {
249
253
                fd = epoll_events[count].data.fd;
308
312
        free(epoll_events);
309
313
 fail_ee:
310
314
        close(epoll_fd);
311
 
        epoll_fd = 0;
 
315
        epoll_fd = -1;
312
316
 fail_fd:
313
317
        p->pref = 0;
314
318
        return 0;
322
326
{
323
327
        fd_flush_changes();
324
328
 
325
 
        if (chg_ptr)
326
 
                free(chg_ptr);
327
 
        if (chg_list)
328
 
                free(chg_list);
329
 
        if (fd_evts)
330
 
                free(fd_evts);
331
 
        if (epoll_events)
332
 
                free(epoll_events);
 
329
        free(chg_ptr);
 
330
        free(chg_list);
 
331
        free(fd_evts);
 
332
        free(epoll_events);
333
333
 
334
 
        close(epoll_fd);
335
 
        epoll_fd = 0;
 
334
        if (epoll_fd >= 0) {
 
335
                close(epoll_fd);
 
336
                epoll_fd = -1;
 
337
        }
336
338
 
337
339
        chg_ptr = NULL;
338
340
        chg_list = NULL;
366
368
 */
367
369
REGPRM1 static int _do_fork(struct poller *p)
368
370
{
369
 
        close(epoll_fd);
 
371
        if (epoll_fd >= 0)
 
372
                close(epoll_fd);
370
373
        epoll_fd = epoll_create(global.maxsock + 1);
371
374
        if (epoll_fd < 0)
372
375
                return 0;
385
388
 
386
389
        if (nbpollers >= MAX_POLLERS)
387
390
                return;
 
391
 
 
392
        epoll_fd = -1;
388
393
        p = &pollers[nbpollers++];
389
394
 
390
395
        p->name = "epoll";