From 8ad667cb0b87d251fff7bc2f8f9361e225b232e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 1 Dec 2006 09:45:23 +0000 Subject: [PATCH] * After my recent change, append_size() did not work correctly anymore, if the initial buffer wasn't empty. * Enlarged the minimum header size a bit (one more data_node). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19406 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/network/stack/net_buffer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/network/stack/net_buffer.cpp b/src/add-ons/kernel/network/stack/net_buffer.cpp index 9b3d62a770..012231d066 100644 --- a/src/add-ons/kernel/network/stack/net_buffer.cpp +++ b/src/add-ons/kernel/network/stack/net_buffer.cpp @@ -682,12 +682,13 @@ append_size(net_buffer *_buffer, size_t size, void **_contiguousBuffer) // compute how many buffers we're going to need // TODO: this doesn't leave any tail space, if that should be desired... uint32 tailSpace = node->tail_space; - uint32 minimalHeaderSpace = sizeof(data_header) + 2 * sizeof(data_node); + uint32 minimalHeaderSpace = sizeof(data_header) + 3 * sizeof(data_node); uint32 sizeNeeded = size - tailSpace; uint32 count = (sizeNeeded + BUFFER_SIZE - minimalHeaderSpace - 1) / (BUFFER_SIZE - minimalHeaderSpace); uint32 headerSpace = BUFFER_SIZE - sizeNeeded / count - sizeof(data_header); uint32 sizeUsed = BUFFER_SIZE - sizeof(data_header) - headerSpace; + uint32 sizeAdded = tailSpace; // allocate space left in the node node->tail_space -= tailSpace; @@ -699,7 +700,7 @@ append_size(net_buffer *_buffer, size_t size, void **_contiguousBuffer) for (uint32 i = 0; i < count; i++) { if (i == count - 1) { // last data_header - compensate rounding errors - sizeUsed = size - buffer->size; + sizeUsed = size - sizeAdded; headerSpace = BUFFER_SIZE - sizeof(data_header) - sizeUsed; } @@ -720,6 +721,7 @@ append_size(net_buffer *_buffer, size_t size, void **_contiguousBuffer) header->first_node = node; buffer->size += sizeUsed; + sizeAdded += sizeUsed; list_add_item(&buffer->buffers, node); }