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

Implement event loop based on QNX ionotify #669

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
aa4f966
Provide I/O operation status back to event loop
sfodagain Aug 26, 2024
abe7747
Add flag for last io result
sfodagain Aug 26, 2024
ce39822
Merge branch 'main' into support-qnx
sfodagain Aug 27, 2024
8f7cbff
Add callback to io handle
sfodagain Aug 27, 2024
50bca0d
Revert unrelated changes
sfodagain Aug 27, 2024
29d9c04
Use shared sources
sfodagain Aug 27, 2024
ad1262d
fixup
sfodagain Aug 27, 2024
28e55e1
fixup
sfodagain Aug 27, 2024
c5f9e00
Use #if everywhere
sfodagain Aug 27, 2024
4ed5a87
Fix kqueue
sfodagain Aug 27, 2024
619319f
Fix pipe tests
sfodagain Aug 27, 2024
be85d89
Remove AWS_ASSERT, use AWS_ZERO_STRUCT
sfodagain Sep 3, 2024
739e0f6
Remove changes made to kqueue
sfodagain Sep 16, 2024
4036be9
Add ionotify event loop (#670)
sfod Sep 16, 2024
d709f28
Remove pipe test fix
sfodagain Sep 16, 2024
d8a8085
Copy posix stuff to qnx
sfodagain Sep 16, 2024
702312a
fixup
sfodagain Sep 17, 2024
eede270
fixup
sfodagain Sep 17, 2024
8bc5d1b
Fix pipe missing events issue
sfodagain Sep 17, 2024
692d125
Handle unsubscribing in a task
sfodagain Sep 17, 2024
c79772e
Handle is_subscribed only in resubscriptions
sfodagain Sep 17, 2024
2bddf95
Add aws_pipe_read to tests
sfodagain Sep 17, 2024
dd34f87
Fix race condition, fix pulse error code
sfodagain Sep 20, 2024
c4dceea
Use separate task for resubscribing
sfodagain Sep 20, 2024
29f900e
Add QNX paths
sfodagain Sep 20, 2024
a8d8366
Remove non-qnx specifics from posix copies
sfodagain Sep 23, 2024
6af39ec
Improve comments and logging
sfodagain Sep 23, 2024
9c35c72
Fix latest_io_event_types
sfodagain Sep 23, 2024
bc653f6
Fix format
sfodagain Sep 23, 2024
48134e8
Merge posix and qnx sources
sfodagain Sep 24, 2024
4b59301
Fix naming and comments
sfodagain Sep 25, 2024
1700c76
Use single destroy
sfodagain Sep 25, 2024
88aff4d
Use atomic for event loop state
sfodagain Sep 26, 2024
78b4d38
Use AWS_FATAL_ASSERT
sfodagain Sep 26, 2024
22f3e24
Fix log format string
sfodagain Sep 26, 2024
52110fb
Remove strerror
sfodagain Sep 26, 2024
93c0c39
Add MsgUnregisterEvent on unsubscribing
sfodagain Sep 26, 2024
477a071
Fix logs, comments, code style
sfodagain Sep 26, 2024
bda976c
Fix naming
sfodagain Sep 26, 2024
be74788
Refactor cleaning up and resubscribing
sfodagain Sep 29, 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
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetB
set(EVENT_LOOP_DEFINE "KQUEUE")
set(USE_S2N ON)

elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX")
file(GLOB AWS_IO_OS_SRC
"source/qnx/*.c"
)
set(EVENT_LOOP_DEFINE "ON_EVENT_WITH_RESULT")
set(USE_S2N ON)
list(APPEND PLATFORM_LIBS "socket")
endif()

if (BYO_CRYPTO)
Expand Down Expand Up @@ -231,7 +238,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${LIBRARY_DIRECTORY}/${PROJECT_NAME}/cmake/"
COMPONENT Development)

if (NOT CMAKE_CROSSCOMPILING)
if (NOT CMAKE_CROSSCOMPILING OR AWS_BUILD_QNX_TESTS)
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
Expand Down
28 changes: 28 additions & 0 deletions include/aws/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,40 @@ AWS_PUSH_SANE_WARNING_LEVEL

#define AWS_C_IO_PACKAGE_ID 1

struct aws_io_handle;

#if AWS_USE_ON_EVENT_WITH_RESULT
struct aws_event_loop;

