Skip to content

Commit 64aa5fb

Browse files
authored
Encoder revamp (#202)
### Summary: The existing encoder was **not** streaming. It would error if it didn't have enough space, but there was no way to know how much space it would need. We couldn't just try to re-encode the frame again when more space was available, because header-encoding mutates the HPACK state. Now we have a "partially" streaming encoder. Most frames are pre-encoded, and we stream them into the available buffers. Headers and Data frames, which may need to split their payload across multiple frames, know how to do so. ### Details - `aws_h2_frame` is a proper base class: - Previously, each specific frame type had its own init()/encode()/clean_up(). Now it's heap allocated and has vtable for encode()/destroy() - Simple frame types (most) make use of the `aws_h2_frame_prebuilt` type. - The entire frame is pre-encoded. - We stream the pre-encoded frame into the available space of an aws_io_message. - Remove "continuation" `aws_h2_frame` type. - Instead, the "headers" and "push promise" `aws_h2_frame` types will split their payload across CONTINUATION frames if necessary during encoding. - Remove "data" `aws_h2_frame` type. - Instead, the encoder has a special function that takes a body-stream and writes a DATA frame immediately. - There are lots of differences in how the connection deals with DATA vs every other frame type, so it didn't make sense for it to be a proper `aws_h2_frame` type. - HPACK encoding will grow the output buffer if necessary. - This was the simpler than building a fully "streaming" encoder. - HEADERS frame encoding is therefore 2 stage. - First, do HPACK encoding to separate buffer. - Then, split that payload across multiple HEADERS/CONTINUATION frames as necessary. - Moved logic for encoding the header-block into hpack.c. Previously a bunch of that logic was in h2_frames.c. All this code was changing anyway. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2b83c3d commit 64aa5fb

File tree

17 files changed

+1850
-1622
lines changed

17 files changed

+1850
-1622
lines changed

include/aws/http/http.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ enum aws_http_log_subject {
6868
AWS_LS_HTTP_CONNECTION_MANAGER,
6969
AWS_LS_HTTP_WEBSOCKET,
7070
AWS_LS_HTTP_WEBSOCKET_SETUP,
71-
72-
AWS_LS_HTTP_FRAMES,
7371
};
7472

7573
enum aws_http_version {

include/aws/http/private/h2_connection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct aws_h2_connection {
5252
* Any stream in this list is also in the active_streams_map. */
5353
struct aws_linked_list outgoing_streams_list;
5454

55-
/* List using aws_h2_frame_base.node.
55+
/* List using aws_h2_frame.node.
5656
* Queues all frames (except DATA frames) for connection to send.
5757
* When queue is empty, then we send DATA frames from the outgoing_streams_list */
5858
struct aws_linked_list outgoing_frames_queue;
@@ -101,6 +101,6 @@ AWS_EXTERN_C_END
101101
* Frames are sent into FIFO order.
102102
* Do not enqueue DATA frames, these are sent by other means when the frame queue is empty.
103103
*/
104-
void aws_h2_connection_enqueue_outgoing_frame(struct aws_h2_connection *connection, struct aws_h2_frame_base *frame);
104+
void aws_h2_connection_enqueue_outgoing_frame(struct aws_h2_connection *connection, struct aws_h2_frame *frame);
105105

106106
#endif /* AWS_HTTP_H2_CONNECTION_H */

0 commit comments

Comments
 (0)