]>
git.proxmox.com Git - mirror_frr.git/blob - ldpd/accept.c
4 * Copyright (c) 2012 Claudio Jeker <claudio@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
27 LIST_ENTRY(accept_ev
) entry
;
29 void (*accept_cb
)(int, short, void *);
35 LIST_HEAD(, accept_ev
) queue
;
39 static void accept_arm(void);
40 static void accept_unarm(void);
41 static void accept_cb(int, short, void *);
42 static void accept_timeout(int, short, void *);
47 LIST_INIT(&accept_queue
.queue
);
48 evtimer_set(&accept_queue
.evt
, accept_timeout
, NULL
);
52 accept_add(int fd
, void (*cb
)(int, short, void *), void *arg
)
56 if ((av
= calloc(1, sizeof(*av
))) == NULL
)
61 LIST_INSERT_HEAD(&accept_queue
.queue
, av
, entry
);
63 event_set(&av
->ev
, av
->fd
, EV_READ
, accept_cb
, av
);
64 event_add(&av
->ev
, NULL
);
66 log_debug("%s: accepting on fd %d", __func__
, fd
);
76 LIST_FOREACH(av
, &accept_queue
.queue
, entry
)
78 log_debug("%s: %d removed from queue", __func__
, fd
);
80 LIST_REMOVE(av
, entry
);
89 struct timeval evtpause
= { 1, 0 };
93 evtimer_add(&accept_queue
.evt
, &evtpause
);
99 if (evtimer_pending(&accept_queue
.evt
, NULL
)) {
101 evtimer_del(&accept_queue
.evt
);
109 struct accept_ev
*av
;
110 LIST_FOREACH(av
, &accept_queue
.queue
, entry
)
111 event_add(&av
->ev
, NULL
);
117 struct accept_ev
*av
;
118 LIST_FOREACH(av
, &accept_queue
.queue
, entry
)
123 accept_cb(int fd
, short event
, void *arg
)
125 struct accept_ev
*av
= arg
;
126 event_add(&av
->ev
, NULL
);
127 av
->accept_cb(fd
, event
, av
->arg
);
131 accept_timeout(int fd
, short event
, void *bula
)