summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-17 22:14:09 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-17 22:14:09 -0800
commit04974cc135ca461d8fce50fa8def0ca5fe13b101 (patch)
treee13352fcdf48aa96e5d7ef769b6af63c8986c93b
parent47754eff45271d674fe6d347be82d6755195e8ce (diff)
downloadnng-04974cc135ca461d8fce50fa8def0ca5fe13b101.tar.gz
nng-04974cc135ca461d8fce50fa8def0ca5fe13b101.tar.bz2
nng-04974cc135ca461d8fce50fa8def0ca5fe13b101.zip
fixes #1200 Shouldn't nng_http_server_stop be synchronous?
-rw-r--r--src/supplemental/http/http_server.c10
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