]> git.meshlink.io Git - meshlink/commitdiff
Rename "event_t" to "tevent_t", along with associated functions.
authorScott Lamb <slamb@slamb.org>
Tue, 27 Feb 2007 01:26:11 +0000 (01:26 +0000)
committerScott Lamb <slamb@slamb.org>
Tue, 27 Feb 2007 01:26:11 +0000 (01:26 +0000)
This relieves some confusion and problems during the libevent transition.
In particular, "event_add" was defined by both.
(The 't' stands for 'timeout', 'tinc', 'temporary', or some such.)

src/Makefile.am
src/event.c [deleted file]
src/event.h [deleted file]
src/net.c
src/net_packet.c
src/net_setup.c
src/net_socket.c
src/node.c
src/node.h
src/tevent.c [new file with mode: 0644]
src/tevent.h [new file with mode: 0644]

index 10f07af59e950e86de7acf717813d9c4cdaab6c1..c9c1ac90a99c355fc127dfb16cac95316a0f60cf 100644 (file)
@@ -5,7 +5,7 @@ sbin_PROGRAMS = tincd
 
 EXTRA_DIST = linux/device.c bsd/device.c solaris/device.c cygwin/device.c mingw/device.c mingw/common.h raw_socket/device.c uml_socket/device.c
 
-tincd_SOURCES = conf.c connection.c edge.c event.c graph.c logger.c meta.c net.c net_packet.c net_setup.c      \
+tincd_SOURCES = conf.c connection.c edge.c tevent.c graph.c logger.c meta.c net.c net_packet.c net_setup.c     \
        net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_edge.c protocol_misc.c       \
        protocol_key.c protocol_subnet.c route.c subnet.c tincd.c
 
@@ -15,7 +15,7 @@ DEFAULT_INCLUDES =
 
 INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib
 
-noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h logger.h meta.h net.h netutl.h node.h process.h   \
+noinst_HEADERS = conf.h connection.h device.h edge.h tevent.h graph.h logger.h meta.h net.h netutl.h node.h process.h  \
        protocol.h route.h subnet.h
 
 LIBS = @LIBS@ @LIBINTL@
diff --git a/src/event.c b/src/event.c
deleted file mode 100644 (file)
index c791205..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
-    event.c -- event queue
-    Copyright (C) 2002-2006 Guus Sliepen <guus@tinc-vpn.org>,
-                  2002-2005 Ivo Timmermans
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    $Id$
-*/
-
-#include "system.h"
-
-#include "avl_tree.h"
-#include "event.h"
-#include "utils.h"
-#include "xalloc.h"
-
-avl_tree_t *event_tree;
-extern time_t now;
-
-int id;
-
-static int event_compare(const event_t *a, const event_t *b)
-{
-       if(a->time > b->time)
-               return 1;
-
-       if(a->time < b->time)
-               return -1;
-
-       return a->id - b->id;
-}
-
-void init_events(void)
-{
-       cp();
-
-       event_tree = avl_alloc_tree((avl_compare_t) event_compare, NULL);
-}
-
-void exit_events(void)
-{
-       cp();
-
-       avl_delete_tree(event_tree);
-}
-
-void flush_events(void)
-{
-       avl_tree_t *to_flush;
-       event_t *event;
-
-       /*
-        * Events can be inserted from event handlers, so only flush events
-        * already in the priority queue.
-        */
-
-       cp();
-
-       to_flush = event_tree;
-       init_events();
-       while (to_flush->head) {
-               event = to_flush->head->data;
-               event->handler(event->data);
-               avl_delete(to_flush, event);
-       }
-       avl_delete_tree(to_flush);
-}
-
-event_t *new_event(void)
-{
-       cp();
-
-       return xmalloc_and_zero(sizeof(event_t));
-}
-
-void free_event(event_t *event)
-{
-       cp();
-
-       free(event);
-}
-
-void event_add(event_t *event)
-{
-       cp();
-
-       event->id = ++id;
-       avl_insert(event_tree, event);
-}
-
-void event_del(event_t *event)
-{
-       cp();
-
-       avl_delete(event_tree, event);
-}
-
-event_t *get_expired_event(void)
-{
-       event_t *event;
-
-       cp();
-
-       if(event_tree->head) {
-               event = event_tree->head->data;
-
-               if(event->time < now) {
-                       event_del(event);
-                       return event;
-               }
-       }
-
-       return NULL;
-}
diff --git a/src/event.h b/src/event.h
deleted file mode 100644 (file)
index 50e5b97..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
-    event.h -- header for event.c
-    Copyright (C) 2002-2006 Guus Sliepen <guus@tinc-vpn.org>,
-                  2002-2005 Ivo Timmermans
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    $Id$
-*/
-
-#ifndef __TINC_EVENT_H__
-#define __TINC_EVENT_H__
-
-#include "avl_tree.h"
-
-extern avl_tree_t *event_tree;
-
-typedef void (*event_handler_t)(void *);
-
-typedef struct {
-       time_t time;
-       int id;
-       event_handler_t handler;
-       void *data;
-} event_t;
-
-extern void init_events(void);
-extern void exit_events(void);
-extern void flush_events(void);
-extern event_t *new_event(void) __attribute__ ((__malloc__));
-extern void free_event(event_t *);
-extern void event_add(event_t *);
-extern void event_del(event_t *);
-extern event_t *get_expired_event(void);
-
-#endif                                                 /* __TINC_EVENT_H__ */
index f6b14704607477544b6a34f54cf2144096fe2548..9156147dd73f4e162f90f024ad96ff63bd952394 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -29,7 +29,7 @@
 #include "conf.h"
 #include "connection.h"
 #include "device.h"
