~ubuntu-branches/ubuntu/utopic/haproxy/utopic-proposed

« back to all changes in this revision

Viewing changes to src/ev_kqueue.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
* 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 FreeBSD kqueue()
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
23
23
 
24
24
#include <common/compat.h>
25
25
#include <common/config.h>
 
26
#include <common/ticks.h>
26
27
#include <common/time.h>
27
28
#include <common/tools.h>
28
29
 
29
 
#include <types/fd.h>
30
30
#include <types/global.h>
31
31
 
32
32
#include <proto/fd.h>
 
33
#include <proto/signal.h>
33
34
#include <proto/task.h>
34
35
 
35
36
/* private data */
99
100
/*
100
101
 * kqueue() poller
101
102
 */
102
 
REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
 
103
REGPRM2 static void _do_poll(struct poller *p, int exp)
103
104
{
104
105
        int status;
105
 
        int count, fd;
106
 
        struct timespec timeout, *to_ptr;
107
 
 
108
 
        to_ptr = NULL;  // no timeout
109
 
        if (run_queue) {
110
 
                timeout.tv_sec = timeout.tv_nsec = 0;
111
 
                to_ptr = &timeout;
112
 
        }
113
 
        else if (tv_isset(exp)) {
114
 
                struct timeval delta;
115
 
 
116
 
                if (tv_isge(&now, exp))
117
 
                        delta.tv_sec = delta.tv_usec = 0;
118
 
                else
119
 
                        tv_remain(&now, exp, &delta);
120
 
 
121
 
                timeout.tv_sec  = delta.tv_sec;
122
 
                timeout.tv_nsec = delta.tv_usec * 1000;
123
 
                to_ptr = &timeout;
 
106
        int count, fd, delta_ms;
 
107
        struct timespec timeout;
 
108
 
 
109
        delta_ms        = 0;
 
110
        timeout.tv_sec  = 0;
 
111
        timeout.tv_nsec = 0;
 
112
 
 
113
        if (!run_queue && !signal_queue_len) {
 
114
                if (!exp) {
 
115
                        delta_ms        = MAX_DELAY_MS;
 
116
                        timeout.tv_sec  = (MAX_DELAY_MS / 1000);
 
117
                        timeout.tv_nsec = (MAX_DELAY_MS % 1000) * 1000000;
 
118
                }
 
119
                else if (!tick_is_expired(exp, now_ms)) {
 
120
                        delta_ms = TICKS_TO_MS(tick_remain(now_ms, exp)) + 1;
 
121
                        if (delta_ms > MAX_DELAY_MS)
 
122
                                delta_ms = MAX_DELAY_MS;
 
123
                        timeout.tv_sec  = (delta_ms / 1000);
 
124
                        timeout.tv_nsec = (delta_ms % 1000) * 1000000;
 
125
                }
124
126
        }
125
127
 
126
128
        fd = MIN(maxfd, global.tune.maxpollevents);
129
131
                        0,         // int nchanges
130
132
                        kev,       // struct kevent *eventlist
131
133
                        fd,        // int nevents
132
 
                        to_ptr);   // const struct timespec *timeout
133
 
        tv_now(&now);
 
134
                        &timeout); // const struct timespec *timeout
 
135
        tv_update_date(delta_ms, status);
134
136
 
135
137
        for (count = 0; count < status; count++) {
136
138
                fd = kev[count].ident;
186
188
        free(kev);
187
189
 fail_kev:
188
190
        close(kqueue_fd);
189
 
        kqueue_fd = 0;
 
191
        kqueue_fd = -1;
190
192
 fail_fd:
191
193
        p->pref = 0;
192
194
        return 0;
198
200
 */
199
201
REGPRM1 static void _do_term(struct poller *p)
200
202
{
201
 
        if (fd_evts[DIR_WR])
202
 
                free(fd_evts[DIR_WR]);
203
 
        if (fd_evts[DIR_RD])
204
 
                free(fd_evts[DIR_RD]);
205
 
        if (kev)
206
 
                free(kev);
207
 
        close(kqueue_fd);
208
 
        kqueue_fd = 0;
 
203
        free(fd_evts[DIR_WR]);
 
204
        free(fd_evts[DIR_RD]);
 
205
        free(kev);
 
206
 
 
207
        if (kqueue_fd >= 0) {
 
208
                close(kqueue_fd);
 
209
                kqueue_fd = -1;
 
210
        }
209
211
 
210
212
        p->private = NULL;
211
213
        p->pref = 0;
233
235
 */
234
236
REGPRM1 static int _do_fork(struct poller *p)
235
237
{
236
 
        close(kqueue_fd);
 
238
        if (kqueue_fd >= 0)
 
239
                close(kqueue_fd);
237
240
        kqueue_fd = kqueue();
238
241
        if (kqueue_fd < 0)
239
242
                return 0;
252
255
 
253
256
        if (nbpollers >= MAX_POLLERS)
254
257
                return;
 
258
 
 
259
        kqueue_fd = -1;
255
260
        p = &pollers[nbpollers++];
256
261
 
257
262
        p->name = "kqueue";