validate close cb on server when client connection closes
authorNiels Provos <provos@gmail.com>
Sun, 14 Feb 2010 01:04:17 +0000 (17:04 -0800)
committerNiels Provos <provos@gmail.com>
Sun, 14 Feb 2010 01:04:17 +0000 (17:04 -0800)
test/regress_http.c

index 3fd2d6520711d602c785fcc9cb37766d2e8a9e0d..4f83b774ee2bba7467d4c1fba4acaa0577334032 100644 (file)
@@ -2523,6 +2523,7 @@ struct terminate_state {
        struct evhttp_request *req;
        struct bufferevent *bev;
        int fd;
+       int gotclosecb: 1;
 } terminate_state;
 
 static void
@@ -2548,12 +2549,24 @@ terminate_chunked_trickle_cb(evutil_socket_t fd, short events, void *arg)
        event_once(-1, EV_TIMEOUT, terminate_chunked_trickle_cb, arg, &tv);
 }
 
+static void
+terminate_chunked_close_cb(struct evhttp_connection *evcon, void *arg)
+{
+       struct terminate_state *state = arg;
+       state->gotclosecb = 1;
+}
+
 static void
 terminate_chunked_cb(struct evhttp_request *req, void *arg)
 {
        struct terminate_state *state = arg;
        struct timeval tv;
 
+       /* we want to know if this connection closes on us */
+       evhttp_connection_set_closecb(
+               evhttp_request_get_connection(req),
+               terminate_chunked_close_cb, arg);
+       
        state->req = req;
 
        evhttp_send_reply_start(req, HTTP_OK, "OK");
@@ -2603,6 +2616,7 @@ http_terminate_chunked_test(void)
 
        terminate_state.fd = fd;
        terminate_state.bev = bev;
+       terminate_state.gotclosecb = 0;
 
        /* first half of the http request */
        http_request =
@@ -2617,6 +2631,9 @@ http_terminate_chunked_test(void)
 
        event_dispatch();
 
+       if (terminate_state.gotclosecb == 0)
+               test_ok = 0;
+
  end:
        if (fd >= 0)
                EVUTIL_CLOSESOCKET(fd);