-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! http: server callback API simplified
- Loading branch information
Showing
1 changed file
with
8 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright 2024 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2025 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2018 Capitar IT Group BV <[email protected]> | ||
// Copyright 2019 Devolutions <[email protected]> | ||
// | ||
|
@@ -1240,9 +1240,7 @@ ws_fini(void *arg) | |
|
||
nni_mtx_unlock(&ws->mtx); | ||
|
||
if (ws->http) { | ||
nni_http_conn_fini(ws->http); | ||
} | ||
nni_http_conn_fini(ws->http); | ||
|
||
nni_strfree(ws->reqhdrs); | ||
nni_strfree(ws->reshdrs); | ||
|
@@ -2147,7 +2145,6 @@ ws_conn_cb(void *arg) | |
nni_ws_dialer *d; | ||
nni_ws *ws; | ||
nni_aio *uaio; | ||
nni_http_conn *http; | ||
nni_http_req *req = NULL; | ||
int rv; | ||
uint8_t raw[16]; | ||
|
@@ -2179,13 +2176,12 @@ ws_conn_cb(void *arg) | |
return; | ||
} | ||
|
||
ws->http = nni_aio_get_output(&ws->connaio, 0); | ||
nni_mtx_lock(&ws->mtx); | ||
uaio = ws->useraio; | ||
http = nni_aio_get_output(&ws->connaio, 0); | ||
nni_aio_set_output(&ws->connaio, 0, NULL); | ||
if (uaio == NULL) { | ||
// This request was canceled for some reason. | ||
nni_http_conn_fini(http); | ||
nni_mtx_unlock(&ws->mtx); | ||
ws_reap(ws); | ||
return; | ||
|
@@ -2197,8 +2193,10 @@ ws_conn_cb(void *arg) | |
nni_base64_encode(raw, 16, wskey, 24); | ||
wskey[24] = '\0'; | ||
|
||
req = nni_http_conn_req(ws->http); | ||
|
||
#define SETH(h, v) nni_http_req_set_header(req, h, v) | ||
if ((rv != 0) || ((rv = nni_http_req_alloc(&req, d->url)) != 0) || | ||
if ((rv != 0) || ((rv = nni_http_req_set_url(req, d->url)) != 0) || | ||
((rv = SETH("Upgrade", "websocket")) != 0) || | ||
((rv = SETH("Connection", "Upgrade")) != 0) || | ||
((rv = SETH("Sec-WebSocket-Key", wskey)) != 0) || | ||
|
@@ -2218,22 +2216,15 @@ ws_conn_cb(void *arg) | |
} | ||
#undef SETH | ||
|
||
ws->http = http; | ||
ws->req = req; | ||
ws->req = req; | ||
|
||
nni_http_write_req(http, req, &ws->httpaio); | ||
nni_http_write_req(ws->http, req, &ws->httpaio); | ||
nni_mtx_unlock(&ws->mtx); | ||
return; | ||
|
||
err: | ||
nni_aio_finish_error(uaio, rv); | ||
nni_mtx_unlock(&ws->mtx); | ||
if (http != NULL) { | ||
nni_http_conn_fini(http); | ||
} | ||
if (req != NULL) { | ||
nni_http_req_free(req); | ||
} | ||
ws_reap(ws); | ||
} | ||
|
||
|