Skip to content

Commit 0eace8e

Browse files
authored
Can create streams on h2 connections (#175)
1 parent 6c630a5 commit 0eace8e

File tree

9 files changed

+378
-83
lines changed

9 files changed

+378
-83
lines changed

include/aws/http/http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum aws_http_errors {
4848
AWS_ERROR_HTTP_CONNECTION_MANAGER_SHUTTING_DOWN,
4949
AWS_ERROR_HTTP_PROTOCOL_ERROR,
5050
AWS_ERROR_HTTP_STREAM_CLOSED,
51+
AWS_ERROR_HTTP_STREAM_IDS_EXHAUSTED,
5152
AWS_ERROR_HTTP_INVALID_FRAME_SIZE,
5253
AWS_ERROR_HTTP_COMPRESSION,
5354

include/aws/http/private/h2_connection.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,40 @@ struct aws_h2_decoder;
2727
struct aws_h2_connection {
2828
struct aws_http_connection base;
2929

30+
struct aws_channel_task cross_thread_work_task;
31+
3032
/* Only the event-loop thread may touch this data */
3133
struct {
3234
struct aws_h2_decoder *decoder;
3335
struct aws_h2_frame_encoder encoder;
36+
37+
/* True when reading/writing has stopped, whether due to errors or normal channel shutdown. */
38+
bool is_reading_stopped;
39+
bool is_writing_stopped;
40+
41+
/* Maps stream-id to aws_h2_frame* */
42+
struct aws_hash_table active_streams_map;
43+
3444
} thread_data;
3545

3646
/* Any thread may touch this data, but the lock must be held */
3747
struct {
3848
struct aws_mutex lock;
3949

50+
/* New `aws_h2_stream *` that haven't moved to `thread_data` yet */
51+
struct aws_linked_list pending_stream_list;
52+
4053
/* Refers to the next stream id to vend */
4154
uint32_t next_stream_id;
55+
56+
/* If non-zero, reason to immediately reject new streams. (ex: closing) */
57+
int new_stream_error_code;
58+
59+
bool is_cross_thread_work_task_scheduled;
60+
61+
/* For checking status from outside the event-loop thread. */
62+
bool is_open;
63+
4264
} synced_data;
4365
};
4466

@@ -54,9 +76,6 @@ struct aws_http_connection *aws_http_connection_new_http2_client(
5476
struct aws_allocator *allocator,
5577
size_t initial_window_size);
5678

57-
AWS_HTTP_API
58-
uint32_t aws_h2_connection_get_next_stream_id(struct aws_h2_connection *connection);
59-
6079
AWS_EXTERN_C_END
6180

6281
#endif /* AWS_HTTP_H2_CONNECTION_H */

include/aws/http/private/h2_stream.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121

2222
#include <aws/common/mutex.h>
2323

24+
#include <inttypes.h>
25+
26+
#define AWS_H2_STREAM_LOGF(level, stream, text, ...) \
27+
AWS_LOGF_##level( \
28+
AWS_LS_HTTP_STREAM, \
29+
"id=%" PRIu32 " connection=%p state=%s: " text, \
30+
(stream)->id, \
31+
(void *)(stream)->base.owning_connection, \
32+
aws_h2_stream_state_to_str((stream)->thread_data.state), \
33+
__VA_ARGS__)
34+
#define AWS_H2_STREAM_LOG(level, stream, text) AWS_H2_STREAM_LOGF(level, (stream), "%s", (text))
35+
2436
enum aws_h2_stream_state {
2537
AWS_H2_STREAM_STATE_IDLE,
2638
AWS_H2_STREAM_STATE_RESERVED_LOCAL,
@@ -36,7 +48,9 @@ enum aws_h2_stream_state {
3648
struct aws_h2_stream {
3749
struct aws_http_stream base;
3850

39-
const uint32_t id;
51+
uint32_t id;
52+
53+
struct aws_linked_list_node node;
4054

4155
/* Only the event-loop thread may touch this data */
4256
struct {
@@ -60,7 +74,7 @@ AWS_HTTP_API
6074
const char *aws_h2_stream_state_to_str(enum aws_h2_stream_state state);
6175

6276
AWS_HTTP_API
63-
struct aws_h2_stream *aws_h1_stream_new_request(
77+
struct aws_h2_stream *aws_h2_stream_new_request(
6478
struct aws_http_connection *client_connection,
6579
const struct aws_http_make_request_options *options);
6680

source/h1_connection.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,11 @@ static int s_handler_process_read_message(
15761576
}
15771577

15781578
AWS_LOGF_TRACE(AWS_LS_HTTP_CONNECTION, "id=%p: Done processing message.", (void *)&connection->base);
1579+
if (message) {
1580+
/* release message back to pool before re-opening window */
1581+
aws_mem_release(message->allocator, message);
1582+
message = NULL;
1583+
}
15791584

15801585
/* Increment read window */
15811586
if (incoming_message_size > connection->thread_data.incoming_message_window_shrink_size) {
@@ -1593,9 +1598,6 @@ static int s_handler_process_read_message(
15931598
}
15941599
}
15951600

1596-
if (message) {
1597-
aws_mem_release(message->allocator, message);
1598-
}
15991601
return AWS_OP_SUCCESS;
16001602

16011603
shutdown:
@@ -1735,7 +1737,7 @@ static int s_handler_shutdown(
17351737
}
17361738

17371739
/* It's OK to access synced_data.pending_stream_list without holding the lock because
1738-
* no more streams can be added after s_shutdown_connection() has been invoked. */
1740+
* no more streams can be added after s_stop() has been invoked. */
17391741
while (!aws_linked_list_empty(&connection->synced_data.pending_stream_list)) {
17401742
struct aws_linked_list_node *node = aws_linked_list_front(&connection->synced_data.pending_stream_list);
17411743
s_stream_complete(AWS_CONTAINER_OF(node, struct aws_h1_stream, node), stream_error_code);

0 commit comments

Comments
 (0)