pluto: Added a generic event queue.

This allows to easily execute arbitrary callbacks in the context of the pluto
main thread (e.g. in order to synchronize with threads from the thread-pool).
This commit is contained in:
Tobias Brunner
2010-09-02 19:04:21 +02:00
parent 4cf459a054
commit 8808edfb4c
6 changed files with 292 additions and 1 deletions
+18 -1
View File
@@ -56,6 +56,7 @@
#include "adns.h" /* needs <resolv.h> */
#include "dnskey.h" /* needs keys.h and adns.h */
#include "whack.h" /* for RC_LOG_SERIOUS */
#include "pluto.h"
#include <pfkeyv2.h>
#include <pfkey.h>
@@ -811,7 +812,7 @@ call_server(void)
{
fd_set readfds;
fd_set writefds;
int ndes;
int ndes, events_fd;
/* wait for next interesting thing */
@@ -853,6 +854,11 @@ call_server(void)
FD_SET(adns_afd, &readfds);
}
events_fd = pluto->events->get_event_fd(pluto->events);
if (maxfd < events_fd)
maxfd = events_fd;
FD_SET(events_fd, &readfds);
#ifdef KLIPS
if (!no_klips)
{
@@ -947,6 +953,17 @@ call_server(void)
ndes--;
}
if (FD_ISSET(events_fd, &readfds))
{
passert(ndes > 0);
DBG(DBG_CONTROL,
DBG_log(BLANK_FORMAT);
DBG_log("*handling asynchronous events"));
pluto->events->handle(pluto->events);
passert(GLOBALS_ARE_RESET());
ndes--;
}
#ifdef KLIPS
if (!no_klips && FD_ISSET(*kernel_ops->async_fdp, &readfds))
{