-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apple Network Framework Socket Changes #662
base: grand_dispatch_queue
Are you sure you want to change the base?
Changes from 196 commits
14a3386
9715a3e
b830a86
cccbda2
caac9a5
eb59ff1
8a794de
553d45f
cf610e9
07bac64
dd1fbf2
2fd514c
2a0da42
9cc6620
e3281ee
43fd436
1c1cd02
88f6de3
cf53cc6
a7ab224
62fd06d
cbb8c42
4ce33ee
29ab896
f9cd5d0
2e55d2d
6938bc3
4658492
ef8d53f
731ba49
bac8b07
429bf26
2282f8f
8e7b351
54e58e9
b01b510
5b5a953
b7f13df
b325809
86b4343
9471d05
789d446
33aa640
68fa441
a47fd44
b4cd993
d071082
dd33861
f950453
c188594
6a1c03a
871ae9b
a0be9d2
32728ba
9e8015c
3350e6c
2592e47
f8024d2
0e24c22
40b6b81
81992ba
e89119a
776977e
2aafe5f
ada3e09
fbe538f
86f3b2d
72b51a0
69c22b4
1b79cbd
e613e5d
28b7546
351c682
f24d637
0d69dd7
c408e30
145e7d7
3a4eaca
35934d3
11d0f84
8320127
652195b
1637a88
658463a
d0dddda
31fd471
d784f96
d880859
6b9a05b
630d0bb
1dc7c7d
0b7ba13
e9576c0
9b8fb15
535d92b
95464ab
a5094d2
4992f4e
0588e5c
c094abf
96c3c71
d114817
84b3299
c65daa0
a457935
967379a
0397c14
aabba3c
5f95766
e9e5ee3
cff2fd1
dbeb628
44bb099
d960c5a
a4c1468
b98c09a
03eb5a1
7e709cc
b1fcf8d
9733a56
9fc5d4a
d0b3143
1f9b1ef
c8484df
1fa11ed
b3cc904
4becc61
b79b9a3
2c54a76
5e24039
19cd3c1
fe95355
73f701a
7bb9d06
96e8643
7590685
7809d15
cdfab7e
43ee31f
c4d7096
36bf219
8709bb2
1f4def1
f641e4e
e6fcc3c
439b5ef
1dfd6fa
3fc15b3
8ed037c
de14a43
35f94d9
369eb0b
8c4bdba
be1c90e
acd6659
07c46bd
79e8b0e
e258edc
b5098c0
0ad1471
a25c892
0c2face
6aa2ee9
469615f
f661727
a49b771
2627d1c
8d66c7f
7d7fc09
9bb0a1e
cd41c8f
4c2a4d1
f81423f
d49533c
bd91776
e837f77
6a95f72
5fe71c6
8dc88fd
83981c3
7dec84e
bdcd5ee
b5a0e85
2d312da
6043ce4
2f7eec7
043b468
5ebcf77
17d2190
4b1a553
b86e381
098b1bd
c973549
0368bd9
304f588
214913a
031a0e0
fbcafd8
f4e37dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,14 @@ typedef void(aws_server_bootstrap_on_accept_channel_shutdown_fn)( | |
struct aws_channel *channel, | ||
void *user_data); | ||
|
||
/** | ||
* This function is only used for async listener (Apple Network Framework in this case). | ||
* Once the server listener socket is finished setup and starting listening, this fuction | ||
* will be invoked. | ||
*/ | ||
typedef void( | ||
aws_server_bootstrap_on_listener_setup_fn)(struct aws_server_bootstrap *bootstrap, int error_code, void *user_data); | ||
|
||
/** | ||
* Once the server listener socket is finished destroying, and all the existing connections are closed, this fuction | ||
* will be invoked. | ||
|
@@ -212,6 +220,7 @@ struct aws_server_socket_channel_bootstrap_options { | |
const struct aws_tls_connection_options *tls_options; | ||
aws_server_bootstrap_on_accept_channel_setup_fn *incoming_callback; | ||
aws_server_bootstrap_on_accept_channel_shutdown_fn *shutdown_callback; | ||
aws_server_bootstrap_on_listener_setup_fn *setup_callback; | ||
aws_server_bootstrap_on_server_listener_destroy_fn *destroy_callback; | ||
bool enable_read_back_pressure; | ||
void *user_data; | ||
|
@@ -296,6 +305,9 @@ AWS_IO_API int aws_server_bootstrap_set_alpn_callback( | |
AWS_IO_API struct aws_socket *aws_server_bootstrap_new_socket_listener( | ||
const struct aws_server_socket_channel_bootstrap_options *bootstrap_options); | ||
|
||
AWS_IO_API struct aws_socket *aws_server_bootstrap_new_socket_listener_async( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just make all listener implementations use an async path? |
||
const struct aws_server_socket_channel_bootstrap_options *bootstrap_options); | ||
|
||
/** | ||
* Shuts down 'listener' and cleans up any resources associated with it. Any incoming channels on `listener` will still | ||
* be active. `destroy_callback` will be invoked after the server socket listener is destroyed, and all associated | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ enum aws_socket_impl_type { | |
|
||
#define AWS_NETWORK_INTERFACE_NAME_MAX 16 | ||
|
||
typedef void(aws_socket_on_shutdown_complete_fn)(void *user_data); | ||
|
||
struct aws_socket_options { | ||
enum aws_socket_type type; | ||
enum aws_socket_domain domain; | ||
|
@@ -65,6 +67,9 @@ struct aws_socket_options { | |
uint16_t keep_alive_max_failed_probes; | ||
bool keepalive; | ||
|
||
aws_socket_on_shutdown_complete_fn *on_shutdown_complete; | ||
void *shutdown_user_data; | ||
|
||
/** | ||
* THIS IS AN EXPERIMENTAL AND UNSTABLE API | ||
* (Optional) | ||
|
@@ -90,6 +95,15 @@ struct aws_event_loop; | |
*/ | ||
typedef void(aws_socket_on_connection_result_fn)(struct aws_socket *socket, int error_code, void *user_data); | ||
|
||
/** | ||
* Called by a listening socket when a listener accept has successfully initialized or an error has occurred. | ||
* If the listener was successful error_code will be AWS_ERROR_SUCCESS and the socket has already been assigned | ||
* to the event loop specified in aws_socket_start_accept(). | ||
* | ||
* If an error occurred error_code will be non-zero. | ||
*/ | ||
typedef void(aws_socket_on_accept_started_fn)(struct aws_socket *socket, int error_code, void *user_data); | ||
|
||
/** | ||
* Called by a listening socket when either an incoming connection has been received or an error occurred. | ||
* | ||
|
@@ -116,14 +130,15 @@ typedef void(aws_socket_on_accept_result_fn)( | |
* Callback for when the data passed to a call to aws_socket_write() has either completed or failed. | ||
* On success, error_code will be AWS_ERROR_SUCCESS. | ||
* | ||
* `socket` may be NULL in the callback if the socket is released and cleaned up before a callback is triggered. | ||
* by the system I/O handler, | ||
* `socket` may be NULL in the callback if the socket is released and cleaned up before the callback is triggered. | ||
*/ | ||
typedef void( | ||
aws_socket_on_write_completed_fn)(struct aws_socket *socket, int error_code, size_t bytes_written, void *user_data); | ||
/** | ||
* Callback for when socket is either readable (edge-triggered) or when an error has occurred. If the socket is | ||
* readable, error_code will be AWS_ERROR_SUCCESS. | ||
* | ||
* `socket` may be NULL in the callback if the socket is released and cleaned up before the callback is triggered. | ||
*/ | ||
typedef void(aws_socket_on_readable_fn)(struct aws_socket *socket, int error_code, void *user_data); | ||
|
||
|
@@ -156,6 +171,16 @@ struct aws_socket { | |
void *impl; | ||
}; | ||
|
||
struct aws_socket_listener_options { | ||
aws_socket_on_accept_result_fn *on_accept_result; | ||
void *on_accept_result_user_data; | ||
|
||
// This callback is invoked when the listener starts accepting incoming connections. | ||
// It is only triggered in asynchronous listener APIs while using nw_socket. | ||
aws_socket_on_accept_started_fn *on_accept_start_result; | ||
void *on_accept_start_user_data; | ||
}; | ||
|
||
struct aws_byte_buf; | ||
struct aws_byte_cursor; | ||
|
||
|
@@ -227,8 +252,7 @@ AWS_IO_API int aws_socket_listen(struct aws_socket *socket, int backlog_size); | |
AWS_IO_API int aws_socket_start_accept( | ||
struct aws_socket *socket, | ||
struct aws_event_loop *accept_loop, | ||
aws_socket_on_accept_result_fn *on_accept_result, | ||
void *user_data); | ||
struct aws_socket_listener_options options); | ||
|
||
/** | ||
* TCP, LOCAL and VSOCK only. The listening socket will stop accepting new connections. | ||
|
@@ -239,12 +263,33 @@ AWS_IO_API int aws_socket_start_accept( | |
*/ | ||
AWS_IO_API int aws_socket_stop_accept(struct aws_socket *socket); | ||
|
||
/** | ||
* Apple Network Framework only. The callback that will triggered when aws_socket_close() finished. The callback | ||
* will be called from the socket event loop. | ||
*/ | ||
AWS_IO_API int aws_socket_set_close_complete_callback( | ||
xiazhvera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
struct aws_socket *socket, | ||
aws_socket_on_shutdown_complete_fn fn, | ||
void *user_data); | ||
|
||
/** | ||
* Apple Network Framework only. The callback that will triggered when aws_socket_cleanup() finished. And | ||
* it is only safe to release the socket afterwards. The callback will be called from the socket event loop. | ||
*/ | ||
AWS_IO_API int aws_socket_set_cleanup_complete_callback( | ||
struct aws_socket *socket, | ||
aws_socket_on_shutdown_complete_fn fn, | ||
void *user_data); | ||
|
||
/** | ||
* Calls `close()` on the socket and unregisters all io operations from the event loop. This function must be called | ||
* from the event-loop's thread unless this is a listening socket. If it's a listening socket it can be called from any | ||
* non-event-loop thread or the event-loop the socket is currently assigned to. If called from outside the event-loop, | ||
* this function will block waiting on the socket to close. If this is called from an event-loop thread other than | ||
* the one it's assigned to, it presents the possibility of a deadlock, so don't do it. | ||
* | ||
* If you are using Apple Network Framework, you should always call this function from an event-loop thread regardless | ||
* it is a server or client socket. | ||
*/ | ||
AWS_IO_API int aws_socket_close(struct aws_socket *socket); | ||
|
||
|
@@ -358,6 +403,12 @@ AWS_IO_API void aws_socket_endpoint_init_local_address_for_test(struct aws_socke | |
* network_interface_name on Windows */ | ||
AWS_IO_API bool aws_is_network_interface_name_valid(const char *interface_name); | ||
|
||
/** | ||
* Get default impl type based on the platform. | ||
* For user in internal tests only | ||
*/ | ||
AWS_IO_API enum aws_socket_impl_type aws_socket_get_default_impl_type(void); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repeating in-person comment: can we look into privatizing APIs that are only used internally by the socket handler? The more we can make private, the better I feel about all the special conditions and terms on the socket APIs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but I'm talking about the entire public API for sockets. How much of it needs to be public? |
||
|
||
AWS_EXTERN_C_END | ||
AWS_POP_SANE_WARNING_LEVEL | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this documentation necessary in the public readme? A giant list of functions feels like a distraction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help with anybody who would like to extend the socket implementation. Also, we listed the vtable for other classes as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this does not belong here. Are people supposed to keep this in sync with the real definition? Anyone looking at the code can look at the real definition.
As far as I'm concerned, no vtables should be present in a library README.