Fix pubsub test when compiled w/ libevent 2.1.x
authorOleksandr Senkovych <bjsenya@gmail.com>
Sun, 26 Aug 2018 12:30:36 +0000 (13:30 +0100)
committerAndrii Senkovych <andrii@senkovych.com>
Sun, 26 Aug 2018 12:30:36 +0000 (13:30 +0100)
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

tests/pubsub.c

index f4a3451ffe8e94c85052cb959a7d632b63173104..668147382d11c6376cfa3b12c53ac94d5b151d5e 100644 (file)
@@ -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);
 }