-
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
Event Loop & Socket Type Multi-Support #692
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #692 +/- ##
==========================================
- Coverage 80.10% 79.66% -0.44%
==========================================
Files 29 30 +1
Lines 6001 6122 +121
==========================================
+ Hits 4807 4877 +70
- Misses 1194 1245 +51 ☔ View full report in Codecov by Sentry. |
…io into runtime_select_event_loop
@@ -131,7 +131,8 @@ struct aws_event_loop_vtable s_kqueue_vtable = { | |||
.is_on_callers_thread = s_is_event_thread, | |||
}; | |||
|
|||
struct aws_event_loop *aws_event_loop_new_default_with_options( | |||
#ifdef AWS_ENABLE_KQUEUE |
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.
How would we be here if this wasn't defined?
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.
If not defined AWS_ENABLE_KQUEUE, the following function should be defined. (in source/event_loop.c)
#ifndef AWS_ENABLE_KQUEUE
struct aws_event_loop *aws_event_loop_new_with_kqueue(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options) {
(void)alloc;
(void)options;
AWS_ASSERT(0);
AWS_LOGF_DEBUG(AWS_LS_IO_EVENT_LOOP, "Kqueue is not supported on the platform");
aws_raise_error(AWS_ERROR_PLATFORM_NOT_SUPPORTED);
return NULL;
}
#endif // AWS_ENABLE_EPOLL
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.
Hmm, a rephrasing: "why is this source file being compiled if AWS_ENABLE_KQUEUE is not defined at compile time?"
@@ -6,6 +6,7 @@ | |||
*/ | |||
|
|||
#include <aws/io/channel.h> | |||
#include <aws/io/event_loop.h> |
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 necessary? I don't see a change that would seem to require it.
@@ -114,7 +138,10 @@ struct aws_socket_endpoint { | |||
uint32_t port; | |||
}; | |||
|
|||
struct aws_socket; |
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.
This doesn't do anything.
@@ -131,7 +131,8 @@ struct aws_event_loop_vtable s_kqueue_vtable = { | |||
.is_on_callers_thread = s_is_event_thread, | |||
}; | |||
|
|||
struct aws_event_loop *aws_event_loop_new_default_with_options( | |||
#ifdef AWS_ENABLE_KQUEUE |
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.
Hmm, a rephrasing: "why is this source file being compiled if AWS_ENABLE_KQUEUE is not defined at compile time?"
switch (type) { | ||
case AWS_EVENT_LOOP_EPOLL: | ||
#ifndef AWS_ENABLE_EPOLL | ||
AWS_LOGF_DEBUG(AWS_LS_IO_EVENT_LOOP, "Event loop type EPOLL is not supported on the platform."); |
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 don't agree. An event loop platform mismatch is not an error anyone should be trying to handle. Something is fundamentally wrong and the developer needs to fix it.
static enum aws_socket_impl_type aws_socket_get_default_impl_type(void) { | ||
enum aws_socket_impl_type type = AWS_SOCKET_IMPL_PLATFORM_DEFAULT; | ||
// override default socket | ||
#ifdef AWS_USE_APPLE_NETWORK_FRAMEWORK |
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.
This is pretty convoluted. Can we just simplify to
#ifdef AWS_USE_APPLE_NETWORK_FRAMEWORK
static enum aws_socket_impl_type aws_socket_get_default_impl_type(void) {
return AWS_SOCKET_IMPL_APPLE_NETWORK_FRAMEWORK;
}
#else
<... normal impl>
#endif
I don't see how we're not getting dead code warnings when AWS_USE_APPLE_NETWORK is defined.
#elif AWS_ENABLE_IO_COMPLETION_PORTS | ||
return AWS_SOCKET_IMPL_WINSOCK; | ||
#else | ||
return AWS_SOCKET_IMPL_PLATFORM_DEFAULT; |
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.
Is this reachable? Don't we cmake error if no event loop types are enabled? Maybe add a fatal assert
if (!impl->vtable || !impl->vtable->read) { | ||
socket->vtable = &s_winsock_vtable; | ||
|
||
impl->winsock_vtable = &s_winsock_vtables[options->domain][options->type]; |
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.
Can we make the AWS_ASSERT on domain a fatal assert instead? Same with the assert on type. Making the asserts fatal means we crash "safely" on invariant violation and not perform undefined behavior by reading from invalid static section memory.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.