| 1 |
#ifndef AWS_HTTP_H2_STREAM_H |
| 2 |
#define AWS_HTTP_H2_STREAM_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <aws/http/private/h2_frames.h> |
| 10 |
#include <aws/http/private/request_response_impl.h> |
| 11 |
|
| 12 |
#include <aws/common/mutex.h> |
| 13 |
#include <aws/io/channel.h> |
| 14 |
|
| 15 |
#include <inttypes.h> |
| 16 |
|
| 17 |
#define AWS_H2_STREAM_LOGF(level, stream, text, ...) \ |
| 18 |
AWS_LOGF_##level( \ |
| 19 |
AWS_LS_HTTP_STREAM, \ |
| 20 |
"id=%" PRIu32 " connection=%p state=%s: " text, \ |
| 21 |
(stream)->base.id, \ |
| 22 |
(void *)(stream)->base.owning_connection, \ |
| 23 |
aws_h2_stream_state_to_str((stream)->thread_data.state), \ |
| 24 |
__VA_ARGS__) |
| 25 |
#define AWS_H2_STREAM_LOG(level, stream, text) AWS_H2_STREAM_LOGF(level, (stream), "%s", (text)) |
| 26 |
|
| 27 |
enum aws_h2_stream_state { |
| 28 |
|
| 29 |
AWS_H2_STREAM_STATE_IDLE, |
| 30 |
|
| 31 |
|
| 32 |
AWS_H2_STREAM_STATE_RESERVED_LOCAL, |
| 33 |
|
| 34 |
|
| 35 |
AWS_H2_STREAM_STATE_RESERVED_REMOTE, |
| 36 |
|
| 37 |
AWS_H2_STREAM_STATE_OPEN, |
| 38 |
|
| 39 |
AWS_H2_STREAM_STATE_HALF_CLOSED_LOCAL, |
| 40 |
|
| 41 |
AWS_H2_STREAM_STATE_HALF_CLOSED_REMOTE, |
| 42 |
|
| 43 |
|
| 44 |
AWS_H2_STREAM_STATE_CLOSED, |
| 45 |
|
| 46 |
AWS_H2_STREAM_STATE_COUNT, |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
enum aws_h2_stream_api_state { |
| 51 |
AWS_H2_STREAM_API_STATE_INIT, |
| 52 |
AWS_H2_STREAM_API_STATE_ACTIVE, |
| 53 |
AWS_H2_STREAM_API_STATE_COMPLETE, |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
enum aws_h2_stream_body_state { |
| 58 |
AWS_H2_STREAM_BODY_STATE_NONE, |
| 59 |
AWS_H2_STREAM_BODY_STATE_WAITING_WRITES, |
| 60 |
|
| 61 |
AWS_H2_STREAM_BODY_STATE_ONGOING, |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
struct aws_h2_stream_data_write { |
| 66 |
struct aws_linked_list_node node; |
| 67 |
struct aws_input_stream *data_stream; |
| 68 |
aws_http2_stream_write_data_complete_fn *on_complete; |
| 69 |
void *user_data; |
| 70 |
bool end_stream; |
| 71 |
}; |
| 72 |
|
| 73 |
struct aws_h2_stream { |
| 74 |
struct aws_http_stream base; |
| 75 |
|
| 76 |
struct aws_linked_list_node node; |
| 77 |
struct aws_channel_task cross_thread_work_task; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
int32_t window_size_threshold_to_send_update; |
| 83 |
aws_http2_on_remote_end_stream_fn *on_h2_remote_end_stream; |
| 84 |
|
| 85 |
|
| 86 |
struct { |
| 87 |
enum aws_h2_stream_state state; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
int32_t window_size_peer; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
int32_t window_size_self; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
uint64_t pending_window_update_size_self; |
| 104 |
|
| 105 |
struct aws_http_message *outgoing_message; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
struct aws_linked_list outgoing_writes; |
| 110 |
bool received_main_headers; |
| 111 |
|
| 112 |
bool content_length_received; |
| 113 |
|
| 114 |
uint64_t incoming_content_length; |
| 115 |
|
| 116 |
uint64_t incoming_data_length; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
bool waiting_for_writes; |
| 121 |
|
| 122 |
|
| 123 |
bool is_complete; |
| 124 |
} thread_data; |
| 125 |
|
| 126 |
|
| 127 |
struct { |
| 128 |
struct aws_mutex lock; |
| 129 |
|
| 130 |
bool is_cross_thread_work_task_scheduled; |
| 131 |
|
| 132 |
|
| 133 |
uint64_t pending_window_update_size_self; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
struct aws_h2err reset_error; |
| 138 |
bool reset_called; |
| 139 |
bool manual_write_ended; |
| 140 |
|
| 141 |
|
| 142 |
enum aws_h2_stream_api_state api_state; |
| 143 |
|
| 144 |
|
| 145 |
struct aws_linked_list pending_write_list; |
| 146 |
} synced_data; |
| 147 |
bool manual_write; |
| 148 |
|
| 149 |
|
| 150 |
int64_t sent_reset_error_code; |
| 151 |
|
| 152 |
|
| 153 |
int64_t received_reset_error_code; |
| 154 |
}; |
| 155 |
|
| 156 |
const char *aws_h2_stream_state_to_str(enum aws_h2_stream_state state); |
| 157 |
|
| 158 |
struct aws_h2_stream *aws_h2_stream_new_request( |
| 159 |
struct aws_http_connection *client_connection, |
| 160 |
const struct aws_http_make_request_options *options); |
| 161 |
|
| 162 |
enum aws_h2_stream_state aws_h2_stream_get_state(const struct aws_h2_stream *stream); |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
struct aws_h2err aws_h2_stream_window_size_change_direct(struct aws_h2_stream *stream, int32_t size_changed, bool self); |
| 170 |
|
| 171 |
|
| 172 |
int aws_h2_stream_on_activated(struct aws_h2_stream *stream, enum aws_h2_stream_body_state *body_state); |
| 173 |
|
| 174 |
|
| 175 |
void aws_h2_stream_complete(struct aws_h2_stream *stream, int error_code); |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
int aws_h2_stream_encode_data_frame( |
| 182 |
struct aws_h2_stream *stream, |
| 183 |
struct aws_h2_frame_encoder *encoder, |
| 184 |
struct aws_byte_buf *output, |
| 185 |
int *data_encode_status); |
| 186 |
|
| 187 |
struct aws_h2err aws_h2_stream_on_decoder_headers_begin(struct aws_h2_stream *stream); |
| 188 |
|
| 189 |
struct aws_h2err aws_h2_stream_on_decoder_headers_i( |
| 190 |
struct aws_h2_stream *stream, |
| 191 |
const struct aws_http_header *header, |
| 192 |
enum aws_http_header_name name_enum, |
| 193 |
enum aws_http_header_block block_type); |
| 194 |
|
| 195 |
struct aws_h2err aws_h2_stream_on_decoder_headers_end( |
| 196 |
struct aws_h2_stream *stream, |
| 197 |
bool malformed, |
| 198 |
enum aws_http_header_block block_type); |
| 199 |
|
| 200 |
struct aws_h2err aws_h2_stream_on_decoder_push_promise(struct aws_h2_stream *stream, uint32_t promised_stream_id); |
| 201 |
struct aws_h2err aws_h2_stream_on_decoder_data_begin( |
| 202 |
struct aws_h2_stream *stream, |
| 203 |
uint32_t payload_len, |
| 204 |
uint32_t total_padding_bytes, |
| 205 |
bool end_stream); |
| 206 |
struct aws_h2err aws_h2_stream_on_decoder_data_i(struct aws_h2_stream *stream, struct aws_byte_cursor data); |
| 207 |
struct aws_h2err aws_h2_stream_on_decoder_window_update( |
| 208 |
struct aws_h2_stream *stream, |
| 209 |
uint32_t window_size_increment, |
| 210 |
bool *window_resume); |
| 211 |
struct aws_h2err aws_h2_stream_on_decoder_end_stream(struct aws_h2_stream *stream); |
| 212 |
struct aws_h2err aws_h2_stream_on_decoder_rst_stream(struct aws_h2_stream *stream, uint32_t h2_error_code); |
| 213 |
|
| 214 |
int aws_h2_stream_activate(struct aws_http_stream *stream); |
| 215 |
|
| 216 |
#endif |