Skip to content

Commit

Permalink
fixup! http: server callback API simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Jan 6, 2025
1 parent 2ff83eb commit 126984c
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/supplemental/websocket/websocket.c
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]>
//
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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) ||
Expand All @@ -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);
}

Expand Down

0 comments on commit 126984c

Please sign in to comment.