1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

IPv4: Basic implementation of TCP socket shutdown

We can now participate in the TCP connection closing handshake. :^)
This implementation is definitely not complete and needs to handle a
bunch of other cases. But it's a huge improvement over not being able
to close connections at all.

Note that we hold on to pending-close sockets indefinitely, until they
are moved into the Closed state. This should also have a timeout but
that's still a FIXME. :^)

Fixes #428.
This commit is contained in:
Andreas Kling 2020-02-08 15:52:32 +01:00
parent 8325662186
commit 228a1e9099
7 changed files with 69 additions and 8 deletions

View file

@ -165,7 +165,13 @@ KResult Socket::shutdown(int how)
{
if (type() == SOCK_STREAM && !is_connected())
return KResult(-ENOTCONN);
m_shut_down_for_reading |= how & SHUT_RD;
m_shut_down_for_writing |= how & SHUT_WR;
if (m_role == Role::Listener)
return KResult(-ENOTCONN);
if (!m_shut_down_for_writing && (how & SHUT_WR))
shut_down_for_writing();
if (!m_shut_down_for_reading && (how & SHUT_RD))
shut_down_for_reading();
m_shut_down_for_reading |= (how & SHUT_RD) != 0;
m_shut_down_for_writing |= (how & SHUT_WR) != 0;
return KSuccess;
}