diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-08 21:41:46 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-08 21:44:50 +0200 |
commit | 9bb0374d7de30817dff619947fab8f2b38344876 (patch) | |
tree | 74f558e60f2da7d83e0ef0cbbe2f991dac8c5538 | |
parent | 3aa27b5b0e95b8fb975497a2777bc26cd9bf2811 (diff) | |
download | serenity-9bb0374d7de30817dff619947fab8f2b38344876.zip |
Kernel: Delay moving accepted sockets to SetupState::Completed a bit
Make sure we don't move accepted sockets to the Completed setup state
until we've actually constructed a FileDescription for them.
This is important, since this state transition will trigger connect()
to unblock on the client side, and the client may try writing to the
socket right away.
This makes DNS lookups way more reliable since we don't just fail to
write() right after connect()ing to LookupServer sometimes. :^)
-rw-r--r-- | Kernel/Net/Socket.cpp | 1 | ||||
-rw-r--r-- | Kernel/Process.cpp | 3 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 91d5bc31cb..0749d0ee2e 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -65,7 +65,6 @@ RefPtr<Socket> Socket::accept() auto client = m_pending.take_first(); ASSERT(!client->is_connected()); client->m_acceptor_pid = m_origin_pid; - client->set_setup_state(SetupState::Completed); client->m_connected = true; client->m_role = Role::Accepted; return client; diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 221fe8f635..8a122fb1db 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2351,6 +2351,9 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a // I'm not sure if this matches other systems but it makes sense to me. accepted_socket_description->set_blocking(accepting_socket_description->is_blocking()); m_fds[accepted_socket_fd].set(move(accepted_socket_description), m_fds[accepting_socket_fd].flags); + + // NOTE: Moving this state to Completed is what causes connect() to unblock on the client side. + accepted_socket->set_setup_state(Socket::SetupState::Completed); return accepted_socket_fd; } |