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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9d97302
Checkpoint
bretambrose Oct 30, 2024
9781845
Updated with doc comments
Oct 31, 2024
754c56d
Creation API
Oct 31, 2024
974a9b2
Checkpoint
Nov 5, 2024
0b7b061
Merge branch 'main' into EventLoopPublicApi
Nov 5, 2024
75e4f45
Formatting
Nov 5, 2024
4a784cc
Oops
Nov 5, 2024
381f3dd
Windows updates
Nov 5, 2024
e63c0a8
test update
Nov 5, 2024
09cff00
[WIP] API update for runtime switch event loop
xiazhvera Nov 7, 2024
ca3a134
update event loop group creation
xiazhvera Nov 7, 2024
6619695
clang format
xiazhvera Nov 7, 2024
7a89d9e
revert shutdown_types?
xiazhvera Nov 7, 2024
56fa4d1
rename cmake flags
xiazhvera Nov 7, 2024
c1a4971
fix default event loop
xiazhvera Nov 7, 2024
470164b
improve error message
xiazhvera Nov 7, 2024
9e6d574
Update based on PR feedback:
Nov 7, 2024
d8f5fdd
Merge branch 'EventLoopPublicApi' of github.com:awslabs/aws-c-io into…
xiazhvera Nov 7, 2024
9323cc3
Make io testing channel usable across library boundaries
Nov 7, 2024
b771d8c
Revert "Make io testing channel usable across library boundaries"
Nov 7, 2024
4f3048e
add function to override the default event loop type
xiazhvera Nov 7, 2024
fcb3d9a
Revert "Revert "Make io testing channel usable across library boundar…
Nov 8, 2024
9b16a3b
Set allocator
Nov 8, 2024
a30cd39
default event loop type override
xiazhvera Nov 8, 2024
74733ad
hide the test help function as internal private
xiazhvera Nov 8, 2024
558d179
clang format
xiazhvera Nov 8, 2024
16d4e25
remove unreachable..
xiazhvera Nov 8, 2024
7cb0936
update cmake for dispatch queue
xiazhvera Nov 8, 2024
e84a1a6
introduce socket vtable
xiazhvera Nov 8, 2024
d79b5b7
fix platform error code
xiazhvera Nov 8, 2024
3ce216c
remove global vtable
xiazhvera Nov 9, 2024
6233c9d
fix flag
xiazhvera Nov 9, 2024
0f75185
set apple networkframework flag
xiazhvera Nov 9, 2024
f7fb5a2
prevent fail fast
xiazhvera Nov 9, 2024
16861b9
update cmake event loop defines
xiazhvera Nov 9, 2024
17c7cca
temporary remove dispatch queue wrap
xiazhvera Nov 9, 2024
d68acdb
Doc comments
bretambrose Nov 11, 2024
3999196
make apple network framework public
xiazhvera Nov 11, 2024
6f1984c
Merge branch 'EventLoopPublicApi' of github.com:awslabs/aws-c-io into…
xiazhvera Nov 11, 2024
8d84d11
Apply suggestions from code review
xiazhvera Nov 11, 2024
71fae6f
update cr changes
xiazhvera Nov 11, 2024
35efc2e
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 11, 2024
405c988
rename enum
xiazhvera Nov 12, 2024
e614bdc
Merge branch 'main' of github.com:awslabs/aws-c-io into runtime_selec…
xiazhvera Nov 12, 2024
e22131a
Merge branch 'main' into runtime_select_event_loop
xiazhvera Nov 12, 2024
51e2d5a
eliminate event loop constructor
xiazhvera Nov 12, 2024
8be6cd2
clean up and format
xiazhvera Nov 12, 2024
ab05a35
Merge branch 'main' into runtime_select_event_loop
xiazhvera Nov 12, 2024
61cbc90
lint
xiazhvera Nov 12, 2024
4d0e12c
Merge branch 'runtime_select_event_loop' of github.com:awslabs/aws-c-…
xiazhvera Nov 12, 2024
7b51b56
wrap the kqueue function
xiazhvera Nov 12, 2024
aa876a1
add posix file for non-darwin Apple platform
xiazhvera Nov 12, 2024
ee7fa76
fix lint
xiazhvera Nov 12, 2024
2fb32ab
handling library error in cmake
xiazhvera Nov 12, 2024
f5a5338
Merge branch 'main' into runtime_select_event_loop
xiazhvera Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,16 @@ jobs:

