~ubuntu-branches/ubuntu/intrepid/haproxy/intrepid

« back to all changes in this revision

Viewing changes to src/ev_sepoll.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2008-03-09 21:30:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080309213029-8oupnrc607mg5uqw
Tags: 1.3.14.3-1
* New Upstream Version
* Add status argument support to init-script to conform to LSB.
* Cleanup pidfile after stop in init script. Init script return code fixups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include <common/compat.h>
18
18
#include <common/config.h>
 
19
#include <common/debug.h>
19
20
#include <common/standard.h>
20
21
#include <common/time.h>
21
22
#include <common/tools.h>
115
116
 * FIXME: should be a bit field */
116
117
struct fd_status {
117
118
        unsigned int e:4;       // read and write events status.
118
 
        unsigned int s:28;      // Position in spec list. Should be last.
 
119
        unsigned int s1:28;     // Position in spec list+1. 0=not in list. Should be last.
119
120
};
120
121
 
121
122
static int nbspec = 0;          // current size of the spec list
135
136
 
136
137
REGPRM1 static void alloc_spec_entry(const int fd)
137
138
{
138
 
        if (fd_list[fd].e & FD_EV_RW_SL)
 
139
        if (fd_list[fd].s1)
139
140
                return;
140
 
        fd_list[fd].s = nbspec;
141
 
        spec_list[nbspec++] = fd;
 
141
        fd_list[fd].s1 = nbspec + 1;
 
142
        spec_list[nbspec] = fd;
 
143
        nbspec++;
142
144
}
143
145
 
144
 
/* removes entry <pos> from the spec list and replaces it with the last one.
145
 
 * The fd_list is adjusted to match the back reference if needed.
 
146
/* Removes entry used by fd <fd> from the spec list and replaces it with the
 
147
 * last one. The fd_list is adjusted to match the back reference if needed.
 
148
 * If the fd has no entry assigned, return immediately.
146
149
 */
147
 
REGPRM1 static void delete_spec_entry(const int pos)
 
150
REGPRM1 static void release_spec_entry(int fd)
148
151
{
149
 
        int fd;
 
152
        unsigned int pos;
 
153
 
 
154
        pos = fd_list[fd].s1;
 
155
        if (!pos)
 
156
                return;
 
157
 
 
158
        fd_list[fd].s1 = 0;
 
159
        pos--;
 
160
        /* we have spec_list[pos]==fd */
150
161
 
151
162
        nbspec--;
152
163
        if (pos == nbspec)
153
164
                return;
154
165
 
155
 
        /* we replace current FD by the highest one */
 
166
        /* we replace current FD by the highest one, which may sometimes be the same */
156
167
        fd = spec_list[nbspec];
 
168
        fd_list[fd].s1 = pos + 1;
157
169
        spec_list[pos] = fd;
158
 
        fd_list[fd].s = pos;
159
170
}
160
171
 
161
172
/*
234
245
REGPRM1 static void __fd_clo(int fd)
235
246
{
236
247
        if (fd_list[fd].e & FD_EV_RW_SL)
237
 
                delete_spec_entry(fd_list[fd].s);
 
248
                release_spec_entry(fd);
238
249
        fd_list[fd].e &= ~(FD_EV_MASK);
239
250
}
240
251
 
275
286
                 * the WAIT status.
276
287
                 */
277
288
 
278
 
                fdtab[fd].ev = 0;
 
289
                fdtab[fd].ev &= FD_POLL_STICKY;
279
290
                if ((eo & FD_EV_MASK_R) == FD_EV_SPEC_R) {
280
291
                        /* The owner is interested in reading from this FD */
281
292
                        if (fdtab[fd].state != FD_STCLOSE && fdtab[fd].state != FD_STERROR) {
346
357
                        /* This fd switched to combinations of either WAIT or
347
358
                         * IDLE. It must be removed from the spec list.
348
359
                         */
349
 
                        delete_spec_entry(spec_idx);
 
360
                        release_spec_entry(fd);
350
361
                        continue;
351
362
                }
352
363
        }
402
413
                /* it looks complicated but gcc can optimize it away when constants
403
414
                 * have same values.
404
415
                 */
405
 
                fdtab[fd].ev = 
 
416
                DPRINTF(stderr, "%s:%d: fd=%d, ev=0x%08x, e=0x%08x\n",
 
417
                        __FUNCTION__, __LINE__,
 
418
                        fd, fdtab[fd].ev, e);
 
419
 
 
420
                fdtab[fd].ev &= FD_POLL_STICKY;
 
421
                fdtab[fd].ev |= 
406
422
                        ((e & EPOLLIN ) ? FD_POLL_IN  : 0) |
407
423
                        ((e & EPOLLPRI) ? FD_POLL_PRI : 0) |
408
424
                        ((e & EPOLLOUT) ? FD_POLL_OUT : 0) |
412
428
                if ((fd_list[fd].e & FD_EV_MASK_R) == FD_EV_WAIT_R) {
413
429
                        if (fdtab[fd].state == FD_STCLOSE || fdtab[fd].state == FD_STERROR)
414
430
                                continue;
415
 
                        if (fdtab[fd].ev & (FD_POLL_RD|FD_POLL_HUP|FD_POLL_ERR))
 
431
                        if (fdtab[fd].ev & (FD_POLL_IN|FD_POLL_HUP|FD_POLL_ERR))
416
432
                                fdtab[fd].cb[DIR_RD].f(fd);
417
433
                }
418
434
 
419
435
                if ((fd_list[fd].e & FD_EV_MASK_W) == FD_EV_WAIT_W) {
420
436
                        if (fdtab[fd].state == FD_STCLOSE || fdtab[fd].state == FD_STERROR)
421
437
                                continue;
422
 
                        if (fdtab[fd].ev & (FD_POLL_WR|FD_POLL_ERR))
 
438
                        if (fdtab[fd].ev & (FD_POLL_OUT|FD_POLL_ERR))
423
439
                                fdtab[fd].cb[DIR_WR].f(fd);
424
440
                }
425
441
        }