-#include "event.h"
+#include "tevent.h"
 #include "graph.h"
 #include "logger.h"
 #include "meta.h"
@@ -355,7 +355,7 @@ int main_loop(void)
        struct timeval tv;
        int r, maxfd;
        time_t last_ping_check, last_config_check, last_graph_dump;
-       event_t *event;
+       tevent_t *event;
 
        cp();
 
index 105cafbb21e3d2b90368fa739de5a1aafff95d8e..9e0ba2e893fc688c898f5ba15ffc15c1bb2171f6 100644 (file)
@@ -36,7 +36,7 @@
 #include "connection.h"
 #include "device.h"
 #include "ethernet.h"
-#include "event.h"
+#include "tevent.h"
 #include "graph.h"
 #include "list.h"
 #include "logger.h"
@@ -96,11 +96,11 @@ void send_mtu_probe(node_t *n)
                send_udppacket(n, &packet);
        }
 
-       n->mtuevent = new_event();
+       n->mtuevent = new_tevent();
        n->mtuevent->handler = (event_handler_t)send_mtu_probe;
        n->mtuevent->data = n;
        n->mtuevent->time = now + 1;
-       event_add(n->mtuevent);
+       tevent_add(n->mtuevent);
 }
 
 void mtu_probe_h(node_t *n, vpn_packet_t *packet) {
index f53127b5989085c5753018e8bb4eb9d7f020e503..84171e722ecc910c8ee50bd274f12290687e7281 100644 (file)
@@ -32,7 +32,7 @@
 #include "conf.h"
 #include "connection.h"
 #include "device.h"
-#include "event.h"
+#include "tevent.h"
 #include "graph.h"
 #include "logger.h"
 #include "net.h"
index c2a685965a362c1314308b4046e1fc8d16585f0e..1db1949c1676fd824f8d8aff6129fb44d8a3fe1c 100644 (file)
@@ -25,7 +25,7 @@
 #include "avl_tree.h"
 #include "conf.h"
 #include "connection.h"
-#include "event.h"
+#include "tevent.h"
 #include "logger.h"
 #include "meta.h"
 #include "net.h"
@@ -220,7 +220,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa)
 
 void retry_outgoing(outgoing_t *outgoing)
 {
-       event_t *event;
+       tevent_t *event;
 
        cp();
 
@@ -229,11 +229,11 @@ void retry_outgoing(outgoing_t *outgoing)
        if(outgoing->timeout > maxtimeout)
                outgoing->timeout = maxtimeout;
 
-       event = new_event();
+       event = new_tevent();
        event->handler = (event_handler_t) setup_outgoing_connection;
        event->time = now + outgoing->timeout;
        event->data = outgoing;
-       event_add(event);
+       tevent_add(event);
 
        ifdebug(CONNECTIONS) logger(LOG_NOTICE,
                           _("Trying to re-establish outgoing connection in %d seconds"),
index 5dad0aaf379851c2518c586cb8fe43e63036ddbb..ec6815a61f41607cd8332a79cba43935f68efc4f 100644 (file)
@@ -107,7 +107,7 @@ void free_node(node_t *n)
        EVP_CIPHER_CTX_cleanup(&n->packet_ctx);
 
        if(n->mtuevent) {
-               event_del(n->mtuevent);
+               tevent_del(n->mtuevent);
                free_event(n->mtuevent);
        }
        
index 4b3224e3cab4da7822f5441c729598a03a50a8de..b3319e17350ae1e347c993d0a280d80f23d26ce0 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "avl_tree.h"
 #include "connection.h"
-#include "event.h"
+#include "tevent.h"
 #include "list.h"
 #include "subnet.h"
 
@@ -80,7 +80,7 @@ typedef struct node_t {
        length_t minmtu;                        /* Probed minimum MTU */
        length_t maxmtu;                        /* Probed maximum MTU */
        int mtuprobes;                          /* Number of probes */
-       event_t *mtuevent;                      /* Probe event */
+       tevent_t *mtuevent;                     /* Probe event */
 } node_t;
 
 extern struct node_t *myself;
diff --git a/src/tevent.c b/src/tevent.c
new file mode 100644 (file)
index 0000000..bdda639
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+    event.c -- event queue
+    Copyright (C) 2002-2006 Guus Sliepen <guus@tinc-vpn.org>,
+                  2002-2005 Ivo Timmermans
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+    $Id$
+*/
+
+#include "system.h"
+
+#include "avl_tree.h"
+#include "tevent.h"
+#include "utils.h"
+#include "xalloc.h"
+
+avl_tree_t *tevent_tree;
+extern time_t now;
+
+int id;
+
+static int tevent_compare(const tevent_t *a, const tevent_t *b)
+{
+       if(a->time > b->time)
+               return 1;
+
+       if(a->time < b->time)
+               return -1;
+
+       return a->id - b->id;
+}
+
+void init_tevents(void)
+{
+       cp();
+
+       tevent_tree = avl_alloc_tree((avl_compare_t) tevent_compare, NULL);
+}
+
+void exit_tevents(void)
+{
+       cp();
+
+       avl_delete_tree(tevent_tree);
+}
+
+void flush_tevents(void)
+{
+       avl_tree_t *to_flush;
+       tevent_t *event;
+
+       /*
+        * Events can be inserted from event handlers, so only flush events
+        * already in the priority queue.
+        */
+
+       cp();
+
+       to_flush = tevent_tree;
+       init_tevents();
+       while (to_flush->head) {
+               event = to_flush->head->data;
+               event->handler(event->data);
+               avl_delete(to_flush, event);
+       }
+       avl_delete_tree(to_flush);
+}
+
+tevent_t *new_tevent(void)
+{
+       cp();
+
+       return xmalloc_and_zero(sizeof(tevent_t));
+}
+
+void free_tevent(tevent_t *event)
+{
+       cp();
+
+       free(event);
+}
+
+void tevent_add(tevent_t *event)
+{
+       cp();
+
+       event->id = ++id;
+       avl_insert(tevent_tree, event);
+}
+
+void tevent_del(tevent_t *event)
+{
+       cp();
+
+       avl_delete(tevent_tree, event);
+}
+
+tevent_t *get_expired_tevent(void)
+{
+       tevent_t *event;
+
+       cp();
+
+       if(tevent_tree->head) {
+               event = tevent_tree->head->data;
+
+               if(event->time < now) {
+                       tevent_del(event);
+                       return event;
+               }
+       }
+
+       return NULL;
+}
diff --git a/src/tevent.h b/src/tevent.h
new file mode 100644 (file)
index 0000000..8f5cfd8
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+    event.h -- header for event.c
+    Copyright (C) 2002-2006 Guus Sliepen <guus@tinc-vpn.org>,
+                  2002-2005 Ivo Timmermans
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+    $Id$
+*/
+
+#ifndef __TINC_EVENT_H__
+#define __TINC_EVENT_H__
+
+#include "avl_tree.h"
+
+extern avl_tree_t *tevent_tree;
+
+typedef void (*event_handler_t)(void *);
+
+typedef struct {
+       time_t time;
+       int id;
+       event_handler_t handler;
+       void *data;
+} tevent_t;
+
+extern void init_tevents(void);
+extern void exit_tevents(void);
+extern void flush_tevents(void);
+extern tevent_t *new_tevent(void) __attribute__ ((__malloc__));
+extern void free_tevent(tevent_t *);
+extern void tevent_add(tevent_t *);
+extern void tevent_del(tevent_t *);
+extern tevent_t *get_expired_tevent(void);
+
+#endif                                                 /* __TINC_EVENT_H__ */