- Implemented some suggestions by stippi.
- Corrected some bugs also pointed by him. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28933 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
|
* Scott T. Mansfield, [email protected]
|
||||||
* Bruno Albuquerque, [email protected]
|
* Bruno Albuquerque, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -65,6 +66,8 @@ BNetBuffer::BNetBuffer(BMessage* archive) :
|
|||||||
BNetBuffer&
|
BNetBuffer&
|
||||||
BNetBuffer::operator=(const BNetBuffer& buffer)
|
BNetBuffer::operator=(const BNetBuffer& buffer)
|
||||||
{
|
{
|
||||||
|
delete fImpl;
|
||||||
|
|
||||||
fImpl = new (std::nothrow) DynamicBuffer(*buffer.GetImpl());
|
fImpl = new (std::nothrow) DynamicBuffer(*buffer.GetImpl());
|
||||||
if (fImpl != NULL)
|
if (fImpl != NULL)
|
||||||
fInit = fImpl->InitCheck();
|
fInit = fImpl->InitCheck();
|
||||||
@@ -79,11 +82,10 @@ BNetBuffer::Archive(BMessage* into, bool deep) const
|
|||||||
if (fInit != B_OK)
|
if (fInit != B_OK)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
|
||||||
if (into->AddData("buffer", B_RAW_TYPE, fImpl->Data(),
|
status_t result = into->AddData("buffer", B_RAW_TYPE, fImpl->Data(),
|
||||||
fImpl->BytesRemaining()) != B_OK)
|
fImpl->BytesRemaining());
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
return B_OK;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -94,7 +96,7 @@ BNetBuffer::Instantiate(BMessage* archive)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BNetBuffer* buffer = new BNetBuffer(archive);
|
BNetBuffer* buffer = new (std::nothrow) BNetBuffer(archive);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -188,22 +190,32 @@ BNetBuffer::AppendData(const void* data, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define STACK_BUFFER_SIZE 2048
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BNetBuffer::AppendMessage(const BMessage& data)
|
BNetBuffer::AppendMessage(const BMessage& data)
|
||||||
{
|
{
|
||||||
|
char stackFlattenedData[STACK_BUFFER_SIZE];
|
||||||
|
|
||||||
size_t dataSize = data.FlattenedSize();
|
size_t dataSize = data.FlattenedSize();
|
||||||
if (dataSize == 0)
|
if (dataSize == 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
char* flattenedData = new (std::nothrow) char[dataSize];
|
status_t result = B_OK;
|
||||||
if (flattenedData == NULL)
|
|
||||||
return B_NO_MEMORY;
|
if (dataSize > STACK_BUFFER_SIZE) {
|
||||||
|
char* flattenedData = new (std::nothrow) char[dataSize];
|
||||||
|
if (flattenedData == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
status_t result = B_OK;
|
if (data.Flatten(flattenedData, dataSize) == B_OK)
|
||||||
if (data.Flatten(flattenedData, dataSize) == B_OK)
|
result = AppendData((const void*)&flattenedData, dataSize);
|
||||||
result = AppendData((const void*)&flattenedData, dataSize);
|
|
||||||
|
|
||||||
delete[] flattenedData;
|
delete[] flattenedData;
|
||||||
|
} else {
|
||||||
|
if (data.Flatten(stackFlattenedData, dataSize) == B_OK)
|
||||||
|
result = AppendData((const void*)&stackFlattenedData, dataSize);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user