]> err.no Git - varnish/commitdiff
How I wish people would think more ahead when writing libraries like
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 3 Apr 2006 11:03:28 +0000 (11:03 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 3 Apr 2006 11:03:28 +0000 (11:03 +0000)
libevent.  The entire "implicit event engine" api assumption stinks.

Deal with it better.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@96 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/cli_event.c
varnish-cache/bin/varnishd/cli_event.h
varnish-cache/bin/varnishd/mgt.h
varnish-cache/bin/varnishd/mgt_child.c
varnish-cache/bin/varnishd/varnishd.c

index e67101d192f1ed275127c6c8d223d6c509fa8370..15869c708214ce3220a2f158fddfb5bc2d97b7eb 100644 (file)
@@ -113,7 +113,7 @@ child_main(void)
        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);
index 8b8d6f6f0b79650d2ae0d19d7e6c20b0d6a450dc..a83109e59b9196376df830d6f2596d67e1c477eb 100644 (file)
@@ -123,8 +123,25 @@ excb(struct bufferevent *bev, short what, void *arg)
        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_setup(int fdr, int fdw, int ver, struct cli_proto *cli_proto)
 
        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);
 
index dae3eee25c9fcf6c70ae8f0bef1d99837ad43e1c..ed33a46da805884777b8843e816cd15dd9d36ece 100644 (file)
@@ -11,7 +11,7 @@ struct cli {
        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);
index 9b6a7063c0f9a0d8041a95994c4290d4225e19b5..c4b855eaa8549acbc2833facaf614e8305e10a6b 100644 (file)
@@ -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);
index a581fc785594a96aec2e79395aeff2b44dd07a96..e0ca92a29c1add6a60ce274d25c2aba5e2abb345 100644 (file)
@@ -246,6 +246,7 @@ start_child(void)
        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);
 }
 
index f2c9e482145dbf261de36a5cedbd1ec2f490e4b2..5ad81825c35d4b54e8f7b19ca942ea12d47e2644 100644 (file)
@@ -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 @@ testme(void)
        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);