From 04974cc135ca461d8fce50fa8def0ca5fe13b101 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 17 Nov 2020 22:14:09 -0800 Subject: fixes #1200 Shouldn't nng_http_server_stop be synchronous? --- src/supplemental/http/http_server.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index 6fad99c2..33e49c09 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -82,6 +82,7 @@ struct nng_http_server { nni_list handlers; nni_list conns; nni_mtx mtx; + nni_cv cv; bool closed; nni_aio * accaio; nng_stream_listener *listener; @@ -294,6 +295,9 @@ http_sconn_reap(void *arg) if (nni_list_node_active(&sc->node)) { nni_list_remove(&s->conns, sc); } + if (nni_list_empty(&s->conns)) { + nni_cv_wake(&s->cv); + } nni_mtx_unlock(&s->mtx); NNI_FREE_STRUCT(sc); @@ -916,6 +920,7 @@ http_server_fini(nni_http_server *s) nni_mtx_fini(&s->errors_mtx); nni_aio_free(s->accaio); + nni_cv_fini(&s->cv); nni_mtx_fini(&s->mtx); nni_strfree(s->hostname); NNI_FREE_STRUCT(s); @@ -957,6 +962,7 @@ http_server_init(nni_http_server **serverp, const nni_url *url) } nni_mtx_init(&s->mtx); nni_mtx_init(&s->errors_mtx); + nni_cv_init(&s->cv, &s->mtx); NNI_LIST_INIT(&s->handlers, nni_http_handler, node); NNI_LIST_INIT(&s->conns, http_sconn, node); @@ -1069,6 +1075,10 @@ http_server_stop(nni_http_server *s) NNI_LIST_FOREACH (&s->conns, sc) { http_sconn_close_locked(sc); } + + while (!nni_list_empty(&s->conns)) { + nni_cv_wait(&s->cv); + } } void -- cgit v1.2.3-70-g09d2