diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-01-05 16:46:03 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-01-06 13:58:07 -0800 |
| commit | f42d0c6ef956d119e8762a3ecda37886fa055637 (patch) | |
| tree | 1744a559dafafdfecd906608888bf0cb9f6c4d10 /src/supplemental/http/http_conn.c | |
| parent | bce6a79fc55852032e9d653b099a121353aaa238 (diff) | |
| download | nng-f42d0c6ef956d119e8762a3ecda37886fa055637.tar.gz nng-f42d0c6ef956d119e8762a3ecda37886fa055637.tar.bz2 nng-f42d0c6ef956d119e8762a3ecda37886fa055637.zip | |
http: server callback API simplified
This simplified API lets callbacks obtain the response from the
connection objection directly, and does not require the aio to carry
it as a parameter. Further, the request and response are both
stored inline in the connection, reducing allocations.
This is at present only for the server; the client will get a similar
set of changes.
Diffstat (limited to 'src/supplemental/http/http_conn.c')
| -rw-r--r-- | src/supplemental/http/http_conn.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index 912f2cc9..9ed882f1 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -63,6 +63,8 @@ struct nng_http_conn { size_t rd_bufsz; bool rd_buffered; + bool res_sent; + enum write_flavor wr_flavor; }; @@ -509,10 +511,13 @@ http_wr_submit(nni_http_conn *conn, nni_aio *aio, enum write_flavor flavor) } void -nni_http_read_req(nni_http_conn *conn, nni_http_req *req, nni_aio *aio) +nni_http_read_req(nni_http_conn *conn, nni_aio *aio) { - nni_aio_set_prov_data(aio, req); + nni_aio_set_prov_data(aio, &conn->req); + // clear the sent flag (used for the server) + conn->res_sent = false; + nni_http_req_reset(&conn->req); nni_mtx_lock(&conn->mtx); http_rd_submit(conn, aio, HTTP_RD_REQ); nni_mtx_unlock(&conn->mtx); @@ -590,16 +595,18 @@ nni_http_write_req(nni_http_conn *conn, nni_http_req *req, nni_aio *aio) } void -nni_http_write_res(nni_http_conn *conn, nni_http_res *res, nni_aio *aio) +nni_http_write_res(nni_http_conn *conn, nni_aio *aio) { - int rv; - void *buf; - size_t bufsz; - void *data; - size_t size; - nni_iov iov[2]; - int nio; - + int rv; + void *buf; + size_t bufsz; + void *data; + size_t size; + nni_iov iov[2]; + int nio; + nng_http_res *res = nng_http_conn_res(conn); + + conn->res_sent = true; if ((rv = nni_http_res_get_buf(res, &buf, &bufsz)) != 0) { nni_aio_finish_error(aio, rv); return; @@ -713,3 +720,10 @@ nni_http_conn_init(nni_http_conn **connp, nng_stream *stream) } return (rv); } + +// private to the HTTP framework, used on the server +bool +nni_http_conn_res_sent(nni_http_conn *conn) +{ + return (conn->res_sent); +} |