macos:
runs-on: macos-14 # latest
strategy:
fail-fast: false
matrix:
eventloop: ["-DAWS_USE_APPLE_NETWORK_FRAMEWORK=ON", "-DAWS_USE_APPLE_NETWORK_FRAMEWORK=OFF"]
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}
./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=${{ matrix.eventloop }}

macos-x64:
runs-on: macos-14-large # latest
Expand All @@ -176,12 +180,16 @@ jobs:

macos-debug:
runs-on: macos-14 # latest
strategy:
fail-fast: false
matrix:
eventloop: ["-DAWS_USE_APPLE_NETWORK_FRAMEWORK=ON", "-DAWS_USE_APPLE_NETWORK_FRAMEWORK=OFF"]
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }} --config Debug
./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=${{ matrix.eventloop }} --config Debug

freebsd:
runs-on: ubuntu-22.04 # latest
Expand Down
32 changes: 23 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if (WIN32)
)
list(APPEND AWS_IO_OS_SRC ${AWS_IO_IOCP_SRC})

set(EVENT_LOOP_DEFINE "IO_COMPLETION_PORTS")
list(APPEND EVENT_LOOP_DEFINES "IO_COMPLETION_PORTS")
endif ()

if (MSVC)
Expand All @@ -102,7 +102,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Androi
)
set(PLATFORM_LIBS "")

set(EVENT_LOOP_DEFINE "EPOLL")
list(APPEND EVENT_LOOP_DEFINES "EPOLL")
set(USE_S2N ON)

elseif (APPLE)
Expand All @@ -117,13 +117,18 @@ elseif (APPLE)
)

find_library(SECURITY_LIB Security)
if (NOT SECURITY_LIB)
message(FATAL_ERROR "Security framework not found")
find_library(NETWORK_LIB Network)

# Enable dispatch queue if the libraries are avaliable
if (NETWORK_LIB AND SECURITY_LIB)
list(APPEND PLATFORM_LIBS "-framework Security -framework Network")
list(APPEND EVENT_LOOP_DEFINES "DISPATCH_QUEUE")
endif ()

#No choice on TLS for apple, darwinssl will always be used.
list(APPEND PLATFORM_LIBS "-framework Security")
set(EVENT_LOOP_DEFINE "KQUEUE")
# Enable KQUEUE on MacOS
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND EVENT_LOOP_DEFINES "KQUEUE")
endif()

elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
file(GLOB AWS_IO_OS_HEADERS
Expand All @@ -134,7 +139,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetB
"source/posix/*.c"
)

set(EVENT_LOOP_DEFINE "KQUEUE")
list(APPEND EVENT_LOOP_DEFINES "KQUEUE")
set(USE_S2N ON)

endif()
Expand Down Expand Up @@ -187,7 +192,12 @@ aws_add_sanitizers(${PROJECT_NAME})
# We are not ABI stable yet
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION 1.0.0)

target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_USE_${EVENT_LOOP_DEFINE}")
if (NOT EVENT_LOOP_DEFINES)
message(FATAL_ERROR "Event Loop is not setup on the platform.")
endif()
foreach(EVENT_LOOP_DEFINE IN LISTS EVENT_LOOP_DEFINES)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_ENABLE_${EVENT_LOOP_DEFINE}")
endforeach()

if (BYO_CRYPTO)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DBYO_CRYPTO")
Expand All @@ -205,6 +215,10 @@ if (USE_VSOCK)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DUSE_VSOCK")
endif()

if (AWS_USE_APPLE_NETWORK_FRAMEWORK)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_USE_APPLE_NETWORK_FRAMEWORK")
endif()

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
Expand Down
26 changes: 26 additions & 0 deletions include/aws/io/event_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AWS_PUSH_SANE_WARNING_LEVEL

struct aws_event_loop;
struct aws_event_loop_group;
struct aws_event_loop_options;
struct aws_shutdown_callback_options;
struct aws_task;

Expand Down Expand Up @@ -47,6 +48,25 @@ struct aws_event_loop_vtable {
bool (*is_on_callers_thread)(struct aws_event_loop *event_loop);
};

