Move event_set_timeout --> tcp_set_connect_timeout.
authorLinus Nordberg <linus@nordu.net>
Sun, 6 Mar 2011 16:08:41 +0000 (17:08 +0100)
committerLinus Nordberg <linus@nordu.net>
Sun, 6 Mar 2011 16:08:41 +0000 (17:08 +0100)
lib/event.c
lib/event.h
lib/tcp.c
lib/tcp.h

index 97a08c8..55a7e6b 100644 (file)
 #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)
 {
index 5395f58..e5ea90c 100644 (file)
@@ -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);
index 2e641f6..acee94b 100644 (file)
--- a/lib/tcp.c
+++ b/lib/tcp.c
 #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;
+}
index eae3e7b..8f519bb 100644 (file)
--- 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);