mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 18:55:08 +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:
parent
8325662186
commit
228a1e9099
7 changed files with 69 additions and 8 deletions
|
@ -572,6 +572,9 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
|
|||
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
|
||||
socket->set_state(TCPSocket::State::TimeWait);
|
||||
return;
|
||||
case TCPFlags::ACK | TCPFlags::RST:
|
||||
socket->set_state(TCPSocket::State::Closed);
|
||||
return;
|
||||
default:
|
||||
kprintf("handle_tcp: unexpected flags in FinWait2 state\n");
|
||||
socket->send_tcp_packet(TCPFlags::RST);
|
||||
|
@ -596,12 +599,8 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
|
|||
socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
|
||||
|
||||
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
|
||||
// TODO: We should only send a FIN packet out once we're shutting
|
||||
// down our side of the socket, so we should change this back to
|
||||
// just being an ACK and a transition to CloseWait once we have a
|
||||
// shutdown() implementation.
|
||||
socket->send_tcp_packet(TCPFlags::FIN | TCPFlags::ACK);
|
||||
socket->set_state(TCPSocket::State::Closing);
|
||||
socket->send_tcp_packet(TCPFlags::ACK);
|
||||
socket->set_state(TCPSocket::State::CloseWait);
|
||||
socket->set_connected(false);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue