From: phk Date: Mon, 3 Apr 2006 11:03:28 +0000 (+0000) Subject: How I wish people would think more ahead when writing libraries like X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29baa06bca1831d04d14a5e122a191be341c8d30;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@96 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index e67101d1..15869c70 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -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); diff --git a/varnish-cache/bin/varnishd/cli_event.c b/varnish-cache/bin/varnishd/cli_event.c index 8b8d6f6f..a83109e5 100644 --- a/varnish-cache/bin/varnishd/cli_event.c +++ b/varnish-cache/bin/varnishd/cli_event.c @@ -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); diff --git a/varnish-cache/bin/varnishd/cli_event.h b/varnish-cache/bin/varnishd/cli_event.h index dae3eee2..ed33a46d 100644 --- a/varnish-cache/bin/varnishd/cli_event.h +++ b/varnish-cache/bin/varnishd/cli_event.h @@ -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); diff --git a/varnish-cache/bin/varnishd/mgt.h b/varnish-cache/bin/varnishd/mgt.h index 9b6a7063..c4b855ea 100644 --- a/varnish-cache/bin/varnishd/mgt.h +++ b/varnish-cache/bin/varnishd/mgt.h @@ -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); diff --git a/varnish-cache/bin/varnishd/mgt_child.c b/varnish-cache/bin/varnishd/mgt_child.c index a581fc78..e0ca92a2 100644 --- a/varnish-cache/bin/varnishd/mgt_child.c +++ b/varnish-cache/bin/varnishd/mgt_child.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index f2c9e482..5ad81825 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -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);