diff --git a/headers/private/net/DynamicBuffer.h b/headers/private/net/DynamicBuffer.h index 183f88b48a..58a49d9ca2 100644 --- a/headers/private/net/DynamicBuffer.h +++ b/headers/private/net/DynamicBuffer.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Haiku, Inc. All Rights Reserved. + * Copyright 2009-2014, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -9,10 +9,11 @@ #ifndef _DYNAMIC_BUFFER_H #define _DYNAMIC_BUFFER_H +#include #include -class DynamicBuffer { +class DynamicBuffer : public BDataIO { public: DynamicBuffer(size_t initialSize = 0); ~DynamicBuffer(); @@ -25,11 +26,11 @@ public: // Insert data at the end of the buffer. The buffer will be increased to // accomodate the data if needed. - status_t Insert(const void* data, size_t size); + status_t Write(const void* data, size_t size); // Remove data from the start of the buffer. Move the buffer start // pointer to point to the data following it. - status_t Remove(void* data, size_t size); + ssize_t Read(void* data, size_t size); // Return a pointer to the underlying buffer. Note this will not // necessarily be a pointer to the start of the allocated memory as the diff --git a/src/kits/network/libnetapi/DynamicBuffer.cpp b/src/kits/network/libnetapi/DynamicBuffer.cpp index 1c63eca581..75f4a46458 100644 --- a/src/kits/network/libnetapi/DynamicBuffer.cpp +++ b/src/kits/network/libnetapi/DynamicBuffer.cpp @@ -68,7 +68,7 @@ DynamicBuffer::InitCheck() const status_t -DynamicBuffer::Insert(const void* data, size_t size) +DynamicBuffer::Write(const void* data, size_t size) { if (fInit != B_OK) return fInit; @@ -84,14 +84,14 @@ DynamicBuffer::Insert(const void* data, size_t size) } -status_t -DynamicBuffer::Remove(void* data, size_t size) +ssize_t +DynamicBuffer::Read(void* data, size_t size) { if (fInit != B_OK) return fInit; - if (fDataStart + size > fDataEnd) - return B_BUFFER_OVERFLOW; + if (size > Size()) + size = Size(); memcpy(data, fBuffer + fDataStart, size); fDataStart += size; @@ -99,7 +99,7 @@ DynamicBuffer::Remove(void* data, size_t size) if (fDataStart == fDataEnd) fDataStart = fDataEnd = 0; - return B_OK; + return size; } diff --git a/src/kits/network/libnetapi/NetBuffer.cpp b/src/kits/network/libnetapi/NetBuffer.cpp index d2a0911d15..c1ccb2b932 100644 --- a/src/kits/network/libnetapi/NetBuffer.cpp +++ b/src/kits/network/libnetapi/NetBuffer.cpp @@ -54,7 +54,7 @@ BNetBuffer::BNetBuffer(BMessage* archive) : &bufferSize) == B_OK) { fImpl = new (std::nothrow) DynamicBuffer(bufferSize); if (fImpl != NULL) { - status_t result = fImpl->Insert(bufferPtr, bufferSize); + status_t result = fImpl->Write(bufferPtr, bufferSize); if (result == B_OK) fInit = fImpl->InitCheck(); else @@ -185,7 +185,7 @@ BNetBuffer::AppendString(const char* data) status_t BNetBuffer::AppendData(const void* data, size_t size) { - return fImpl->Insert(data, size); + return fImpl->Write(data, size); } @@ -332,7 +332,7 @@ BNetBuffer::RemoveString(char* data, size_t size) status_t BNetBuffer::RemoveData(void* data, size_t size) { - return fImpl->Remove(data, size); + return fImpl->Read(data, size); }