summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/event.c40
-rw-r--r--lib/event.h1
-rw-r--r--lib/tcp.c34
-rw-r--r--lib/tcp.h1
4 files changed, 38 insertions, 38 deletions
diff --git a/lib/event.c b/lib/event.c
index 97a08c8..55a7e6b 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -14,10 +14,11 @@
#endif
#include <radsec/radsec.h>
#include <radsec/radsec-impl.h>
+#include "tcp.h"
+#include "udp.h"
#if defined (RS_ENABLE_TLS)
#include "tls.h"
#endif
-#include "udp.h"
#include "event.h"
#include "packet.h"
#include "debug.h"
@@ -74,24 +75,6 @@ event_init_socket (struct rs_connection *conn, struct rs_peer *p)
return RSE_OK;
}
-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_IO, __FILE__, __LINE__, NULL);
- event_loopbreak (conn);
- }
-}
-
int
event_init_bufferevent (struct rs_connection *conn, struct rs_peer *peer)
{
@@ -155,7 +138,7 @@ event_do_connect (struct rs_connection *conn)
if (p->conn->bev) /* TCP */
{
- event_set_timeout (conn);
+ tcp_set_connect_timeout (conn);
err = bufferevent_socket_connect (p->conn->bev, p->addr->ai_addr,
p->addr->ai_addrlen);
if (err < 0)
@@ -192,23 +175,6 @@ event_loopbreak (struct rs_connection *conn)
}
-int
-event_set_timeout (struct rs_connection *conn)
-{
- struct timeval tv;
-
- if (!conn->tev)
- conn->tev = evtimer_new (conn->evb, _conn_timeout_cb, conn);
- if (!conn->tev)
- return rs_err_conn_push_fl (conn, RSE_EVENT, __FILE__, __LINE__,
- "evtimer_new");
- tv.tv_sec = conn->realm->timeout;
- tv.tv_usec = 0;
- evtimer_add (conn->tev, &tv);
-
- return RSE_OK;
-}
-
void
event_on_disconnect (struct rs_connection *conn)
{
diff --git a/lib/event.h b/lib/event.h
index 5395f58..e5ea90c 100644
--- a/lib/event.h
+++ b/lib/event.h
@@ -1,7 +1,6 @@
/* Copyright 2011 NORDUnet A/S. All rights reserved.
See the file COPYING for licensing information. */
-int event_set_timeout (struct rs_connection *conn);
void event_on_disconnect (struct rs_connection *conn);
void event_on_connect (struct rs_connection *conn, struct rs_packet *pkt);
int event_loopbreak (struct rs_connection *conn);
diff --git a/lib/tcp.c b/lib/tcp.c
index 2e641f6..acee94b 100644
--- a/lib/tcp.c
+++ b/lib/tcp.c
@@ -23,6 +23,24 @@
#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_IO, __FILE__, __LINE__, NULL);
+ event_loopbreak (conn);
+ }
+}
+
static int
_close_conn (struct rs_connection **connp)
{
@@ -274,3 +292,19 @@ tcp_write_cb (struct bufferevent *bev, void *ctx)
pkt->conn->callbacks.sent_cb (pkt->conn->user_data);
}
+int
+tcp_set_connect_timeout (struct rs_connection *conn)
+{
+ struct timeval tv;
+
+ if (!conn->tev)
+ conn->tev = evtimer_new (conn->evb, _conn_timeout_cb, conn);
+ if (!conn->tev)
+ return rs_err_conn_push_fl (conn, RSE_EVENT, __FILE__, __LINE__,
+ "evtimer_new");
+ tv.tv_sec = conn->realm->timeout;
+ tv.tv_usec = 0;
+ evtimer_add (conn->tev, &tv);
+
+ return RSE_OK;
+}
diff --git a/lib/tcp.h b/lib/tcp.h
index eae3e7b..8f519bb 100644
--- a/lib/tcp.h
+++ b/lib/tcp.h
@@ -4,3 +4,4 @@
void tcp_event_cb (struct bufferevent *bev, short events, void *user_data);
void tcp_read_cb (struct bufferevent *bev, void *user_data);
void tcp_write_cb (struct bufferevent *bev, void *ctx);
+int tcp_set_connect_timeout (struct rs_connection *conn);