From 01b60f3d7ee14299cc8eb68cb4e82b62050cf3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 20 Jan 2009 10:38:05 +0000 Subject: [PATCH] * Fixed one more case of a resulting 0 byte buffer. Also added a test case for it to the test app. This finally fixes ticket #2594. * Of course, I neither saw this one before, nor did I accidently reproduce it with a test :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28967 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/network/protocols/tcp/BufferQueue.cpp | 7 ++++++- src/tests/kits/net/tcp_shell/BufferQueueTest.cpp | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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;