From 8d84d1162e77293c60957588865d62f14a515c23 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Mon, 11 Nov 2024 13:38:28 -0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Michael Graeb --- include/aws/io/socket.h | 2 +- source/event_loop.c | 13 ++++--------- source/socket.c | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/aws/io/socket.h b/include/aws/io/socket.h index ab295b576..7351525a5 100644 --- a/include/aws/io/socket.h +++ b/include/aws/io/socket.h @@ -99,7 +99,7 @@ typedef void(aws_socket_on_connection_result_fn)(struct aws_socket *socket, int * A user may want to call aws_socket_set_options() on the new socket if different options are desired. * * new_socket is not yet assigned to an event-loop. The user should call aws_socket_assign_to_event_loop() before - * performing IO operations. The user is responsible to releasing the socket memory after use. + * performing IO operations. The user must call `aws_socket_release()` when they're done with the socket, to free it. * * When error_code is AWS_ERROR_SUCCESS, new_socket is the recently accepted connection. * If error_code is non-zero, an error occurred and you should aws_socket_close() the socket. diff --git a/source/event_loop.c b/source/event_loop.c index 867eb7591..3b05fc3ba 100644 --- a/source/event_loop.c +++ b/source/event_loop.c @@ -57,23 +57,17 @@ struct aws_event_loop *aws_event_loop_new_with_options( switch (type) { case AWS_ELT_EPOLL: return aws_event_loop_new_epoll_with_options(alloc, options); - break; case AWS_ELT_IOCP: return aws_event_loop_new_iocp_with_options(alloc, options); - break; case AWS_ELT_KQUEUE: return aws_event_loop_new_kqueue_with_options(alloc, options); - break; case AWS_ELT_DISPATCH_QUEUE: return aws_event_loop_new_dispatch_queue_with_options(alloc, options); - break; default: AWS_LOGF_DEBUG(AWS_LS_IO_EVENT_LOOP, "Invalid event loop type on the platform."); aws_raise_error(AWS_ERROR_PLATFORM_NOT_SUPPORTED); - break; + return NULL; } - - return NULL; } static void s_event_loop_group_thread_exit(void *user_data) { @@ -547,10 +541,11 @@ int aws_event_loop_current_clock_time(struct aws_event_loop *event_loop, uint64_ * AWS_ELT_PLATFORM_DEFAULT. */ void aws_event_loop_override_default_type(enum aws_event_loop_type default_type_override) { - if (aws_event_loop_type_validate_platform(default_type_override)) { + if (aws_event_loop_type_validate_platform(default_type_override) == AWS_OP_SUCCESS) { + s_default_event_loop_type_override = default_type_override; + } else { s_default_event_loop_type_override = AWS_ELT_PLATFORM_DEFAULT; } - s_default_event_loop_type_override = default_type_override; } /** diff --git a/source/socket.c b/source/socket.c index c4a8e9759..f7eb77520 100644 --- a/source/socket.c +++ b/source/socket.c @@ -116,7 +116,7 @@ int aws_socket_init(struct aws_socket *socket, struct aws_allocator *alloc, cons if (aws_socket_impl_type_validate_platform(type)) { AWS_LOGF_DEBUG(AWS_LS_IO_SOCKET, "Invalid event loop type on the platform."); - return AWS_ERROR_PLATFORM_NOT_SUPPORTED; + return aws_raise_error(AWS_ERROR_PLATFORM_NOT_SUPPORTED); } // 2. setup vtable based on socket type