From a67ab277c9fdbcfc8c0550e9046df2a00b5fed81 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 17 May 2007 22:09:55 +0000 Subject: [PATCH] Use libevent for retrying outgoing connections. --- src/net.h | 1 + src/net_socket.c | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/net.h b/src/net.h index 9082d8b9..7d1ea7bf 100644 --- a/src/net.h +++ b/src/net.h @@ -115,6 +115,7 @@ typedef struct outgoing_t { struct config_t *cfg; struct addrinfo *ai; struct addrinfo *aip; + struct event ev; } outgoing_t; extern int maxoutbufsize; diff --git a/src/net_socket.c b/src/net_socket.c index 9cb2ecd0..5394d364 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -25,7 +25,6 @@ #include "avl_tree.h" #include "conf.h" #include "connection.h" -#include "tevent.h" #include "logger.h" #include "meta.h" #include "net.h" @@ -234,10 +233,11 @@ int setup_vpn_in_socket(const sockaddr_t *sa) return nfd; } -void retry_outgoing(outgoing_t *outgoing) -{ - tevent_t *event; +static void retry_outgoing_handler(int fd, short events, void *data) { + retry_outgoing(data); +} +void retry_outgoing(outgoing_t *outgoing) { cp(); outgoing->timeout += 5; @@ -245,11 +245,8 @@ void retry_outgoing(outgoing_t *outgoing) if(outgoing->timeout > maxtimeout) outgoing->timeout = maxtimeout; - event = new_tevent(); - event->handler = (event_handler_t) setup_outgoing_connection; - event->time = now + outgoing->timeout; - event->data = outgoing; - tevent_add(event); + timeout_set(&outgoing->ev, retry_outgoing_handler, outgoing); + event_add(&outgoing->ev, &(struct timeval){outgoing->timeout, 0}); ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Trying to re-establish outgoing connection in %d seconds"),