summaryrefslogtreecommitdiff
path: root/lib/tcp.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-03-09 10:18:06 +0100
committerLinus Nordberg <linus@nordu.net>2011-03-09 10:18:06 +0100
commitce4d6dfe1728e5633a8f49fc4b16c36df0d23521 (patch)
tree679a007b7897e03e9105a0902a84a8df1356e8c7 /lib/tcp.c
parentc4e2bd206bb9248843a8a4d9a945c5e49a188474 (diff)
Add retransmission timer support (UDP).
Diffstat (limited to 'lib/tcp.c')
-rw-r--r--lib/tcp.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/tcp.c b/lib/tcp.c
index 063e9b2..ce071cd 100644
--- a/lib/tcp.c
+++ b/lib/tcp.c
@@ -24,24 +24,6 @@
#include <event2/buffer.h>
#endif
-static void
-_conn_timeout_cb (int fd, short event, void *data)
-{
- struct rs_connection *conn;
-
- assert (data);
- conn = (struct rs_connection *) data;
-
- if (event & EV_TIMEOUT)
- {
- rs_debug (("%s: connection timeout on %p (fd %d) connecting to %p\n",
- __func__, conn, conn->fd, conn->active_peer));
- conn->is_connecting = 0;
- rs_err_conn_push_fl (conn, RSE_TIMEOUT_CONN, __FILE__, __LINE__, NULL);
- event_loopbreak (conn);
- }
-}
-
/* Read one RADIUS packet header. Return !0 on error. A return value
of 0 means that we need more data. */
static int
@@ -191,6 +173,8 @@ tcp_event_cb (struct bufferevent *bev, short events, void *user_data)
conn->is_connecting = 0;
if (events & BEV_EVENT_CONNECTED)
{
+ if (conn->tev)
+ evtimer_del (conn->tev); /* Cancel connect timer. */
event_on_connect (conn, pkt);
}
else if (events & BEV_EVENT_EOF)
@@ -255,13 +239,16 @@ tcp_write_cb (struct bufferevent *bev, void *ctx)
}
int
-tcp_set_connect_timeout (struct rs_connection *conn)
+tcp_init_connect_timer (struct rs_connection *conn)
{
- if (!conn->tev)
- conn->tev = evtimer_new (conn->evb, _conn_timeout_cb, conn);
+ assert (conn);
+
+ if (conn->tev)
+ event_free (conn->tev);
+ conn->tev = evtimer_new (conn->evb, event_conn_timeout_cb, conn);
if (!conn->tev)
return rs_err_conn_push_fl (conn, RSE_EVENT, __FILE__, __LINE__,
"evtimer_new");
- evtimer_add (conn->tev, &conn->timeout);
+
return RSE_OK;
}