Skip to content

Commit d39c61a

Browse files
committed
Update contrib/restricted/aws/aws-c-event-stream to 0.5.5
commit_hash:8307bd2fe419c4785e2cf1b39f6127b9f71b54cf
1 parent 8bd56b6 commit d39c61a

File tree

7 files changed

+126
-35
lines changed

7 files changed

+126
-35
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
pkgs: attrs: with pkgs; with attrs; rec {
2-
version = "0.5.4";
2+
version = "0.5.5";
33

44
src = fetchFromGitHub {
55
owner = "awslabs";
66
repo = "aws-c-event-stream";
77
rev = "v${version}";
8-
hash = "sha256-Y4vyoNlYdIQg/NggBoYtX4CPiCzG24a4mKG8VGTdqy8=";
8+
hash = "sha256-wVjpDKKwoksq5gFtvhH76c7ciP0XmMozhkWmzY6GwgU=";
99
};
1010
}

contrib/restricted/aws/aws-c-event-stream/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ Total message overhead, including the prelude and both checksums, is 16 bytes.
7070

7171
The following diagram shows the components that make up a message and a header. There are multiple headers per message.
7272

73-
![Encoding Diagram](docs/encoding.png)
73+
![Encoding Diagram](docs/images/encoding.png)

contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream_exports.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
55
* SPDX-License-Identifier: Apache-2.0.
66
*/
7-
#if defined(USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32)
7+
#if defined(AWS_CRT_USE_WINDOWS_DLL_SEMANTICS) || defined(_WIN32)
88
# ifdef AWS_EVENT_STREAM_USE_IMPORT_EXPORT
99
# ifdef AWS_EVENT_STREAM_EXPORTS
1010
# define AWS_EVENT_STREAM_API __declspec(dllexport)
@@ -15,15 +15,14 @@
1515
# define AWS_EVENT_STREAM_API
1616
# endif /* AWS_EVENT_STREAM_USE_IMPORT_EXPORT */
1717

18-
#else /* defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */
18+
#else /* defined (AWS_CRT_USE_WINDOWS_DLL_SEMANTICS) || defined (_WIN32) */
1919

20-
# if ((__GNUC__ >= 4) || defined(__clang__)) && defined(AWS_EVENT_STREAM_USE_IMPORT_EXPORT) && \
21-
defined(AWS_EVENT_STREAM_EXPORTS)
20+
# if defined(AWS_EVENT_STREAM_USE_IMPORT_EXPORT) && defined(AWS_EVENT_STREAM_EXPORTS)
2221
# define AWS_EVENT_STREAM_API __attribute__((visibility("default")))
2322
# else
2423
# define AWS_EVENT_STREAM_API
25-
# endif /* __GNUC__ >= 4 || defined(__clang__) */
24+
# endif
2625

27-
#endif /* defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */
26+
#endif /* defined (AWS_CRT_USE_WINDOWS_DLL_SEMANTICS) || defined (_WIN32) */
2827

2928
#endif /* AWS_EVENT_STREAM_EXPORTS_H */

contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_client.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
AWS_PUSH_SANE_WARNING_LEVEL
1111

1212
struct aws_channel;
13+
struct aws_event_loop;
1314
struct aws_event_stream_rpc_client_connection;
1415
struct aws_event_stream_rpc_client_continuation_token;
1516

@@ -30,9 +31,15 @@ typedef void(aws_event_stream_rpc_client_stream_continuation_closed_fn)(
3031
struct aws_event_stream_rpc_client_continuation_token *token,
3132
void *user_data);
3233

34+
/**
35+
* Invoked after a continuation has been fully destroyed. Listeners know that no further callbacks are possible.
36+
*/
37+
typedef void(aws_event_stream_rpc_client_stream_continuation_terminated_fn)(void *user_data);
38+
3339
struct aws_event_stream_rpc_client_stream_continuation_options {
3440
aws_event_stream_rpc_client_stream_continuation_fn *on_continuation;
3541
aws_event_stream_rpc_client_stream_continuation_closed_fn *on_continuation_closed;
42+
aws_event_stream_rpc_client_stream_continuation_terminated_fn *on_continuation_terminated;
3643
void *user_data;
3744
};
3845

