diff options
Diffstat (limited to 'src/supplemental')
| -rw-r--r-- | src/supplemental/http/http_server.c | 10 |
1 files changed, 10 insertions, 0 deletions
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 |
