Skip to content

Commit f9569db

Browse files
committed
TCP: Collect the payload if present in a packet with FIN set.
1 parent 25e521f commit f9569db

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Kernel/IPv4Socket.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,11 @@ ssize_t IPv4Socket::recvfrom(void* buffer, size_t buffer_length, int flags, sock
222222
void IPv4Socket::did_receive(ByteBuffer&& packet)
223223
{
224224
LOCKER(lock());
225+
auto packet_size = packet.size();
225226
m_receive_queue.append(move(packet));
226227
m_can_read = true;
228+
m_bytes_received += packet_size;
227229
#ifdef IPV4_SOCKET_DEBUG
228-
kprintf("IPv4Socket(%p): did_receive %d bytes, packets in queue: %d\n", this, packet.size(), m_receive_queue.size_slow());
230+
kprintf("IPv4Socket(%p): did_receive %d bytes, total_received=%u, packets in queue: %d\n", this, packet_size, m_bytes_received, m_receive_queue.size_slow());
229231
#endif
230232
}

Kernel/IPv4Socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class IPv4Socket : public Socket {
6868
word m_source_port { 0 };
6969
word m_destination_port { 0 };
7070

71+
dword m_bytes_received { 0 };
72+
7173
bool m_can_read { false };
7274
};
7375

Kernel/NetworkTask.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ void handle_tcp(const EthernetFrameHeader& eth, int frame_size)
302302

303303
if (tcp_packet.has_fin()) {
304304
kprintf("handle_tcp: Got FIN, payload_size=%u\n", payload_size);
305+
306+
if (payload_size != 0)
307+
socket->did_receive(ByteBuffer::copy((const byte*)&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
308+
305309
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
306310
socket->send_tcp_packet(TCPFlags::FIN | TCPFlags::ACK);
307311
socket->set_state(TCPSocket::State::Disconnecting);

0 commit comments

Comments
 (0)