/**
* Results of the I/O operation(s) performed on the aws_io_handle.
*/
struct aws_io_handle_io_op_result {
size_t read_bytes;
size_t written_bytes;
/** Error codes representing generic errors happening on I/O handles. */
int error_code;
/** Error codes specific to reading operations. */
int read_error_code;
bretambrose marked this conversation as resolved.
Show resolved Hide resolved
/** Error codes specific to writing operations. */
int write_error_code;
};

typedef void(aws_io_handle_update_io_results_fn)(
struct aws_event_loop *,
struct aws_io_handle *,
const struct aws_io_handle_io_op_result *);
#endif /* AWS_USE_ON_EVENT_WITH_RESULT */

struct aws_io_handle {
union {
int fd;
void *handle;
} data;
void *additional_data;
#if AWS_USE_ON_EVENT_WITH_RESULT
aws_io_handle_update_io_results_fn *update_io_result;
#endif /* AWS_USE_ON_EVENT_WITH_RESULT */
};

enum aws_io_message_type {
Expand Down
114 changes: 114 additions & 0 deletions source/qnx/host_resolver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/io/host_resolver.h>

#include <aws/io/logging.h>

#include <aws/common/string.h>

#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>

int aws_default_dns_resolve(
struct aws_allocator *allocator,
const struct aws_string *host_name,
struct aws_array_list *output_addresses,
void *user_data) {

(void)user_data;
struct addrinfo *result = NULL;
struct addrinfo *iter = NULL;
/* max string length for ipv6. */
socklen_t max_len = INET6_ADDRSTRLEN;
char address_buffer[max_len];

const char *hostname_cstr = aws_string_c_str(host_name);
AWS_LOGF_DEBUG(AWS_LS_IO_DNS, "static: resolving host %s", hostname_cstr);

struct addrinfo hints;
AWS_ZERO_STRUCT(hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ALL | AI_V4MAPPED;

int err_code = getaddrinfo(hostname_cstr, NULL, &hints, &result);

if (err_code) {
AWS_LOGF_ERROR(
AWS_LS_IO_DNS, "static: getaddrinfo failed with error_code %d: %s", err_code, gai_strerror(err_code));
goto clean_up;
}

for (iter = result; iter != NULL; iter = iter->ai_next) {
struct aws_host_address host_address;

AWS_ZERO_ARRAY(address_buffer);

if (iter->ai_family == AF_INET6) {
host_address.record_type = AWS_ADDRESS_RECORD_TYPE_AAAA;
inet_ntop(iter->ai_family, &((struct sockaddr_in6 *)iter->ai_addr)->sin6_addr, address_buffer, max_len);
} else {
host_address.record_type = AWS_ADDRESS_RECORD_TYPE_A;
inet_ntop(iter->ai_family, &((struct sockaddr_in *)iter->ai_addr)->sin_addr, address_buffer, max_len);
}

size_t address_len = strlen(address_buffer);
const struct aws_string *address =
aws_string_new_from_array(allocator, (const uint8_t *)address_buffer, address_len);

if (!address) {
goto clean_up;
}

const struct aws_string *host_cpy = aws_string_new_from_string(allocator, host_name);

if (!host_cpy) {
aws_string_destroy((void *)address);
goto clean_up;
}

AWS_LOGF_DEBUG(AWS_LS_IO_DNS, "static: resolved record: %s", address_buffer);

host_address.address = address;
host_address.weight = 0;
host_address.allocator = allocator;
host_address.use_count = 0;
host_address.connection_failure_count = 0;
host_address.host = host_cpy;

if (aws_array_list_push_back(output_addresses, &host_address)) {
aws_host_address_clean_up(&host_address);
goto clean_up;
}
}

freeaddrinfo(result);
return AWS_OP_SUCCESS;

clean_up:
if (result) {
freeaddrinfo(result);
}

if (err_code) {
switch (err_code) {
case EAI_FAIL:
case EAI_AGAIN:
return aws_raise_error(AWS_IO_DNS_QUERY_FAILED);
case EAI_MEMORY:
return aws_raise_error(AWS_ERROR_OOM);
case EAI_NONAME:
case EAI_SERVICE:
return aws_raise_error(AWS_IO_DNS_INVALID_NAME);
default:
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
}
}

return AWS_OP_ERR;
}
Loading