diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-11-10 01:00:30 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-11-10 01:00:30 -0800 |
| commit | e10f53cbaf9011e77044822080db134e1bd8a0fd (patch) | |
| tree | b27ffa0f4c4b6686002429c7766eb260b16409b7 /src | |
| parent | 34b363ce101ddc03c74fb1f002e587d2315420c3 (diff) | |
| download | nng-e10f53cbaf9011e77044822080db134e1bd8a0fd.tar.gz nng-e10f53cbaf9011e77044822080db134e1bd8a0fd.tar.bz2 nng-e10f53cbaf9011e77044822080db134e1bd8a0fd.zip | |
fixes #1337 nni aio user data could be removed
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/aio.c | 17 | ||||
| -rw-r--r-- | src/core/aio.h | 4 | ||||
| -rw-r--r-- | src/supplemental/http/http_conn.c | 47 | ||||
| -rw-r--r-- | src/supplemental/http/http_server.c | 9 | ||||
| -rw-r--r-- | src/supplemental/websocket/websocket.c | 5 |
5 files changed, 30 insertions, 52 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index 676199a5..1a8739e4 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -222,23 +222,6 @@ nni_aio_get_msg(nni_aio *aio) } void -nni_aio_set_data(nni_aio *aio, unsigned index, void *data) -{ - if (index < NNI_NUM_ELEMENTS(aio->a_user_data)) { - aio->a_user_data[index] = data; - } -} - -void * -nni_aio_get_data(nni_aio *aio, unsigned index) -{ - if (index < NNI_NUM_ELEMENTS(aio->a_user_data)) { - return (aio->a_user_data[index]); - } - return (NULL); -} - -void nni_aio_set_input(nni_aio *aio, unsigned index, void *data) { if (index < NNI_NUM_ELEMENTS(aio->a_inputs)) { diff --git a/src/core/aio.h b/src/core/aio.h index 7e6a1741..a46c1feb 100644 --- a/src/core/aio.h +++ b/src/core/aio.h @@ -194,10 +194,6 @@ struct nng_aio { // Message operations. nni_msg *a_msg; - // User scratch data. Consumers may store values here, which - // must be preserved by providers and the framework. - void *a_user_data[2]; - // Operation inputs & outputs. Up to 4 inputs and 4 outputs may be // specified. The semantics of these will vary, and depend on the // specific operation. diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index 583f5eee..4b0c81c0 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2019 Devolutions <info@devolutions.net> // @@ -65,6 +65,7 @@ struct nng_http_conn { size_t rd_get; size_t rd_put; size_t rd_bufsz; + bool rd_buffered; }; void @@ -135,7 +136,7 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) int rv; bool raw = false; nni_iov *iov; - unsigned niov; + unsigned nio; rbuf += conn->rd_get; @@ -143,8 +144,8 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) case HTTP_RD_RAW: raw = true; // FALLTHROUGH case HTTP_RD_FULL: - nni_aio_get_iov(aio, &niov, &iov); - while ((niov != 0) && (cnt != 0)) { + nni_aio_get_iov(aio, &nio, &iov); + while ((nio != 0) && (cnt != 0)) { // Pull up data from the buffer if possible. n = iov[0].iov_len; if (n > cnt) { @@ -159,14 +160,14 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) cnt -= n; if (iov[0].iov_len == 0) { - niov--; + nio--; iov = &iov[1]; } } - nni_aio_set_iov(aio, niov, iov); + nni_aio_set_iov(aio, nio, iov); - if ((niov == 0) || (raw && (nni_aio_count(aio) != 0))) { + if ((nio == 0) || (raw && (nni_aio_count(aio) != 0))) { // Finished the read. (We are finished if we either // got *all* the data, or we got *some* data for // a raw read.) @@ -177,8 +178,8 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) // (Note that we get here if we either have not completed // a full transaction on a FULL read, or were not even able // to get *any* data for a partial RAW read.) - nni_aio_set_data(conn->rd_aio, 1, NULL); - nni_aio_set_iov(conn->rd_aio, niov, iov); + conn->rd_buffered = false; + nni_aio_set_iov(conn->rd_aio, nio, iov); nng_stream_recv(conn->sock, conn->rd_aio); return (NNG_EAGAIN); @@ -191,10 +192,10 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) } if (rv == NNG_EAGAIN) { nni_iov iov1; - iov1.iov_buf = conn->rd_buf + conn->rd_put; - iov1.iov_len = conn->rd_bufsz - conn->rd_put; + iov1.iov_buf = conn->rd_buf + conn->rd_put; + iov1.iov_len = conn->rd_bufsz - conn->rd_put; + conn->rd_buffered = true; nni_aio_set_iov(conn->rd_aio, 1, &iov1); - nni_aio_set_data(conn->rd_aio, 1, aio); nng_stream_recv(conn->sock, conn->rd_aio); } return (rv); @@ -208,10 +209,10 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) } if (rv == NNG_EAGAIN) { nni_iov iov1; - iov1.iov_buf = conn->rd_buf + conn->rd_put; - iov1.iov_len = conn->rd_bufsz - conn->rd_put; + iov1.iov_buf = conn->rd_buf + conn->rd_put; + iov1.iov_len = conn->rd_bufsz - conn->rd_put; + conn->rd_buffered = true; nni_aio_set_iov(conn->rd_aio, 1, &iov1); - nni_aio_set_data(conn->rd_aio, 1, aio); nng_stream_recv(conn->sock, conn->rd_aio); } return (rv); @@ -225,10 +226,10 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio) } if (rv == NNG_EAGAIN) { nni_iov iov1; - iov1.iov_buf = conn->rd_buf + conn->rd_put; - iov1.iov_len = conn->rd_bufsz - conn->rd_put; + iov1.iov_buf = conn->rd_buf + conn->rd_put; + iov1.iov_len = conn->rd_bufsz - conn->rd_put; + conn->rd_buffered = true; nni_aio_set_iov(conn->rd_aio, 1, &iov1); - nni_aio_set_data(conn->rd_aio, 1, aio); nng_stream_recv(conn->sock, conn->rd_aio); } return (rv); @@ -299,7 +300,7 @@ http_rd_cb(void *arg) cnt = nni_aio_count(aio); // If we were reading into the buffer, then advance location(s). - if ((uaio = nni_aio_get_data(aio, 1)) != NULL) { + if (conn->rd_buffered) { conn->rd_put += cnt; NNI_ASSERT(conn->rd_put <= conn->rd_bufsz); http_rd_start(conn); @@ -602,22 +603,22 @@ nni_http_write_res(nni_http_conn *conn, nni_http_res *res, nni_aio *aio) void * data; size_t size; nni_iov iov[2]; - int niov; + int nio; if ((rv = nni_http_res_get_buf(res, &buf, &bufsz)) != 0) { nni_aio_finish_error(aio, rv); return; } nni_http_res_get_data(res, &data, &size); - niov = 1; + nio = 1; iov[0].iov_len = bufsz; iov[0].iov_buf = buf; if ((size > 0) && (data != NULL)) { - niov++; + nio++; iov[1].iov_len = size; iov[1].iov_buf = data; } - nni_aio_set_iov(aio, niov, iov); + nni_aio_set_iov(aio, nio, iov); SET_WR_FLAVOR(aio, HTTP_WR_RES); diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index caa06b3d..d43dd888 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -56,6 +56,7 @@ typedef struct http_sconn { nni_http_req * req; nni_http_res * res; nni_http_handler *handler; // set if we deferred to read body + nni_http_handler *release; // set if we dispatched handler bool close; bool closed; bool finished; @@ -724,6 +725,7 @@ http_sconn_rxdone(void *arg) } finish: + sc->release = h; sc->handler = NULL; nni_aio_set_input(sc->cbaio, 0, sc->req); nni_aio_set_input(sc->cbaio, 1, h); @@ -734,7 +736,6 @@ finish: nni_mtx_unlock(&s->mtx); return; } - nni_aio_set_data(sc->cbaio, 1, h); // Set a reference -- this because the callback may be running // asynchronously even after it gets removed from the server. nni_atomic_inc64(&h->ref); @@ -754,10 +755,8 @@ http_sconn_cbdone(void *arg) // Get the handler. It may be set regardless of success or // failure. Clear it, and drop our reference, since we're // done with the handler for now. - h = nni_aio_get_data(aio, 1); - nni_aio_set_data(aio, 1, NULL); - - if (h != NULL) { + if ((h = sc->release) != NULL) { + sc->release = NULL; nni_http_handler_fini(h); } diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index 1cc03b45..e65fc24f 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -1260,8 +1260,7 @@ ws_reap(nni_ws *ws) static void ws_http_cb_listener(nni_ws *ws, nni_aio *aio) { - nni_ws_listener *l; - l = nni_aio_get_data(aio, 0); + nni_ws_listener *l = ws->listener; nni_mtx_lock(&l->mtx); nni_list_remove(&l->reply, ws); @@ -1646,9 +1645,9 @@ ws_handler(nni_aio *aio) ws->isstream = l->isstream; ws->recv_text = l->recv_text; ws->send_text = l->send_text; + ws->listener = l; nni_list_append(&l->reply, ws); - nni_aio_set_data(ws->httpaio, 0, l); nni_http_write_res(conn, res, ws->httpaio); (void) nni_http_hijack(conn); nni_aio_set_output(aio, 0, NULL); |
