From 28b75463aa88b891ad19c240429a94f2ffd08ee4 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Fri, 8 Nov 2024 17:52:01 -0800 Subject: [PATCH] update socket api changes for network framework --- source/darwin/nw_socket.c | 21 --------------------- source/socket.c | 5 +++++ tests/CMakeLists.txt | 6 +++--- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/source/darwin/nw_socket.c b/source/darwin/nw_socket.c index a54367aa5..25fd09750 100644 --- a/source/darwin/nw_socket.c +++ b/source/darwin/nw_socket.c @@ -1587,24 +1587,3 @@ static bool s_socket_is_open_fn(struct aws_socket *socket) { return nw_socket->last_error == AWS_OP_SUCCESS; } -void aws_socket_endpoint_init_local_address_for_test(struct aws_socket_endpoint *endpoint) { - struct aws_uuid uuid; - AWS_FATAL_ASSERT(aws_uuid_init(&uuid) == AWS_OP_SUCCESS); - char uuid_str[AWS_UUID_STR_LEN] = {0}; - 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); - snprintf(endpoint->address, sizeof(endpoint->address), "testsock" PRInSTR ".local", AWS_BYTE_BUF_PRI(uuid_buf)); -} - -int aws_socket_get_bound_address(const struct aws_socket *socket, struct aws_socket_endpoint *out_address) { - if (socket->local_endpoint.address[0] == 0) { - AWS_LOGF_ERROR( - AWS_LS_IO_SOCKET, - "id=%p fd=%d: Socket has no local address. Socket must be bound first.", - (void *)socket, - socket->io_handle.data.fd); - return aws_raise_error(AWS_IO_SOCKET_ILLEGAL_OPERATION_FOR_STATE); - } - *out_address = socket->local_endpoint; - return AWS_OP_SUCCESS; -} diff --git a/source/socket.c b/source/socket.c index a1fb739c1..ed5c1a762 100644 --- a/source/socket.c +++ b/source/socket.c @@ -160,6 +160,11 @@ void aws_socket_endpoint_init_local_address_for_test(struct aws_socket_endpoint 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(WS_USE_APPLE_NETWORK_FRAMEWORK) + snprintf(endpoint->address, sizeof(endpoint->address), "testsock" PRInSTR ".local", AWS_BYTE_BUF_PRI(uuid_buf)); + return; +#endif + #if defined(AWS_ENABLE_KQUEUE) || defined(AWS_ENABLE_EPOLL) snprintf(endpoint->address, sizeof(endpoint->address), "testsock" PRInSTR ".sock", AWS_BYTE_BUF_PRI(uuid_buf)); return; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 56bebddd0..f96080aee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,7 +18,7 @@ add_test_case(io_library_init) add_test_case(io_library_init_cleanup_init_cleanup) # Dispatch Queue does not support pipe -if(NOT AWS_EVENT_LOOP_DISPATCH_QUEUE_OVERRIDE) +if(NOT AWS_USE_APPLE_NETWORK_FRAMEWORK) add_pipe_test_case(pipe_open_close) add_pipe_test_case(pipe_read_write) add_pipe_test_case(pipe_read_write_large_buffer) @@ -39,7 +39,7 @@ add_test_case(event_loop_canceled_tasks_run_in_el_thread) if(USE_IO_COMPLETION_PORTS) add_test_case(event_loop_completion_events) -elseif(NOT AWS_EVENT_LOOP_DISPATCH_QUEUE_OVERRIDE) # Dispatch Queue does not support pipe +elseif(NOT AWS_USE_APPLE_NETWORK_FRAMEWORK) # Dispatch Queue does not support pipe add_test_case(event_loop_subscribe_unsubscribe) add_test_case(event_loop_writable_event_on_subscribe) add_test_case(event_loop_no_readable_event_before_write) @@ -83,7 +83,7 @@ add_test_case(cleanup_in_write_cb_doesnt_explode) add_test_case(sock_write_cb_is_async) add_test_case(socket_validate_port) -if(NOT AWS_EVENT_LOOP_DISPATCH_QUEUE_OVERRIDE) +if(NOT AWS_USE_APPLE_NETWORK_FRAMEWORK) # Apple Network Framework does not support bind+connect add_test_case(udp_bind_connect_communication) # The read/write will always run a different thread for Apple Network Framework