aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sp/transport/ws/ws_test.c13
-rw-r--r--src/supplemental/websocket/websocket.c12
-rw-r--r--src/supplemental/websocket/wssfile_test.c2
3 files changed, 18 insertions, 9 deletions
diff --git a/src/sp/transport/ws/ws_test.c b/src/sp/transport/ws/ws_test.c
index 7cbcd9d7..4a2b58c2 100644
--- a/src/sp/transport/ws/ws_test.c
+++ b/src/sp/transport/ws/ws_test.c
@@ -56,19 +56,16 @@ test_wild_card_port(void)
NUTS_OPEN(s5);
NUTS_OPEN(s6);
NUTS_PASS(nng_listen(s1, "ws://127.0.0.1:0/one", &l1, 0));
- NUTS_PASS(
- nng_listener_get_int(l1, NNG_OPT_TCP_BOUND_PORT, &port1));
+ NUTS_PASS(nng_listener_get_int(l1, NNG_OPT_TCP_BOUND_PORT, &port1));
NUTS_TRUE(port1 != 0);
snprintf(ws_url, sizeof(ws_url), "ws4://127.0.0.1:%d/two", port1);
NUTS_PASS(nng_listen(s2, ws_url, &l2, 0));
- NUTS_PASS(
- nng_listener_get_int(l2, NNG_OPT_TCP_BOUND_PORT, &port2));
+ NUTS_PASS(nng_listener_get_int(l2, NNG_OPT_TCP_BOUND_PORT, &port2));
NUTS_TRUE(port1 != 0);
NUTS_TRUE(port1 == port2);
// Now try a different wild card port.
NUTS_PASS(nng_listen(s3, "ws4://127.0.0.1:0/three", &l3, 0));
- NUTS_PASS(
- nng_listener_get_int(l3, NNG_OPT_TCP_BOUND_PORT, &port3));
+ NUTS_PASS(nng_listener_get_int(l3, NNG_OPT_TCP_BOUND_PORT, &port3));
NUTS_TRUE(port3 != 0);
NUTS_TRUE(port3 != port1);
@@ -147,7 +144,9 @@ test_ws_recv_max(void)
nng_socket s1;
nng_listener l;
size_t sz;
- char *addr;
+ char * addr;
+
+ memset(msg, 0, sizeof(msg)); // required to silence valgrind
NUTS_ADDR(addr, "ws");
NUTS_OPEN(s0);
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c
index daf1be13..416d968c 100644
--- a/src/supplemental/websocket/websocket.c
+++ b/src/supplemental/websocket/websocket.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
@@ -1510,6 +1510,12 @@ ws_handler(nni_aio *aio)
conn = nni_aio_get_input(aio, 2);
l = nni_http_handler_get_data(h);
+ nni_mtx_lock(&l->mtx);
+ if (l->closed) {
+ status = NNG_HTTP_STATUS_SERVICE_UNAVAILABLE;
+ goto err;
+ }
+
// Now check the headers, etc.
if (strcmp(nni_http_req_get_version(req), "HTTP/1.1") != 0) {
status = NNG_HTTP_STATUS_HTTP_VERSION_NOT_SUPP;
@@ -1609,6 +1615,7 @@ ws_handler(nni_aio *aio)
if (rv != 0) {
nni_http_res_free(res);
nni_aio_finish_error(aio, rv);
+ nni_mtx_unlock(&l->mtx);
return;
}
@@ -1625,6 +1632,7 @@ ws_handler(nni_aio *aio)
nni_http_req_free(req);
nni_aio_set_output(aio, 0, res);
nni_aio_finish(aio, 0, 0);
+ nni_mtx_unlock(&l->mtx);
return;
}
}
@@ -1657,6 +1665,7 @@ ws_handler(nni_aio *aio)
(void) nni_http_hijack(conn);
nni_aio_set_output(aio, 0, NULL);
nni_aio_finish(aio, 0, 0);
+ nni_mtx_unlock(&l->mtx);
return;
err:
@@ -1666,6 +1675,7 @@ err:
nni_aio_set_output(aio, 0, res);
nni_aio_finish(aio, 0, 0);
}
+ nni_mtx_unlock(&l->mtx);
}
static void
diff --git a/src/supplemental/websocket/wssfile_test.c b/src/supplemental/websocket/wssfile_test.c
index 59003123..ee7c8ffd 100644
--- a/src/supplemental/websocket/wssfile_test.c
+++ b/src/supplemental/websocket/wssfile_test.c
@@ -254,7 +254,7 @@ test_verify_works(void)
NUTS_PASS(nng_dialer_start(d, 0));
nng_msleep(100);
- NUTS_PASS(nng_send(s1, "hello", 6, 0));
+ NUTS_SEND(s1, "hello");
NUTS_PASS(nng_recvmsg(s2, &msg, 0));
NUTS_ASSERT(msg != NULL);
NUTS_TRUE(nng_msg_len(msg) == 6);