/**
* Event Loop Type. If set to `AWS_EVENT_LOOP_PLATFORM_DEFAULT`, the event loop will automatically use the platform’s
* 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

* Windows | AWS_EVENT_LOOP_IOCP
* BSD Variants| AWS_EVENT_LOOP_KQUEUE
* MacOS | AWS_EVENT_LOOP_KQUEUE
* iOS | AWS_EVENT_LOOP_DISPATCH_QUEUE
*/
enum aws_event_loop_type {
AWS_EVENT_LOOP_PLATFORM_DEFAULT = 0,
AWS_EVENT_LOOP_EPOLL,
AWS_EVENT_LOOP_IOCP,
AWS_EVENT_LOOP_KQUEUE,
AWS_EVENT_LOOP_DISPATCH_QUEUE,
};

/**
* Event loop group configuration options
*/
Expand All @@ -58,6 +78,12 @@ struct aws_event_loop_group_options {
*/
uint16_t loop_count;

/**
* Event loop type. If the event loop type is set to AWS_EVENT_LOOP_PLATFORM_DEFAULT, the
* creation function will automatically use the platform’s default event loop type.
*/
enum aws_event_loop_type type;

/**
* Optional callback to invoke when the event loop group finishes destruction.
*/
Expand Down
30 changes: 22 additions & 8 deletions include/aws/io/private/event_loop_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,27 @@ struct aws_event_loop_local_object {
struct aws_event_loop_options {
aws_io_clock_fn *clock;
struct aws_thread_options *thread_options;

/**
* Event loop type. If the event loop type is set to AWS_EVENT_LOOP_PLATFORM_DEFAULT, the
* creation function will automatically use the platform’s default event loop type.
*/
enum aws_event_loop_type type;
};

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...)

struct aws_event_loop *aws_event_loop_new_dispatch_queue_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
struct aws_event_loop *aws_event_loop_new_kqueue_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
struct aws_event_loop *aws_event_loop_new_epoll_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);

typedef struct aws_event_loop *(aws_new_event_loop_fn)(struct aws_allocator *alloc,
const struct aws_event_loop_options *options,
void *new_loop_user_data);
Expand All @@ -105,7 +124,7 @@ struct aws_event_loop_group {

AWS_EXTERN_C_BEGIN

#ifdef AWS_USE_IO_COMPLETION_PORTS
#ifdef AWS_ENABLE_IO_COMPLETION_PORTS

/**
* Prepares aws_overlapped for use, and sets a function to call when the overlapped operation completes.
Expand All @@ -128,6 +147,7 @@ void aws_overlapped_reset(struct aws_overlapped *overlapped);
*/
AWS_IO_API
struct _OVERLAPPED *aws_overlapped_to_windows_overlapped(struct aws_overlapped *overlapped);
#endif /* AWS_ENABLE_IO_COMPLETION_PORTS */

/**
* Associates an aws_io_handle with the event loop's I/O Completion Port.
Expand All @@ -144,8 +164,6 @@ int aws_event_loop_connect_handle_to_io_completion_port(
struct aws_event_loop *event_loop,
struct aws_io_handle *handle);

#else

/**
* Subscribes on_event to events on the event-loop for handle. events is a bitwise concatenation of the events that were
* received. The definition for these values can be found in aws_io_event_type. Currently, only
Expand All @@ -161,8 +179,6 @@ int aws_event_loop_subscribe_to_io_events(
aws_event_loop_on_event_fn *on_event,
void *user_data);

#endif /* AWS_USE_IO_COMPLETION_PORTS */

/**
* Creates an instance of the default event loop implementation for the current architecture and operating system.
*/
Expand All @@ -174,9 +190,7 @@ struct aws_event_loop *aws_event_loop_new_default(struct aws_allocator *alloc, a
* extendable options.
*/
AWS_IO_API
struct aws_event_loop *aws_event_loop_new_default_with_options(
struct aws_allocator *alloc,
const struct aws_event_loop_options *options);
struct aws_event_loop *aws_event_loop_new(struct aws_allocator *alloc, const struct aws_event_loop_options *options);

/**
* Initializes common event-loop data structures.
Expand Down
Loading
Loading