Skip to contentSkip to conversation

CLD: drop dependency on libevent from libcldc

PATCH In review Pete Zaitcev 1 participant 1 message Nov 29, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 CLD: drop dependency on libevent from libcldc

Let's remove the dependency on libevent completely. The core CLD daemon did not use libevent for some time, but getting rid of it entirely required an implementation of some kind of common main loop for tests, which is what this patch does.

Since we were refactoring, we add a common header and library for tests, same as Chunk has.

We use the same timers that the main daemon uses (libtimer), they are general enough for other applications such as tests.

This patch introduces an incompatibility, so Chunk and tabled must be rebuilt. This is because the layout of struct cldc_udp changes.

---
 configure.ac           |    4 -
 include/cldc.h         |    7 --
 include/libtimer.h     |    3 -
 lib/cldc-udp.c         |   27 ---------
 pkg/cld.spec           |    2 
 test/.gitignore        |    1 
 test/Makefile.am       |    9 ++-
 test/it-works.c        |   62 +++++++++++++--------
 test/load-file-event.c |  105 +++++++++++++++---------------------
 test/lock-file-event.c |  111 +++++++++++++++++++++------------------
 test/save-file-event.c |  106 +++++++++++++++----------------------
 test/test.h            |   25 ++++++++
 test/util.c            |   58 ++++++++++++++++++++
 tools/Makefile.am      |    2 
 14 files changed, 284 insertions(+), 238 deletions(-)

commit 3930e86ee0be3cedd22f524825895dd465cddd77

Author: Master <[email protected]>
Date:   Sat Nov 28 23:26:39 2009 -0700

Drop libevent dependency.

configure.ac +2 -2
index 26a1548..b1247b6 100644
@@ -78,9 +78,9 @@ AC_CHECK_LIB(db-4.7, db_create, DB4_LIBS=-ldb-4.7,
 	AC_CHECK_LIB(db-4.5, db_create, DB4_LIBS=-ldb-4.5,
 	AC_CHECK_LIB(db-4.4, db_create, DB4_LIBS=-ldb-4.4,
 	AC_CHECK_LIB(db-4.3, db_create, DB4_LIBS=-ldb-4.3, exit 1)))))
-AC_CHECK_LIB(event, event_base_new, EVENT_LIBS=-levent, exit 1)
 AC_CHECK_LIB(argp, argp_parse, ARGP_LIBS=-largp)
 AC_CHECK_LIB(crypto, MD5_Init, CRYPTO_LIBS=-lcrypto)
+AC_CHECK_LIB(resolv, ns_initparse, RESOLV_LIBS=-lresolv)
 
 dnl -------------------------------------
 dnl Checks for optional library functions
@@ -108,9 +108,9 @@ PKG_PROG_PKG_CONFIG()
 AM_PATH_GLIB_2_0(2.0.0,,,gthread)
 
 AC_SUBST(DB4_LIBS)
-AC_SUBST(EVENT_LIBS)
 AC_SUBST(ARGP_LIBS)
 AC_SUBST(CRYPTO_LIBS)
