diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2019-08-11 16:28:18 +0300 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-11 16:30:43 +0200 |
commit | d46c3b0b5bc196bb987d3c77855be678849e2e09 (patch) | |
tree | 92714fa43c348133fcdce48841f478fc5ef3cb5f /Kernel/Net/LocalSocket.cpp | |
parent | 1606261c58599328ed509c356ca106b9dda59b95 (diff) | |
download | serenity-d46c3b0b5bc196bb987d3c77855be678849e2e09.zip |
Net: Simplify how LocalSocket tracks open fds
Now that there can't be multiple clones of the same fd,
we only need to track whether or not an fd exists on each
side. Also there's no point in tracking connecting fds.
Diffstat (limited to 'Kernel/Net/LocalSocket.cpp')
-rw-r--r-- | Kernel/Net/LocalSocket.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 1309c77078..f4e1377134 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -131,16 +131,17 @@ KResult LocalSocket::listen(int backlog) void LocalSocket::attach(FileDescription& description) { + ASSERT(!m_accept_side_fd_open); switch (description.socket_role()) { + case SocketRole::None: + ASSERT(!m_connect_side_fd_open); + m_connect_side_fd_open = true; + break; case SocketRole::Accepted: - ++m_accepted_fds_open; + m_accept_side_fd_open = true; break; case SocketRole::Connected: - ++m_connected_fds_open; - break; - case SocketRole::Connecting: - ++m_connecting_fds_open; - break; + ASSERT_NOT_REACHED(); default: break; } @@ -149,17 +150,18 @@ void LocalSocket::attach(FileDescription& description) void LocalSocket::detach(FileDescription& description) { switch (description.socket_role()) { + case SocketRole::None: + ASSERT(!m_accept_side_fd_open); + ASSERT(m_connect_side_fd_open); + m_connect_side_fd_open = false; + break; case SocketRole::Accepted: - ASSERT(m_accepted_fds_open); - --m_accepted_fds_open; + ASSERT(m_accept_side_fd_open); + m_accept_side_fd_open = false; break; case SocketRole::Connected: - ASSERT(m_connected_fds_open); - --m_connected_fds_open; - break; - case SocketRole::Connecting: - ASSERT(m_connecting_fds_open); - --m_connecting_fds_open; + ASSERT(m_connect_side_fd_open); + m_connect_side_fd_open = false; break; default: break; @@ -181,9 +183,9 @@ bool LocalSocket::can_read(FileDescription& description) const bool LocalSocket::has_attached_peer(const FileDescription& description) const { if (description.socket_role() == SocketRole::Accepted) - return m_connected_fds_open || m_connecting_fds_open; + return m_connect_side_fd_open; if (description.socket_role() == SocketRole::Connected) - return m_accepted_fds_open; + return m_accept_side_fd_open; ASSERT_NOT_REACHED(); } |