|
17 | 17 |
|
18 | 18 | #include <aws/http/http.h> |
19 | 19 |
|
20 | | -struct aws_channel_handler; |
21 | | -struct aws_http_header; |
22 | | - |
23 | 20 | /* TODO: Document lifetime stuff */ |
| 21 | +/* TODO: Should shutdown callback fire when it's a midchannel handler? */ |
24 | 22 | /* TODO: Document CLOSE frame behavior (when auto-sent during close, when auto-closed) */ |
25 | 23 | /* TODO: Document auto-pong behavior */ |
26 | 24 |
|
@@ -236,25 +234,15 @@ bool aws_websocket_is_data_frame(uint8_t opcode); |
236 | 234 | AWS_HTTP_API |
237 | 235 | int aws_websocket_client_connect(const struct aws_websocket_client_connection_options *options); |
238 | 236 |
|
239 | | -/* TODO: Require all users to manually grab a hold? Http doesn't work like that... */ |
240 | | -/* TODO: should the last release trigger a shutdown automatically? http does that, channel doesn't. */ |
241 | | - |
242 | | -/** |
243 | | - * Ensure that the websocket cannot be destroyed until aws_websocket_release_hold() is called. |
244 | | - * The websocket might still shutdown/close, but the public API will not crash when this websocket pointer is used. |
245 | | - * If acquire_hold() is never called, the websocket is destroyed when its channel its channel is destroyed. |
246 | | - * This function may be called from any thread. |
247 | | - */ |
248 | | -AWS_HTTP_API |
249 | | -void aws_websocket_acquire_hold(struct aws_websocket *websocket); |
250 | | - |
251 | 237 | /** |
252 | | - * See aws_websocket_acquire_hold(). |
253 | | - * The websocket will shut itself down when the last hold is released. |
| 238 | + * Users must release the websocket when they are done with it (unless it's been converted to a mid-channel handler). |
| 239 | + * The websocket's memory cannot be reclaimed until this is done. |
| 240 | + * If the websocket connection was not already shutting down, it will be shut down. |
| 241 | + * Callbacks may continue firing after this is called, with "shutdown" being the final callback. |
254 | 242 | * This function may be called from any thread. |
255 | 243 | */ |
256 | 244 | AWS_HTTP_API |
257 | | -void aws_websocket_release_hold(struct aws_websocket *websocket); |
| 245 | +void aws_websocket_release(struct aws_websocket *websocket); |
258 | 246 |
|
259 | 247 | /** |
260 | 248 | * Close the websocket connection. |
@@ -285,11 +273,29 @@ int aws_websocket_send_frame(struct aws_websocket *websocket, const struct aws_w |
285 | 273 | AWS_HTTP_API |
286 | 274 | void aws_websocket_increment_read_window(struct aws_websocket *websocket, size_t size); |
287 | 275 |
|
288 | | -/* WIP */ |
| 276 | +/** |
| 277 | + * Convert the websocket into a mid-channel handler. |
| 278 | + * The websocket will stop being usable via its public API and become just another handler in the channel. |
| 279 | + * The caller will likely install a channel handler to the right. |
| 280 | + * This must not be called in the middle of an incoming frame (between "frame begin" and "frame complete" callbacks). |
| 281 | + * This MUST be called from the websocket's thread. |
| 282 | + * |
| 283 | + * If successful, the channel that the websocket belongs to is returned and: |
| 284 | + * - The websocket will ignore all further calls to aws_websocket_X() functions. |
| 285 | + * - The websocket will no longer invoke any "incoming frame" callbacks. |
| 286 | + * - There is no need to invoke aws_websocket_release(), the websocket will be destroyed when the channel is destroyed. |
| 287 | + * The caller should acquire a hold on the channel if they need to prevent its destruction. |
| 288 | + * - aws_io_messages written by a downstream handler will be wrapped in binary data frames and sent upstream. |
| 289 | + * The data may be split/combined as it is sent along. |
| 290 | + * - aws_io_messages read from upstream handlers will be scanned for binary data frames. |
| 291 | + * The payloads of these frames will be sent downstream. |
| 292 | + * The payloads may be split/combined as they are sent along. |
| 293 | + * - An incoming close frame will automatically result in channel-shutdown. |
| 294 | + * |
| 295 | + * If unsuccessful, NULL is returned and the websocket is unchanged. |
| 296 | + */ |
289 | 297 | AWS_HTTP_API |
290 | | -int aws_websocket_install_channel_handler_to_right( |
291 | | - struct aws_websocket *websocket, |
292 | | - struct aws_channel_handler *right_handler); |
| 298 | +struct aws_channel *aws_websocket_convert_to_midchannel_handler(struct aws_websocket *websocket); |
293 | 299 |
|
294 | 300 | AWS_EXTERN_C_END |
295 | 301 |
|
|
0 commit comments