+AC_SUBST(RESOLV_LIBS)
 
 AC_CONFIG_FILES([
 	Makefile
include/cldc.h +0 -7
index 8c2bde5..9ae6dfe 100644
@@ -3,7 +3,6 @@
 
 #include <sys/types.h>
 #include <stdbool.h>
-#include <event.h>
 #include <glib.h>
 #include <cld_msg.h>
 
@@ -130,8 +129,6 @@ struct cldc_udp {
 
 	int		fd;
 
-	struct event	timer_ev;
-
 	struct cldc_session *sess;
 
 	int		(*cb)(struct cldc_session *, void *);
@@ -202,10 +199,6 @@ extern int cldc_udp_receive_pkt(struct cldc_udp *udp);
 extern int cldc_udp_pkt_send(void *private,
 			  const void *addr, size_t addrlen,
 			  const void *buf, size_t buflen);
-extern bool cldc_levent_timer(void *private, bool add,
-		       int (*cb)(struct cldc_session *, void *),
-		       void *cb_private,
-		       time_t secs);
 
 /* cldc-dns */
 extern int cldc_getaddr(GList **host_list, const char *thishost, bool verbose,
include/libtimer.h +1 -2
index aedaea0..c10f993 100644
@@ -20,8 +20,7 @@ extern void timer_del(struct timer *timer);
 extern time_t timers_run(void);
 
 static inline void timer_init(struct timer *timer, const char *name,
-			      void (*cb)(struct timer *),
-			      void *userdata)
+			      void (*cb)(struct timer *), void *userdata)
 {
 	memset(timer, 0, sizeof(*timer));
 	timer->cb = cb;
lib/cldc-udp.c +0 -27
index b212643..0a8d0ad 100644
@@ -42,14 +42,6 @@ void cldc_udp_free(struct cldc_udp *udp)
 	free(udp);
 }
 
-static void cldc_udp_timer(int fd, short events, void *userdata)
-{
-	struct cldc_udp *udp = userdata;
-
-	if (udp->cb)
-		udp->cb(udp->sess, udp->cb_private);
-}
-
 int cldc_udp_new(const char *hostname, int port,
 		 struct cldc_udp **udp_out)
 {
@@ -100,8 +92,6 @@ int cldc_udp_new(const char *hostname, int port,
 
 	udp->fd = fd;
 
-	evtimer_set(&udp->timer_ev, cldc_udp_timer, udp);
-
 	freeaddrinfo(res);
 
 	*udp_out = udp;
@@ -149,20 +139,3 @@ int cldc_udp_pkt_send(void *private,
 	return 0;
 }
 
-bool cldc_levent_timer(void *private, bool add,
-		       int (*cb)(struct cldc_session *, void *),
-		       void *cb_private,
-		       time_t secs)
-{
-	struct cldc_udp *udp = private;
-	struct timeval tv = { secs, 0 };
-
-	if (add) {
-		udp->cb = cb;
-		udp->cb_private = cb_private;
-		return evtimer_add(&udp->timer_ev, &tv) == 0;
-	} else {
-		return evtimer_del(&udp->timer_ev) == 0;
-	}
-}
-
pkg/cld.spec +1 -1
index 3b93a0d..daeaa4a 100644
@@ -15,7 +15,7 @@ BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 Requires(post):		chkconfig
 Requires(preun):	chkconfig initscripts
 
-BuildRequires:	db4-devel libevent-devel glib2-devel doxygen openssl-devel
+BuildRequires:	db4-devel glib2-devel doxygen openssl-devel
 BuildRequires:	texlive-latex
 
 %description
test/.gitignore +1 -0
index 386e7b1..00a676c 100644
@@ -1,5 +1,6 @@
 
 .libs
+libtest.a
 it-works
 save-file-event
 load-file-event
test/Makefile.am +8 -1
index af67b90..a04058c 100644
@@ -3,6 +3,7 @@ INCLUDES        = -I$(top_srcdir)/include       \
 		  @GLIB_CFLAGS@
 
 EXTRA_DIST =			\
+	test.h			\
 	prep-db			\
 	start-daemon		\
 	pid-exists		\
@@ -24,10 +25,16 @@ check_PROGRAMS		= it-works \
 			  save-file-event load-file-event lock-file-event
 
 TESTLDADD		= ../lib/libcldc.la	\
-			  @GLIB_LIBS@ @CRYPTO_LIBS@ @EVENT_LIBS@
+			  ../lib/libtimer.a	\
+			  libtest.a		\
+			  @GLIB_LIBS@ @CRYPTO_LIBS@ @RESOLV_LIBS@
 it_works_LDADD		= $(TESTLDADD)
 save_file_event_LDADD	= $(TESTLDADD)
 load_file_event_LDADD	= $(TESTLDADD)
 lock_file_event_LDADD	= $(TESTLDADD)
 
+noinst_LIBRARIES	= libtest.a
+
+libtest_a_SOURCES	= util.c
+
 TESTS_ENVIRONMENT=top_srcdir=$(top_srcdir)
test/it-works.c +38 -24

109 lines not on this page · raw message

test/load-file-event.c +44 -61

179 lines not on this page · raw message

test/lock-file-event.c +61 -50

213 lines not on this page · raw message

test/save-file-event.c +44 -62

181 lines not on this page · raw message

test/test.h new file +25 -0
new file mode 100644
index 0000000..8e87684
@@ -0,0 +1,25 @@
+#ifndef _CLD_TEST_H_
+#define _CLD_TEST_H_
+
+#include <stdbool.h>
+#include <cldc.h>
+
+#define TESTSTR          "longertestdata\n"
+#define TESTLEN  (sizeof("longertestdata\n")-1)
+
+#define LOCKSTR          "testlock\n"
+#define LOCKLEN  (sizeof("testlock\n")-1)
+
+#define TFNAME     "/cld-test-inst"
+#define TLNAME     "/cld-lock-inst"
+
+#define TEST_HOST "localhost"
+
+#define TEST_USER "testuser"
+#define TEST_USER_KEY "testuser"
+
+#define TEST_PORTFILE_CLD	"cld.port"
+
+extern void test_loop(struct cldc_udp *udp);
+
+#endif
test/util.c new file +58 -0

58 lines not on this page · raw message

tools/Makefile.am +1 -1
index c171a78..2a6e1a5 100644
@@ -5,5 +5,5 @@ INCLUDES	= -I$(top_srcdir)/include	\
 bin_PROGRAMS	= cldcli
 
 cldcli_LDADD	= ../lib/libcldc.la		\
-		  @GLIB_LIBS@ @CRYPTO_LIBS@ @EVENT_LIBS@ @ARGP_LIBS@
+		  @GLIB_LIBS@ @CRYPTO_LIBS@ @ARGP_LIBS@ @RESOLV_LIBS@