]>
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.
26 LIST_ENTRY(accept_ev
) entry
;
28 int (*accept_cb
)(struct thread
*);
34 LIST_HEAD(, accept_ev
) queue
;
38 static void accept_arm(void);
39 static void accept_unarm(void);
40 static int accept_cb(struct thread
*);
41 static int accept_timeout(struct thread
*);
46 LIST_INIT(&accept_queue
.queue
);
50 accept_add(int fd
, int (*cb
)(struct thread
*), void *arg
)
54 if ((av
= calloc(1, sizeof(*av
))) == NULL
)
59 LIST_INSERT_HEAD(&accept_queue
.queue
, av
, entry
);
62 thread_add_read(master
, accept_cb
, av
, av
->fd
, &av
->ev
);
64 log_debug("%s: accepting on fd %d", __func__
, fd
);
74 LIST_FOREACH(av
, &accept_queue
.queue
, entry
)
76 log_debug("%s: %d removed from queue", __func__
, fd
);
77 THREAD_READ_OFF(av
->ev
);
78 LIST_REMOVE(av
, entry
);
89 accept_queue
.evt
= NULL
;
90 thread_add_timer(master
, accept_timeout
, NULL
, 1, &accept_queue
.evt
);
96 if (accept_queue
.evt
!= NULL
) {
98 THREAD_TIMER_OFF(accept_queue
.evt
);
106 struct accept_ev
*av
;
107 LIST_FOREACH(av
, &accept_queue
.queue
, entry
) {
109 thread_add_read(master
, accept_cb
, av
, av
->fd
, &av
->ev
);
116 struct accept_ev
*av
;
117 LIST_FOREACH(av
, &accept_queue
.queue
, entry
)
118 THREAD_READ_OFF(av
->ev
);
122 accept_cb(struct thread
*thread
)
124 struct accept_ev
*av
= THREAD_ARG(thread
);
126 thread_add_read(master
, accept_cb
, av
, av
->fd
, &av
->ev
);
127 av
->accept_cb(thread
);
133 accept_timeout(struct thread
*thread
)
135 accept_queue
.evt
= NULL
;