From: Oleksandr Senkovych Date: Tue, 19 Nov 2019 08:28:46 +0000 (+0000) Subject: Fix pubsub test when compiled w/ libevent 2.1.x X-Git-Tag: archive/raspbian/0.1.4+dfsg-2+rpi1~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=322e0ea0114620512707cac8a859482b1caedfb4;p=webdis.git Fix pubsub test when compiled w/ libevent 2.1.x Bug: https://github.com/nicolasff/webdis/issues/149 Last-Update: 2018-08-25 The pubsub test hangs in the infinite loop due to changes in the libevent2.x compared to the previous version. This patch makes test pass again. Gbp-Pq: Name fix-test-new-libevent.patch --- diff --git a/tests/pubsub.c b/tests/pubsub.c index f4a3451..6681473 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -82,6 +82,23 @@ reader_http_request(struct cx *c, const char* buffer, const char *limit) { } } +/* + * prepare an event structure(s) + */ +void +cx_init(struct cx* c) +{ + if(c->read_fun) { /* attach callback for read. */ + event_set(&c->evr, c->fd, EV_READ, c->read_fun, c); + event_base_set(c->base, &c->evr); + } + + if(c->write_fun) { /* attach callback for write. */ + event_set(&c->evw, c->fd, EV_WRITE, c->write_fun, c); + event_base_set(c->base, &c->evw); + } +} + /** * (re)install connection in the event loop. */ @@ -89,16 +106,11 @@ void cx_install(struct cx *c) { if(c->read_fun) { /* attach callback for read. */ - event_set(&c->evr, c->fd, EV_READ, c->read_fun, c); - event_base_set(c->base, &c->evr); event_add(&c->evr, NULL); } if(c->write_fun) { /* attach callback for write. */ - event_set(&c->evw, c->fd, EV_WRITE, c->write_fun, c); - event_base_set(c->base, &c->evw); event_add(&c->evw, NULL); } - } /** @@ -160,6 +172,7 @@ reader_new(struct event_base *base, const char *host, short port, int total, int reader_http_request(c, c->http_request, "{\"SUBSCRIBE\":[\"subscribe\""); /* add to the event loop. */ + cx_init(c); cx_install(c); } @@ -209,6 +222,7 @@ writer_new(struct event_base *base, const char *host, short port, int chan) { sprintf(c->http_request, "GET /PUBLISH/chan:%d/hi HTTP/1.1\r\n\r\n", chan); reader_http_request(c, c->http_request, "{\"PUBLISH\":"); + cx_init(c); cx_install(c); }