aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-12-19 10:21:54 -0800
committerGarrett D'Amore <garrett@damore.org>2020-12-19 12:50:05 -0800
commitd12e169c1e733b255d146847ed57037b74681285 (patch)
treee4a59142a6cf097dfdda8620635f173f53db9e7a /src/supplemental
parent2033988343bce413763d3e9664e3e8372da48591 (diff)
downloadnng-d12e169c1e733b255d146847ed57037b74681285.tar.gz
nng-d12e169c1e733b255d146847ed57037b74681285.tar.bz2
nng-d12e169c1e733b255d146847ed57037b74681285.zip
fixes #1372 nni_reap could be smaller
Diffstat (limited to 'src/supplemental')
-rw-r--r--src/supplemental/http/http_server.c38
-rw-r--r--src/supplemental/tls/tls_common.c14
-rw-r--r--src/supplemental/websocket/websocket.c11
3 files changed, 44 insertions, 19 deletions
diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c
index e1f51e52..1ebc8907 100644
--- a/src/supplemental/http/http_server.c
+++ b/src/supplemental/http/http_server.c
@@ -64,7 +64,7 @@ typedef struct http_sconn {
nni_aio * rxaio;
nni_aio * txaio;
nni_aio * txdataio;
- nni_reap_item reap;
+ nni_reap_node reap;
} http_sconn;
typedef struct http_error {
@@ -90,7 +90,21 @@ struct nng_http_server {
char * hostname;
nni_list errors;
nni_mtx errors_mtx;
- nni_reap_item reap;
+ nni_reap_node reap;
+};
+
+static void http_sc_reap(void *);
+
+static nni_reap_list http_sc_reap_list = {
+ .rl_offset = offsetof(http_sconn, reap),
+ .rl_func = http_sc_reap,
+};
+
+static void http_server_fini(nni_http_server *);
+
+static nni_reap_list http_server_reap_list = {
+ .rl_offset = offsetof(nni_http_server, reap),
+ .rl_func = (nni_cb) http_server_fini,
};
int
@@ -269,7 +283,7 @@ static nni_list http_servers;
static nni_mtx http_servers_lk;
static void
-http_sconn_reap(void *arg)
+http_sc_reap(void *arg)
{
http_sconn * sc = arg;
nni_http_server *s = sc->server;
@@ -304,7 +318,7 @@ http_sconn_reap(void *arg)
}
static void
-http_sconn_close_locked(http_sconn *sc)
+http_sc_close_locked(http_sconn *sc)
{
nni_http_conn *conn;
@@ -322,7 +336,7 @@ http_sconn_close_locked(http_sconn *sc)
if ((conn = sc->conn) != NULL) {
nni_http_conn_close(conn);
}
- nni_reap(&sc->reap, http_sconn_reap, sc);
+ nni_reap(&http_sc_reap_list, sc);
}
static void
@@ -332,7 +346,7 @@ http_sconn_close(http_sconn *sc)
s = sc->server;
nni_mtx_lock(&s->mtx);
- http_sconn_close_locked(sc);
+ http_sc_close_locked(sc);
nni_mtx_unlock(&s->mtx);
}
@@ -704,7 +718,7 @@ http_sconn_rxdone(void *arg)
if ((h->getbody) &&
((cls = nni_http_req_get_header(req, "Content-Length")) != NULL)) {
uint64_t len;
- char *end;
+ char * end;
len = strtoull(cls, &end, 10);
if ((end == NULL) || (*end != '\0') || (len > h->maxbody)) {
@@ -900,9 +914,9 @@ http_server_fini(nni_http_server *s)
nni_mtx_lock(&s->mtx);
if (!nni_list_empty(&s->conns)) {
- // Try to reap later, after the sconns are done reaping.
- // (Note, sconns will all have been closed already.)
- nni_reap(&s->reap, (nni_cb) http_server_fini, s);
+ // Try to reap later, after the connections are done reaping.
+ // (Note, connections will all have been closed already.)
+ nni_reap(&http_server_reap_list, s);
nni_mtx_unlock(&s->mtx);
return;
}
@@ -1059,7 +1073,7 @@ http_server_stop(nni_http_server *s)
// Stopping the server is a hard stop -- it aborts any work
// being done by clients. (No graceful shutdown).
NNI_LIST_FOREACH (&s->conns, sc) {
- http_sconn_close_locked(sc);
+ http_sc_close_locked(sc);
}
while (!nni_list_empty(&s->conns)) {
@@ -1904,7 +1918,7 @@ nni_http_server_fini(nni_http_server *s)
http_server_stop(s);
nni_mtx_unlock(&s->mtx);
nni_list_remove(&http_servers, s);
- nni_reap(&s->reap, (nni_cb) http_server_fini, s);
+ nni_reap(&http_server_reap_list, s);
}
nni_mtx_unlock(&http_servers_lk);
}
diff --git a/src/supplemental/tls/tls_common.c b/src/supplemental/tls/tls_common.c
index e23fb4d8..6e5e6757 100644
--- a/src/supplemental/tls/tls_common.c
+++ b/src/supplemental/tls/tls_common.c
@@ -78,7 +78,7 @@ typedef struct {
size_t tcp_send_len;
size_t tcp_send_head;
size_t tcp_send_tail;
- struct nni_reap_item reap;
+ nni_reap_node reap;
// ... engine connection data follows
} tls_conn;
@@ -89,10 +89,16 @@ static void tls_do_send(tls_conn *);
static void tls_do_recv(tls_conn *);
static void tls_tcp_send_start(tls_conn *);
static void tls_free(void *);
+static void tls_reap(void *);
static int tls_alloc(tls_conn **, nng_tls_config *, nng_aio *);
static int tls_start(tls_conn *, nng_stream *);
static void tls_tcp_error(tls_conn *, int);
+static nni_reap_list tls_conn_reap_list = {
+ .rl_offset = offsetof(tls_conn, reap),
+ .rl_func = tls_reap,
+};
+
typedef struct {
nng_stream_dialer ops;
nng_stream_dialer *d; // underlying TCP dialer
@@ -331,8 +337,7 @@ static const nni_option tls_dialer_opts[] = {
};
static int
-tls_dialer_get(
- void *arg, const char *name, void *buf, size_t *szp, nni_type t)
+tls_dialer_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tls_dialer *d = arg;
int rv;
@@ -873,7 +878,7 @@ tls_free(void *arg)
{
tls_conn *conn = arg;
- nni_reap(&conn->reap, tls_reap, conn);
+ nni_reap(&tls_conn_reap_list, conn);
}
static int
@@ -1501,6 +1506,7 @@ nni_tls_sys_init(void)
void
nni_tls_sys_fini(void)
{
+ nni_reap_drain();
NNG_TLS_ENGINE_FINI();
}
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c
index 20adf626..daf1be13 100644
--- a/src/supplemental/websocket/websocket.c
+++ b/src/supplemental/websocket/websocket.c
@@ -47,7 +47,7 @@ typedef struct ws_header {
struct nni_ws {
nng_stream ops;
nni_list_node node;
- nni_reap_item reap;
+ nni_reap_node reap;
bool server;
bool closed;
bool ready;
@@ -1251,10 +1251,15 @@ ws_fini(void *arg)
NNI_FREE_STRUCT(ws);
}
+static nni_reap_list ws_reap_list = {
+ .rl_offset = offsetof(nni_ws, reap),
+ .rl_func = ws_fini,
+};
+
static void
ws_reap(nni_ws *ws)
{
- nni_reap(&ws->reap, ws_fini, ws);
+ nni_reap(&ws_reap_list, ws);
}
static void
@@ -2656,7 +2661,7 @@ static void
ws_str_free(void *arg)
{
nni_ws *ws = arg;
- nni_reap(&ws->reap, ws_fini, ws);
+ ws_reap(ws);
}
static void