diff --git a/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp b/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp index 1db7b6cea0..b71b4b1cea 100644 --- a/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp @@ -176,9 +176,14 @@ BufferQueue::Add(net_buffer *buffer, tcp_sequence sequence) fList.Remove(remove); fNumBytes -= remove->size; gBufferModule->free(remove); - } else { + } else if (tcp_sequence(next->sequence) > sequence) { + // We have the end of this buffer already gBufferModule->remove_trailer(buffer, sequence + buffer->size - next->sequence); + } else { + // We already have this data + gBufferModule->free(buffer); + buffer = NULL; } } diff --git a/src/tests/kits/net/tcp_shell/BufferQueueTest.cpp b/src/tests/kits/net/tcp_shell/BufferQueueTest.cpp index 5fc5927955..ef8cbe01b4 100644 --- a/src/tests/kits/net/tcp_shell/BufferQueueTest.cpp +++ b/src/tests/kits/net/tcp_shell/BufferQueueTest.cpp @@ -1,3 +1,8 @@ +/* + * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + #define DEBUG_BUFFER_QUEUE 1 #include "BufferQueue.h" @@ -129,7 +134,11 @@ main() dump("add 3"); add(60, 540); - dump("add at the end of previous data"); + dump("added at the end of previous data"); + + add(998, 1002); + add(500, 1000); + dump("added data covered by next"); put_module(NET_BUFFER_MODULE_NAME); return 0;