Skip to content

Commit 5400050

Browse files
authored
WebSocket ref-counts its HTTP request (#403)
The WebSocket wasn't using acquire()/release() ref-counting on its HTTP request, because this code was written before we realized ref-counting was a thing we needed to do. Also, correct a bunch of comments about old-fashioned lifetime management that don't apply now that we ref-count everything.
1 parent b27a25a commit 5400050

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

include/aws/http/connection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ struct aws_http_client_connection_options {
256256

257257
/**
258258
* Required.
259-
* Must outlive the connection.
259+
* The connection keeps the bootstrap alive via ref-counting.
260260
*/
261261
struct aws_client_bootstrap *bootstrap;
262262

@@ -279,8 +279,8 @@ struct aws_http_client_connection_options {
279279

280280
/**
281281
* Optional.
282-
* aws_http_client_connect() deep-copies all contents except the `aws_tls_ctx`,
283-
* which must outlive the the connection.
282+
* aws_http_client_connect() deep-copies all contents,
283+
* and keeps `aws_tls_ctx` alive via ref-counting.
284284
*/
285285
const struct aws_tls_connection_options *tls_options;
286286

include/aws/http/request_response.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ struct aws_http_make_request_options {
207207
/**
208208
* Definition for outgoing request.
209209
* Required.
210-
* This object must stay alive at least until on_complete is called.
210+
* The request will be kept alive via refcounting until the request completes.
211211
*/
212212
struct aws_http_message *request;
213213

include/aws/http/websocket.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct aws_websocket_client_connection_options {
132132

133133
/**
134134
* Required.
135-
* Must outlive the connection.
135+
* The connection keeps the bootstrap alive via ref-counting.
136136
*/
137137
struct aws_client_bootstrap *bootstrap;
138138

@@ -144,8 +144,8 @@ struct aws_websocket_client_connection_options {
144144

145145
/**
146146
* Optional.
147-
* aws_websocket_client_connect() deep-copies all contents except the `aws_tls_ctx`,
148-
* which must outlive the the connection.
147+
* aws_websocket_client_connect() deep-copies all contents,
148+
* and keeps the `aws_tls_ctx` alive via ref-counting.
149149
*/
150150
const struct aws_tls_connection_options *tls_options;
151151

@@ -169,7 +169,7 @@ struct aws_websocket_client_connection_options {
169169

170170
/**
171171
* Required.
172-
* The request must outlive the handshake process (it will be safe to release in on_connection_setup())
172+
* The request will be kept alive via ref-counting until the handshake completes.
173173
* Suggestion: create via aws_http_message_new_websocket_handshake_request()
174174
*
175175
* The method MUST be set to GET.

source/websocket_bootstrap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int aws_websocket_client_connect(const struct aws_websocket_client_connection_op
155155
ws_bootstrap->websocket_frame_begin_callback = options->on_incoming_frame_begin;
156156
ws_bootstrap->websocket_frame_payload_callback = options->on_incoming_frame_payload;
157157
ws_bootstrap->websocket_frame_complete_callback = options->on_incoming_frame_complete;
158-
ws_bootstrap->handshake_request = options->handshake_request;
158+
ws_bootstrap->handshake_request = aws_http_message_acquire(options->handshake_request);
159159
ws_bootstrap->response_status = AWS_HTTP_STATUS_CODE_UNKNOWN;
160160

161161
/* Pre-allocate space for response headers */
@@ -242,6 +242,7 @@ static void s_ws_bootstrap_destroy(struct aws_websocket_client_bootstrap *ws_boo
242242
return;
243243
}
244244

245+
aws_http_message_release(ws_bootstrap->handshake_request);
245246
aws_array_list_clean_up(&ws_bootstrap->response_headers);
246247
aws_byte_buf_clean_up(&ws_bootstrap->response_storage);
247248

0 commit comments

Comments
 (0)