diff options
author | Yves-Alexis Perez <corsac@corsac.net> | 2012-06-28 21:16:07 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@corsac.net> | 2012-06-28 21:16:07 +0200 |
commit | b34738ed08c2227300d554b139e2495ca5da97d6 (patch) | |
tree | 62f33b52820f2e49f0e53c0f8c636312037c8054 /src/libcharon/bus | |
parent | 0a9d51a49042a68daa15b0c74a2b7f152f52606b (diff) | |
download | vyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.tar.gz vyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.zip |
Imported Upstream version 4.6.4
Diffstat (limited to 'src/libcharon/bus')
-rw-r--r-- | src/libcharon/bus/bus.c | 39 | ||||
-rw-r--r-- | src/libcharon/bus/bus.h | 14 | ||||
-rw-r--r-- | src/libcharon/bus/listeners/listener.h | 2 |
3 files changed, 42 insertions, 13 deletions
diff --git a/src/libcharon/bus/bus.c b/src/libcharon/bus/bus.c index 23931c47d..bf0ab2286 100644 --- a/src/libcharon/bus/bus.c +++ b/src/libcharon/bus/bus.c @@ -151,11 +151,20 @@ static void listener_cleanup(cleanup_data_t *data) entry_destroy(data->entry); } -METHOD(bus_t, listen_, void, - private_bus_t *this, listener_t *listener, job_t *job) +METHOD(bus_t, listen_, bool, + private_bus_t *this, listener_t *listener, job_t *job, u_int timeout) { - bool old; + bool old, timed_out = FALSE; cleanup_data_t data; + timeval_t tv, add; + + if (timeout) + { + add.tv_sec = timeout / 1000; + add.tv_usec = (timeout - (add.tv_sec * 1000)) * 1000; + time_monotonic(&tv); + timeradd(&tv, &add, &tv); + } data.this = this; data.entry = entry_create(listener, TRUE); @@ -168,13 +177,27 @@ METHOD(bus_t, listen_, void, old = thread_cancelability(TRUE); while (data.entry->blocker) { - data.entry->condvar->wait(data.entry->condvar, this->mutex); + if (timeout) + { + if (data.entry->condvar->timed_wait_abs(data.entry->condvar, + this->mutex, tv)) + { + this->listeners->remove(this->listeners, data.entry, NULL); + timed_out = TRUE; + break; + } + } + else + { + data.entry->condvar->wait(data.entry->condvar, this->mutex); + } } thread_cancelability(old); thread_cleanup_pop(FALSE); /* unlock mutex */ thread_cleanup_pop(TRUE); entry_destroy(data.entry); + return timed_out; } METHOD(bus_t, set_sa, void, @@ -564,15 +587,15 @@ METHOD(bus_t, ike_updown, void, /* a down event for IKE_SA implicitly downs all CHILD_SAs */ if (!up) { - iterator_t *iterator; + enumerator_t *enumerator; child_sa_t *child_sa; - iterator = ike_sa->create_child_sa_iterator(ike_sa); - while (iterator->iterate(iterator, (void**)&child_sa)) + enumerator = ike_sa->create_child_sa_enumerator(ike_sa); + while (enumerator->enumerate(enumerator, (void**)&child_sa)) { child_updown(this, child_sa, FALSE); } - iterator->destroy(iterator); + enumerator->destroy(enumerator); } } diff --git a/src/libcharon/bus/bus.h b/src/libcharon/bus/bus.h index 6a306afcc..69060d383 100644 --- a/src/libcharon/bus/bus.h +++ b/src/libcharon/bus/bus.h @@ -80,10 +80,14 @@ typedef struct bus_t bus_t; * Kind of alerts to raise. */ enum alert_t { - /* a RADIUS server did not respond, no additional arguments */ + /** a RADIUS server did not respond, no additional arguments */ ALERT_RADIUS_NOT_RESPONDING, - /* a shutdown signal has been received, argument is a int with the signal */ + /** a shutdown signal has been received, argument is the signal (int) */ ALERT_SHUTDOWN_SIGNAL, + /** peer authentication failed, no arguments */ + ALERT_PEER_AUTH_FAILED, + /** failed to resolve peer address, no arguments */ + ALERT_PEER_ADDR_FAILED, }; /** @@ -148,8 +152,10 @@ struct bus_t { * * @param listener listener to register * @param job job to execute asynchronously when registered, or NULL + * @param timeout max timeout in ms to listen for events, 0 to disable + * @return TRUE if timed out */ - void (*listen)(bus_t *this, listener_t *listener, job_t *job); + bool (*listen)(bus_t *this, listener_t *listener, job_t *job, u_int timeout); /** * Set the IKE_SA the calling thread is using. @@ -177,7 +183,7 @@ struct bus_t { /** * Send a log message to the bus. * - * The signal specifies the type of the event occured. The format string + * The signal specifies the type of the event occurred. The format string * specifies an additional informational or error message with a * printf() like variable argument list. * Use the DBG() macros. diff --git a/src/libcharon/bus/listeners/listener.h b/src/libcharon/bus/listeners/listener.h index e7873ee8c..21caed064 100644 --- a/src/libcharon/bus/listeners/listener.h +++ b/src/libcharon/bus/listeners/listener.h @@ -84,7 +84,7 @@ struct listener_t { /** * Hook called for received/sent messages of an IKE_SA. * - * @param ike_sa IKE_SA sending/receving a message + * @param ike_sa IKE_SA sending/receiving a message * @param message message object * @param incoming TRUE for incoming messages, FALSE for outgoing * @return TRUE to stay registered, FALSE to unregister |