summaryrefslogtreecommitdiff
path: root/lib/radsec.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-09-29 15:52:39 +0200
committerLinus Nordberg <linus@nordu.net>2010-09-29 15:52:39 +0200
commitb10a02e5f3a7dd184ada869015e438e63bca52bf (patch)
tree70c74d012d2a89c1a1efefa5afc0787de0b84368 /lib/radsec.c
parente2633633030e62994ca41ff62006e3e40517c73a (diff)
WIP -- connecting and sending a packet using libevent.
Diffstat (limited to 'lib/radsec.c')
-rw-r--r--lib/radsec.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/radsec.c b/lib/radsec.c
index 97f62e6..82576e1 100644
--- a/lib/radsec.c
+++ b/lib/radsec.c
@@ -5,6 +5,7 @@
#include <libgen.h>
#include <freeradius/libradius.h>
+#include <event2/event.h>
#include <event2/util.h>
#include "libradsec.h"
#include "libradsec-impl.h"
@@ -202,6 +203,9 @@ rs_conn_destroy(struct rs_connection *conn)
if (p->secret)
rs_free (conn->ctx, p->secret);
}
+
+ if (conn->evb)
+ event_base_free (conn->evb);
}
int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb)
@@ -245,6 +249,7 @@ rs_conn_open(struct rs_connection *conn)
if (s < 0)
return rs_conn_err_push_fl (conn, RSE_SOME_ERROR, __FILE__, __LINE__,
strerror (errno));
+#if 0 /* let librevent do this in rs_packet_send() */
if (connect (s, p->addr->ai_addr, p->addr->ai_addrlen))
{
/* TODO: handle nonblocking sockets (EINTR, EAGAIN). */
@@ -252,6 +257,23 @@ rs_conn_open(struct rs_connection *conn)
return rs_conn_err_push_fl (conn, RSE_SOME_ERROR, __FILE__, __LINE__,
strerror (errno));
}
+#endif
+
+ if (!conn->evb)
+ {
+#if defined (DEBUG)
+ event_enable_debug_mode ();
+#endif
+ conn->evb = event_base_new ();
+ }
+
+ if (!conn->evb)
+ {
+ EVUTIL_CLOSESOCKET (s);
+ return rs_conn_err_push_fl (conn, RSE_EVENT, __FILE__, __LINE__,
+ "event_base_new");
+ }
+
p->s = s;
conn->active_peer = p;
return RSE_OK;