Skip to content
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

Open
wants to merge 55 commits into
base: main
Choose a base branch
from

Conversation

xiazhvera
Copy link
Contributor

@xiazhvera xiazhvera commented Nov 7, 2024

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.

@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 56.68790% with 68 lines in your changes missing coverage. Please review.

Project coverage is 79.36%. Comparing base (fcb38c8) to head (f5a5338).

Files with missing lines Patch % Lines
source/event_loop.c 25.86% 43 Missing ⚠️
source/socket.c 68.75% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #692      +/-   ##
==========================================
- Coverage   80.08%   79.36%   -0.72%     
==========================================
  Files          29       30       +1     
  Lines        6001     6122     +121     
==========================================
+ Hits         4806     4859      +53     
- Misses       1195     1263      +68     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xiazhvera xiazhvera changed the title Event Loop Type Multi-Support Event Loop Type & Socket Multi-Support Nov 8, 2024
@xiazhvera xiazhvera changed the title Event Loop Type Multi-Support Event Loop & Socket Type Multi-Support Nov 11, 2024
Copy link
Contributor

@graebm graebm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

posting what I got so far...

CMakeLists.txt Outdated Show resolved Hide resolved
include/aws/io/socket.h Outdated Show resolved Hide resolved
include/aws/io/socket.h Outdated Show resolved Hide resolved
include/aws/io/socket.h Outdated Show resolved Hide resolved
@@ -114,7 +137,44 @@ struct aws_socket_endpoint {
uint32_t port;
};

struct aws_socket;

struct aws_socket_vtable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move the vtable, and the aws_socket struct to a private header?
or is it a big enough change that it needs its own PR...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the aws_socket into private will affect several downstream libs (mainly c-http). I will hold it for now and create its own PR later.

source/event_loop.c Show resolved Hide resolved
include/aws/io/event_loop.h Outdated Show resolved Hide resolved
source/event_loop.c Outdated Show resolved Hide resolved
source/event_loop.c Outdated Show resolved Hide resolved
source/socket.c Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@@ -172,6 +192,8 @@ struct aws_event_loop *aws_event_loop_new_default(struct aws_allocator *alloc, a
/**
* Creates an instance of the default event loop implementation for the current architecture and operating system using
* extendable options.
*
* Please note the event loop type defined in the options will be ignored.
*/
AWS_IO_API
struct aws_event_loop *aws_event_loop_new_default_with_options(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just eliminate all these alternate constructors and replace them with a single aws_event_loop_new(allocator, options)?

I mean ... they were already in a private header
or is that going to happen in some future PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I eventually keep two constructors: aws_event_loop_new_default and aws_event_loop_new. aws_event_loop_new_default was used cross the aws-c-io tests to create default event loop. If we remove it, we probably need create help functions in all those test files, therefore I leave it there...

source/exponential_backoff_retry_strategy.c Outdated Show resolved Hide resolved
Comment on lines +132 to +133
AWS_ASSERT(false && "Invalid socket implementation on platform.");
return aws_socket_init_apple_nw_socket(socket, alloc, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this assert(false) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the point of this PR, apple network framework is not supported yet. Added the assertion to warn developer that we should never use this type so far.
I will update the comments to explan it.

source/socket.c Outdated Show resolved Hide resolved
Base automatically changed from EventLoopPublicApi to main November 12, 2024 17:45
@xiazhvera xiazhvera marked this pull request as ready for review November 12, 2024 23:59
* default.
*
* Default Event Loop Type
* Linux | AWS_EVENT_LOOP_EPOLL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Table isn't very well aligned

};

struct aws_event_loop *aws_event_loop_new_iocp_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put an empty line between function decls.

Also I'd drop the 'with_options'. That's not saying anything useful. I'd use 'with_<event_loop_type>' instead (with_dispatch_queue, with_kqueue, etc...)

* `AWS_SOCKET_IMPL_PLATFORM_DEFAULT`, it will automatically use the platform’s default.
*
* PLATFORM DEFAULT SOCKET IMPLEMENTATION TYPE
* Linux | AWS_SOCKET_IMPL_POSIX
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

@@ -145,6 +206,21 @@ aws_ms_fn_ptr aws_winsock_get_connectex_fn(void);
aws_ms_fn_ptr aws_winsock_get_acceptex_fn(void);
#endif

int aws_socket_init_posix(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these in the public API?

@@ -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
Copy link
Contributor

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?

return socket->vtable->socket_is_open_fn(socket);
}

static enum aws_socket_impl_type aws_socket_get_default_impl_type(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just define these in dependency order?

struct aws_byte_buf uuid_buf = aws_byte_buf_from_empty_array(uuid_str, sizeof(uuid_str));
AWS_FATAL_ASSERT(aws_uuid_to_str(&uuid, &uuid_buf) == AWS_OP_SUCCESS);

#if defined(AWS_ENABLE_KQUEUE) || defined(AWS_ENABLE_EPOLL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something feels off about this function using event loop #defines and not default socket type

* Ideally we should use the platform definition (e.x.: AWS_OS_APPLE) here, however the platform
* definition was declared in aws-c-common. We probably do not want to introduce extra dependency here.
*/
#if defined(AWS_ENABLE_KQUEUE) || defined(AWS_ENABLE_EPOLL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elif this sequence, otherwise having multiple types enabled leads to multiple return statements with all but one useless

@@ -172,7 +172,7 @@ static int s_test_event_loop_canceled_tasks_run_in_el_thread(struct aws_allocato

AWS_TEST_CASE(event_loop_canceled_tasks_run_in_el_thread, s_test_event_loop_canceled_tasks_run_in_el_thread)

#if AWS_USE_IO_COMPLETION_PORTS
#if AWS_ENABLE_IO_COMPLETION_PORTS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests that verify failure on mismatch between request type (for both sockets and event loops) and platform would be nice.

@@ -239,6 +270,24 @@ static struct socket_vtable vtables[3][2] = {
},
};

struct aws_socket_vtable g_winsock_vtable = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static, -g_ + s_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants