Skip to content

Conversation

@sbSteveK
Copy link
Contributor

Apple Network Framework socket integration

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xiazhvera
Copy link
Contributor

The main changes since last code review:

  1. Improve the locks. Now the socket has 2 locks, (a) lock for base_socket (to avoid bad access after aws_socket_cleanup() is called) (b) lock for synced_data including socket_state and read_scheduled.
  2. Remove aws_server_bootstrap_new_socket_listener_async , now aws_server_bootstrap_new_socket_listener will asynchronously invoke the setup_callback when the listener is ready for use, if setup_callback is set.

socket->io_handle.data.fd);
}

struct on_start_accept_result_args {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if it's worth de-duping this across posix/windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to the private header, I'm not sure if that's better either though 🤔

struct nw_socket_scheduled_task_args *task_args = arg;
struct nw_socket *nw_socket = task_args->nw_socket;

AWS_LOGF_TRACE(AWS_LS_IO_SOCKET, "id=%p: start to process connection result task.", (void *)nw_socket);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connection/listener state changes would be better as debug I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the state_change log to debug. For this specific line, since the function is invoking the connection result callback, I think trace would be a good to track for this callback.

if (nw_socket->on_accept_started_fn) {
nw_socket->on_accept_started_fn(aws_socket, crt_error_code, nw_socket->listen_accept_started_user_data);
}
s_unlock_base_socket(nw_socket);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance that something in the accept started callback could invoke something that tries to lock the socket base?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base socket is only modified(write) at two places:
(1) socket creation/init : The lock is just inited, and would not hold at this time.
(2) aws_socket_cleanup(): This is where the base socket get nulled out. We only lock the base socket if the function is not on the event loop to avoid dead lock. Use this callback as an example, if we call aws_socket_cleanup() in on_accept_started_fn, as it is on the event loop, we will not lock the base socket here.

aws_socket_set_cleanup_complete_callback(
socket, s_socket_shutdown_complete_setup_connection_args_fn, close_args);

SETUP_SOCKET_SHUTDOWN_CALLBACKS(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I feel like the macro provides any readability improvement.

@xiazhvera xiazhvera merged commit 43f1822 into grand_dispatch_queue Mar 17, 2025
49 checks passed
@xiazhvera xiazhvera deleted the nw_socket branch March 17, 2025 17:14
@xiazhvera xiazhvera restored the nw_socket branch March 17, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants