diff --git a/README.md b/README.md index 36fbad8ed..b4a0f0636 100644 --- a/README.md +++ b/README.md @@ -646,8 +646,7 @@ All exported functions, simply shim into the v-table and return. We include a cross-platform API for sockets. We support TCP and UDP using IPv4 and IPv6, and Unix Domain sockets. On Windows, we use Named Pipes to support the functionality of Unix Domain sockets. On Windows, this is implemented with winsock2, and on -all unix platforms we use the posix API. We can also enable Apple Network Framework along with the Apple Dispatch Queue by setting -the preprocessing flag `AWS_USE_DISPATCH_QUEUE`. Then we will use Apple Network Framework on Apple platforms. +all unix platforms we use the posix API. Then we will use Apple Network Framework on Apple platforms. Upon a connection being established, the new socket (either as the result of a `connect()` or `start_accept()` call) will not be attached to any event loops. It is your responsibility to register it with an event loop to begin receiving diff --git a/include/aws/io/socket.h b/include/aws/io/socket.h index 01c83084c..621fc17e4 100644 --- a/include/aws/io/socket.h +++ b/include/aws/io/socket.h @@ -213,10 +213,9 @@ AWS_IO_API void aws_socket_clean_up(struct aws_socket *socket); * In TCP, LOCAL and VSOCK this function will not block. If the return value is successful, then you must wait on the * `on_connection_result()` callback to be invoked before using the socket. * - * The function will failed with error if the endpoint is invalid. Except for Apple Network Framework (with - * AWS_USE_DISPATCH_QUEUE enabled). In Apple network framework, as connect is an async api, we would not know if the - * local endpoint is valid until we have the connection state returned in callback. The error will returned in - * `on_connection_result` callback + * The function will failed with error if the endpoint is invalid, except for Apple Network Framework. In Apple network + * framework, as connect is an async api, we would not know if the local endpoint is valid until we have the connection + * state returned in callback. The error will returned in `on_connection_result` callback * * If an event_loop is provided for UDP sockets, a notification will be sent on * on_connection_result in the event-loop's thread. Upon completion, the socket will already be assigned diff --git a/source/darwin/dispatch_queue_event_loop.c b/source/darwin/dispatch_queue_event_loop.c index 842357c67..18e8af76b 100644 --- a/source/darwin/dispatch_queue_event_loop.c +++ b/source/darwin/dispatch_queue_event_loop.c @@ -465,7 +465,6 @@ static void s_cancel_task(struct aws_event_loop *event_loop, struct aws_task *ta static int s_connect_to_dispatch_queue(struct aws_event_loop *event_loop, struct aws_io_handle *handle) { (void)event_loop; (void)handle; -#ifdef AWS_USE_DISPATCH_QUEUE AWS_PRECONDITION(handle->set_queue && handle->clear_queue); AWS_LOGF_TRACE( @@ -475,7 +474,6 @@ static int s_connect_to_dispatch_queue(struct aws_event_loop *event_loop, struct (void *)handle->data.handle); struct dispatch_loop *dispatch_loop = event_loop->impl_data; handle->set_queue(handle, dispatch_loop->dispatch_queue); -#endif // #ifdef AWS_USE_DISPATCH_QUEUE return AWS_OP_SUCCESS; } @@ -485,9 +483,7 @@ static int s_unsubscribe_from_io_events(struct aws_event_loop *event_loop, struc "id=%p: un-subscribing from events on handle %p", (void *)event_loop, (void *)handle->data.handle); -#ifdef AWS_USE_DISPATCH_QUEUE handle->clear_queue(handle); -#endif return AWS_OP_SUCCESS; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 78433a950..56bebddd0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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_USE_DISPATCH_QUEUE) +if(NOT AWS_EVENT_LOOP_DISPATCH_QUEUE_OVERRIDE) # 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 diff --git a/tests/socket_test.c b/tests/socket_test.c index 91b0e80ee..f99a765b2 100644 --- a/tests/socket_test.c +++ b/tests/socket_test.c @@ -23,13 +23,6 @@ # include #endif -// DEBUG WIP -#ifdef AWS_USE_DISPATCH_QUEUE -static bool s_use_dispatch_queue = true; -#else -static bool s_use_dispatch_queue = false; -#endif - struct local_listener_args { struct aws_socket *incoming; struct aws_mutex *mutex; @@ -254,7 +247,7 @@ static int s_test_socket_ex( // The Apple Network Framework always require a "start listener/start connection" // for setup a server socket - if (options->type == AWS_SOCKET_STREAM || s_use_dispatch_queue) { + if (options->type == AWS_SOCKET_STREAM || aws_event_loop_get_default_type() == AWS_ELT_DISPATCH_QUEUE) { ASSERT_SUCCESS(aws_socket_listen(&listener, 1024)); ASSERT_SUCCESS(aws_socket_start_accept(&listener, event_loop, s_local_listener_incoming, &listener_args)); } @@ -269,7 +262,7 @@ static int s_test_socket_ex( } ASSERT_SUCCESS(aws_socket_connect(&outgoing, endpoint, event_loop, s_local_outgoing_connection, &outgoing_args)); - if (listener.options.type == AWS_SOCKET_STREAM || s_use_dispatch_queue) { + if (listener.options.type == AWS_SOCKET_STREAM || aws_event_loop_get_default_type() == AWS_ELT_DISPATCH_QUEUE) { ASSERT_SUCCESS(aws_mutex_lock(&mutex)); ASSERT_SUCCESS( aws_condition_variable_wait_pred(&condition_variable, &mutex, s_incoming_predicate, &listener_args)); @@ -282,7 +275,7 @@ static int s_test_socket_ex( struct aws_socket *server_sock = &listener; - if (options->type == AWS_SOCKET_STREAM || s_use_dispatch_queue) { + if (options->type == AWS_SOCKET_STREAM || aws_event_loop_get_default_type() == AWS_ELT_DISPATCH_QUEUE) { ASSERT_TRUE(listener_args.incoming_invoked); ASSERT_FALSE(listener_args.error_invoked); server_sock = listener_args.incoming; @@ -493,7 +486,7 @@ static int s_test_socket_udp_dispatch_queue( ASSERT_SUCCESS(aws_mutex_unlock(&mutex)); ASSERT_INT_EQUALS(AWS_OP_SUCCESS, io_args.error_code); - if (listener.options.type == AWS_SOCKET_STREAM || s_use_dispatch_queue) { + if (listener.options.type == AWS_SOCKET_STREAM || aws_event_loop_get_default_type() == AWS_ELT_DISPATCH_QUEUE) { ASSERT_SUCCESS(aws_mutex_lock(&mutex)); ASSERT_SUCCESS( aws_condition_variable_wait_pred(&condition_variable, &mutex, s_incoming_predicate, &listener_args)); @@ -593,7 +586,7 @@ static int s_test_socket( struct aws_socket_options *options, struct aws_socket_endpoint *endpoint) { - if (s_use_dispatch_queue && options->type == AWS_SOCKET_DGRAM) + if (aws_event_loop_get_default_type() == AWS_ELT_DISPATCH_QUEUE && options->type == AWS_SOCKET_DGRAM) return s_test_socket_udp_dispatch_queue(allocator, options, endpoint); else return s_test_socket_ex(allocator, options, NULL, endpoint); @@ -1056,7 +1049,7 @@ static int s_test_outgoing_local_sock_errors(struct aws_allocator *allocator, vo int socket_connect_result = aws_socket_connect(&outgoing, &endpoint, event_loop, s_null_sock_connection, &args); // As Apple network framework has a async API design, we would not get the error back on connect - if (!s_use_dispatch_queue) { + if(aws_event_loop_get_default_type() != AWS_ELT_DISPATCH_QUEUE){ ASSERT_FAILS(socket_connect_result); ASSERT_TRUE( aws_last_error() == AWS_IO_SOCKET_CONNECTION_REFUSED || aws_last_error() == AWS_ERROR_FILE_INVALID_PATH); @@ -1270,7 +1263,7 @@ static int s_test_bind_on_zero_port( ASSERT_SUCCESS(aws_socket_get_bound_address(&incoming, &local_address1)); - if (s_use_dispatch_queue) { + if (aws_event_loop_get_default_type() == AWS_ELT_DISPATCH_QUEUE) { struct aws_mutex mutex = AWS_MUTEX_INIT; struct aws_condition_variable condition_variable = AWS_CONDITION_VARIABLE_INIT;