@@ -73,6 +80,11 @@ typedef void(aws_event_stream_rpc_client_on_connection_setup_fn)(
7380
int error_code,
7481
void *user_data);
7582

83+
/**
84+
* Invoked when a connection has been completely destroyed.
85+
*/
86+
typedef void(aws_event_stream_rpc_client_on_connection_terminated_fn)(void *user_data);
87+
7688
/**
7789
* Invoked whenever a message has been flushed to the channel.
7890
*/
@@ -93,6 +105,7 @@ struct aws_event_stream_rpc_client_connection_options {
93105
aws_event_stream_rpc_client_on_connection_setup_fn *on_connection_setup;
94106
aws_event_stream_rpc_client_connection_protocol_message_fn *on_connection_protocol_message;
95107
aws_event_stream_rpc_client_on_connection_shutdown_fn *on_connection_shutdown;
108+
aws_event_stream_rpc_client_on_connection_terminated_fn *on_connection_terminated;
96109
void *user_data;
97110
};
98111

@@ -142,6 +155,12 @@ AWS_EVENT_STREAM_API int aws_event_stream_rpc_client_connection_send_protocol_me
142155
aws_event_stream_rpc_client_message_flush_fn *flush_fn,
143156
void *user_data);
144157

158+
/**
159+
* Returns the event loop that a connection is seated on.
160+
*/
161+
AWS_EVENT_STREAM_API struct aws_event_loop *aws_event_stream_rpc_client_connection_get_event_loop(
162+
const struct aws_event_stream_rpc_client_connection *connection);
163+
145164
/**
146165
* Create a new stream. continuation_option's callbacks will not be invoked, and nothing will be sent across the wire
147166
* until aws_event_stream_rpc_client_continuation_activate() is invoked.

contrib/restricted/aws/aws-c-event-stream/source/event_stream_rpc_client.c

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <inttypes.h>
1616

17+
#include "aws/io/event_loop.h"
18+
1719
#ifdef _MSC_VER
1820
/* allow declared initializer using address of automatic variable */
1921
# pragma warning(disable : 4221)
@@ -28,6 +30,7 @@ struct aws_event_stream_rpc_client_connection {
2830
struct aws_allocator *allocator;
2931
struct aws_hash_table continuation_table;
3032
struct aws_client_bootstrap *bootstrap_ref;
33+
struct aws_event_loop *event_loop;
3134
struct aws_atomic_var ref_count;
3235
struct aws_channel *channel;
3336
struct aws_channel_handler *event_stream_handler;
@@ -39,6 +42,7 @@ struct aws_event_stream_rpc_client_connection {
3942
aws_event_stream_rpc_client_on_connection_setup_fn *on_connection_setup;
4043
aws_event_stream_rpc_client_connection_protocol_message_fn *on_connection_protocol_message;
4144
aws_event_stream_rpc_client_on_connection_shutdown_fn *on_connection_shutdown;
45+
aws_event_stream_rpc_client_on_connection_terminated_fn *on_connection_terminated;
4246
void *user_data;
4347
bool bootstrap_owned;
4448
bool enable_read_back_pressure;
@@ -49,6 +53,7 @@ struct aws_event_stream_rpc_client_continuation_token {
4953
struct aws_event_stream_rpc_client_connection *connection;
5054
aws_event_stream_rpc_client_stream_continuation_fn *continuation_fn;
5155
aws_event_stream_rpc_client_stream_continuation_closed_fn *closed_fn;
56+
aws_event_stream_rpc_client_stream_continuation_terminated_fn *terminated_fn;
5257
void *user_data;
5358
struct aws_atomic_var ref_count;
5459
struct aws_atomic_var is_closed;
@@ -187,9 +192,7 @@ static void s_on_channel_shutdown_fn(
187192
aws_event_stream_rpc_client_connection_release(connection);
188193
}
189194

190-
/* Set each continuation's is_closed=true.
191-
* A lock MUST be held while calling this.
192-
* For use with aws_hash_table_foreach(). */
195+
/* Set each continuation's is_closed=true. */
193196
static int s_mark_each_continuation_closed(void *context, struct aws_hash_element *p_element) {
194197
(void)context;
195198
struct aws_event_stream_rpc_client_continuation_token *continuation = p_element->value;
@@ -233,18 +236,31 @@ static int s_complete_and_clear_each_continuation(void *context, struct aws_hash
233236
static void s_clear_continuation_table(struct aws_event_stream_rpc_client_connection *connection) {
234237
AWS_ASSERT(!aws_event_stream_rpc_client_connection_is_open(connection));
235238

239+
struct aws_hash_table temp_table;
240+
aws_hash_table_init(
241+
&temp_table,
242+
connection->allocator,
243+
64,
244+
aws_event_stream_rpc_hash_streamid,
245+
aws_event_stream_rpc_streamid_eq,
246+
NULL,
247+
NULL);
248+
236249
/* Use lock to ensure synchronization with code that adds entries to table.
237250
* Since connection was just marked closed, no further entries will be
238-
* added to table once we acquire the lock. */
251+
* added to table once we acquire the lock.
252+
*
253+
* While no further entries can be added, there are concurrent execution paths where things can be
254+
* removed. So rather than iterating the connection's table, swap it out for an empty one and iterate
255+
* the temporary table instead. Removing from an empty table will be harmless.
256+
*/
239257
aws_mutex_lock(&connection->stream_lock);
240-
aws_hash_table_foreach(&connection->continuation_table, s_mark_each_continuation_closed, NULL);
258+
aws_hash_table_swap(&temp_table, &connection->continuation_table);
241259
aws_mutex_unlock(&connection->stream_lock);
242260

243-
/* Now release lock before invoking callbacks.
244-
* It's safe to alter the table now without a lock, since no further
245-
* entries can be added, and we've gone through the critical section
246-
* above to ensure synchronization */
247-
aws_hash_table_foreach(&connection->continuation_table, s_complete_and_clear_each_continuation, NULL);
261+
aws_hash_table_foreach(&temp_table, s_mark_each_continuation_closed, NULL);
262+
aws_hash_table_foreach(&temp_table, s_complete_and_clear_each_continuation, NULL);
263+
aws_hash_table_clean_up(&temp_table);
248264
}
249265

250266
int aws_event_stream_rpc_client_connection_connect(
@@ -268,6 +284,8 @@ int aws_event_stream_rpc_client_connection_connect(
268284
connection->allocator = allocator;
269285
aws_atomic_init_int(&connection->ref_count, 1);
270286
connection->bootstrap_ref = conn_options->bootstrap;
287+
connection->event_loop = aws_event_loop_group_get_next_loop(connection->bootstrap_ref->event_loop_group);
288+
271289
/* this is released in the connection release which gets called regardless of if this function is successful or
272290
* not*/
273291
aws_client_bootstrap_acquire(connection->bootstrap_ref);
@@ -276,6 +294,7 @@ int aws_event_stream_rpc_client_connection_connect(
276294
aws_mutex_init(&connection->stream_lock);
277295

278296
connection->on_connection_shutdown = conn_options->on_connection_shutdown;
297+
connection->on_connection_terminated = conn_options->on_connection_terminated;
279298
connection->on_connection_protocol_message = conn_options->on_connection_protocol_message;
280299
connection->on_connection_setup = conn_options->on_connection_setup;
281300
connection->user_data = conn_options->user_data;
@@ -307,6 +326,7 @@ int aws_event_stream_rpc_client_connection_connect(
307326
.enable_read_back_pressure = false,
308327
.setup_callback = s_on_channel_setup_fn,
309328
.shutdown_callback = s_on_channel_shutdown_fn,
329+
.requested_event_loop = connection->event_loop,
310330
};
311331

312332
if (aws_client_bootstrap_new_socket_channel(&bootstrap_options)) {
@@ -340,7 +360,15 @@ static void s_destroy_connection(struct aws_event_stream_rpc_client_connection *
340360
AWS_LOGF_DEBUG(AWS_LS_EVENT_STREAM_RPC_CLIENT, "id=%p: destroying connection.", (void *)connection);
341361
aws_hash_table_clean_up(&connection->continuation_table);
342362
aws_client_bootstrap_release(connection->bootstrap_ref);
363+
364+
aws_event_stream_rpc_client_on_connection_terminated_fn *terminated_fn = connection->on_connection_terminated;
365+
void *terminated_user_data = connection->user_data;
366+
343367
aws_mem_release(connection->allocator, connection);
368+
369+
if (terminated_fn) {
370+
terminated_fn(terminated_user_data);
371+
}
344372
}
345373

346374
void aws_event_stream_rpc_client_connection_release(const struct aws_event_stream_rpc_client_connection *connection) {
@@ -434,13 +462,19 @@ static void s_on_protocol_message_written_fn(
434462
AWS_FATAL_ASSERT(message_args->continuation && "end stream flag was set but it wasn't on a continuation");
435463
aws_atomic_store_int(&message_args->continuation->is_closed, 1U);
436464

465+
int was_present = 0;
437466
aws_mutex_lock(&message_args->connection->stream_lock);
438467
aws_hash_table_remove(
439-
&message_args->connection->continuation_table, &message_args->continuation->stream_id, NULL, NULL);
468+
&message_args->connection->continuation_table, &message_args->continuation->stream_id, NULL, &was_present);
440469
aws_mutex_unlock(&message_args->connection->stream_lock);
441470

442-
/* Lock must NOT be held while invoking callback */
443-
s_complete_continuation(message_args->continuation);
471+
/*
472+
* Whoever successfully removes the continuation from the table gets to complete it.
473+
* Lock must NOT be held while invoking callback
474+
*/
475+
if (was_present) {
476+
s_complete_continuation(message_args->continuation);
477+
}
444478
}
445479

446480
message_args->flush_fn(error_code, message_args->user_data);
@@ -770,7 +804,6 @@ static void s_route_message_by_type(
770804
aws_mutex_unlock(&connection->stream_lock);
771805

772806
continuation->continuation_fn(continuation, &message_args, continuation->user_data);
773-
aws_event_stream_rpc_client_continuation_release(continuation);
774807

775808
/* if it was a terminal stream message purge it from the hash table. The delete will decref the continuation. */
776809
if (message_flags & AWS_EVENT_STREAM_RPC_MESSAGE_FLAG_TERMINATE_STREAM) {
@@ -780,13 +813,21 @@ static void s_route_message_by_type(
780813
(void *)connection,
781814
(void *)continuation);
782815
aws_atomic_store_int(&continuation->is_closed, 1U);
816+
int was_present = 0;
783817
aws_mutex_lock(&connection->stream_lock);
784-
aws_hash_table_remove(&connection->continuation_table, &stream_id, NULL, NULL);
818+
aws_hash_table_remove(&connection->continuation_table, &stream_id, NULL, &was_present);
785819
aws_mutex_unlock(&connection->stream_lock);
786820

787-
/* Note that we do not invoke callback while holding lock */
788-
s_complete_continuation(continuation);
821+
/*
822+
* Whoever successfully removes the continuation from the table gets to complete it.
823+
* Lock must NOT be held while invoking callback
824+
*/
825+
if (was_present) {
826+
s_complete_continuation(continuation);
827+
}
789828
}
829+
830+
aws_event_stream_rpc_client_continuation_release(continuation);
790831
} else {
791832
if (message_type <= AWS_EVENT_STREAM_RPC_MESSAGE_TYPE_APPLICATION_ERROR ||
792833
message_type >= AWS_EVENT_STREAM_RPC_MESSAGE_TYPE_COUNT) {
@@ -915,6 +956,7 @@ struct aws_event_stream_rpc_client_continuation_token *aws_event_stream_rpc_clie
915956
aws_atomic_init_int(&continuation->is_complete, 0);
916957
continuation->continuation_fn = continuation_options->on_continuation;
917958
continuation->closed_fn = continuation_options->on_continuation_closed;
959+
continuation->terminated_fn = continuation_options->on_continuation_terminated;
918960
continuation->user_data = continuation_options->user_data;
919961

920962
return continuation;
@@ -959,7 +1001,15 @@ void aws_event_stream_rpc_client_continuation_release(
9591001
if (ref_count == 1) {
9601002
struct aws_allocator *allocator = continuation_mut->connection->allocator;
9611003
aws_event_stream_rpc_client_connection_release(continuation_mut->connection);
1004+
1005+
aws_event_stream_rpc_client_stream_continuation_terminated_fn *terminated_fn = continuation_mut->terminated_fn;
1006+
void *terminated_user_data = continuation_mut->user_data;
1007+
9621008
aws_mem_release(allocator, continuation_mut);
1009+
1010+
if (terminated_fn) {
1011+
terminated_fn(terminated_user_data);
1012+
}
9631013
}
9641014
}
9651015

@@ -1062,3 +1112,13 @@ int aws_event_stream_rpc_client_continuation_send_message(
10621112
return s_send_protocol_message(
10631113
continuation->connection, continuation, NULL, message_args, continuation->stream_id, flush_fn, user_data);
10641114
}
1115+
1116+
struct aws_event_loop *aws_event_stream_rpc_client_connection_get_event_loop(
1117+
const struct aws_event_stream_rpc_client_connection *connection) {
1118+
1119+
if (!connection) {
1120+
return NULL;
1121+
}
1122+
1123+
return connection->event_loop;
1124+
}

contrib/restricted/aws/aws-c-event-stream/source/event_stream_rpc_server.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,13 +901,26 @@ static void s_route_message_by_type(
901901
struct aws_hash_element *continuation_element = NULL;
902902
if (aws_hash_table_find(&connection->continuation_table, &stream_id, &continuation_element) ||
903903
!continuation_element) {
904-
AWS_LOGF_ERROR(
905-
AWS_LS_EVENT_STREAM_RPC_SERVER,
906-
"id=%p: stream_id does not have a corresponding continuation",
907-
(void *)connection);
908-
aws_raise_error(AWS_ERROR_EVENT_STREAM_RPC_PROTOCOL_ERROR);
909-
s_send_connection_level_error(
910-
connection, AWS_EVENT_STREAM_RPC_MESSAGE_TYPE_PROTOCOL_ERROR, 0, &s_invalid_client_stream_id_error);
904+
if ((message_flags & AWS_EVENT_STREAM_RPC_MESSAGE_FLAG_TERMINATE_STREAM) == 0) {
905+
AWS_LOGF_ERROR(
906+
AWS_LS_EVENT_STREAM_RPC_SERVER,
907+
"id=%p: stream_id does not have a corresponding continuation",
908+
(void *)connection);
909+
aws_raise_error(AWS_ERROR_EVENT_STREAM_RPC_PROTOCOL_ERROR);
910+
s_send_connection_level_error(
911+
connection,
912+
AWS_EVENT_STREAM_RPC_MESSAGE_TYPE_PROTOCOL_ERROR,
913+
0,
914+
&s_invalid_client_stream_id_error);
915+
} else {
916+
/* Simultaneous close can trip this condition */
917+
AWS_LOGF_DEBUG(
918+
AWS_LS_EVENT_STREAM_RPC_SERVER,
919+
"id=%p: received a terminate stream message for stream_id %d, which no longer has a "
920+
"corresponding continuation",
921+
(void *)connection,
922+
(int)stream_id);
923+
}
911924
return;
912925
}
913926

contrib/restricted/aws/aws-c-event-stream/ya.make

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ LICENSE(Apache-2.0)
66

77
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
88

9-
VERSION(0.5.4)
9+
VERSION(0.5.5)
1010

11-
ORIGINAL_SOURCE(https://github.com/awslabs/aws-c-event-stream/archive/v0.5.4.tar.gz)
11+
ORIGINAL_SOURCE(https://github.com/awslabs/aws-c-event-stream/archive/v0.5.5.tar.gz)
1212

1313
PEERDIR(
1414
contrib/restricted/aws/aws-c-common

0 commit comments

Comments
 (0)