Commit 1f0e19d7 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk@96 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 9e5e4a67
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......@@ -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);
......
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment