r96 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Apr 3 13:03:28 CEST 2006


Author: phk
Date: 2006-04-03 13:03:28 +0200 (Mon, 03 Apr 2006)
New Revision: 96

Modified:
   trunk/varnish-cache/bin/varnishd/cache_main.c
   trunk/varnish-cache/bin/varnishd/cli_event.c
   trunk/varnish-cache/bin/varnishd/cli_event.h
   trunk/varnish-cache/bin/varnishd/mgt.h
   trunk/varnish-cache/bin/varnishd/mgt_child.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
How I wish people would think more ahead when writing libraries like
libevent.  The entire "implicit event engine" api assumption stinks.

Deal with it better.



Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c	2006-04-03 09:02:27 UTC (rev 95)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c	2006-04-03 11:03:28 UTC (rev 96)
@@ -113,7 +113,7 @@
 	assert(eb != NULL);
 
 	CVCL_Load(heritage.vcl_file, "boot");
-	cli = cli_setup(heritage.fds[2], heritage.fds[1], 0, cli_proto);
+	cli = cli_setup(eb, heritage.fds[2], heritage.fds[1], 0, cli_proto);
 
 	evtimer_set(&ev_keepalive, timer_keepalive, NULL);
 	event_base_set(eb, &ev_keepalive);

Modified: trunk/varnish-cache/bin/varnishd/cli_event.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cli_event.c	2006-04-03 09:02:27 UTC (rev 95)
+++ trunk/varnish-cache/bin/varnishd/cli_event.c	2006-04-03 11:03:28 UTC (rev 96)
@@ -123,8 +123,25 @@
 	printf("%s(%p, %d, %p)\n", __func__, (void*)bev, what, arg);
 }
 
+/*
+ * XXX: included in libevent in CVS
+ */
+
+static int
+bufferevent_base_set(struct event_base *base, struct bufferevent *bufev)
+{
+	int res;
+
+	res = event_base_set(base, &bufev->ev_read);
+	if (res == -1)
+		return (res);
+
+	res = event_base_set(base, &bufev->ev_write);
+		return (res);
+}
+
 struct cli *
-cli_setup(int fdr, int fdw, int ver, struct cli_proto *cli_proto)
+cli_setup(struct event_base *eb, int fdr, int fdw, int ver, struct cli_proto *cli_proto)
 {
 	struct cli	*cli;
 
@@ -133,11 +150,13 @@
 
 	cli->bev0 = bufferevent_new(fdr, rdcb, wrcb, excb, cli);
 	assert(cli->bev0 != NULL);
+	bufferevent_base_set(eb, cli->bev0);
 	if (fdr == fdw)
 		cli->bev1 = cli->bev0;
 	else 
 		cli->bev1 = bufferevent_new(fdw, rdcb, wrcb, excb, cli);
 	assert(cli->bev1 != NULL);
+	bufferevent_base_set(eb, cli->bev1);
 	cli->sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
 	assert(cli->sb != NULL);
 

Modified: trunk/varnish-cache/bin/varnishd/cli_event.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cli_event.h	2006-04-03 09:02:27 UTC (rev 95)
+++ trunk/varnish-cache/bin/varnishd/cli_event.h	2006-04-03 11:03:28 UTC (rev 96)
@@ -11,7 +11,7 @@
 	struct cli_proto	*cli_proto;
 };
 
-struct cli *cli_setup(int fdr, int fdw, int ver, struct cli_proto *cli_proto);
+struct cli *cli_setup(struct event_base *eb, int fdr, int fdw, int ver, struct cli_proto *cli_proto);
 void cli_suspend(struct cli *cli);
 void cli_resume(struct cli *cli);
 void cli_encode_string(struct evbuffer *buf, char *b);

Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h	2006-04-03 09:02:27 UTC (rev 95)
+++ trunk/varnish-cache/bin/varnishd/mgt.h	2006-04-03 11:03:28 UTC (rev 96)
@@ -2,7 +2,7 @@
  * $Id$
  */
 
-extern struct event_base *eb;
+extern struct event_base *mgt_eb;
 
 void mgt_child_start(void);
 void mgt_child_stop(void);

Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c	2006-04-03 09:02:27 UTC (rev 95)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c	2006-04-03 11:03:28 UTC (rev 96)
@@ -246,6 +246,7 @@
 	assert(child_cli1 != NULL);
 
 	evtimer_set(&ev_child_pingpong, child_pingpong, NULL);
+	event_base_set(mgt_eb, &ev_child_pingpong);
 	child_pingpong(0, 0, NULL);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2006-04-03 09:02:27 UTC (rev 95)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2006-04-03 11:03:28 UTC (rev 96)
@@ -34,7 +34,7 @@
 /*--------------------------------------------------------------------*/
 
 struct heritage heritage;
-struct event_base *eb;
+struct event_base *mgt_eb;
 
 /*--------------------------------------------------------------------
  * Generic passthrough for CLI functions
@@ -242,15 +242,15 @@
 	struct cli *cli;
 	int i;
 
-	eb = event_init();
-	assert(eb != NULL);
+	mgt_eb = event_init();
+	assert(mgt_eb != NULL);
 
-	cli = cli_setup(0, 1, 1, cli_proto);
+	cli = cli_setup(mgt_eb, 0, 1, 1, cli_proto);
 
 	signal_set(&e_sigchld, SIGCHLD, mgt_sigchld, NULL);
 	signal_add(&e_sigchld, NULL);
 
-	i = event_dispatch();
+	i = event_base_loop(mgt_eb, 0);
 	if (i != 0)
 		printf("event_dispatch() = %d\n", i);
 




More information about the varnish-commit mailing list