2 * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include <boot/net/ChainBuffer.h>
11 #include <util/kernel_cpp.h>
14 ChainBuffer::ChainBuffer(void *data
, uint32 size
, ChainBuffer
*next
,
17 _Init(data
, size
, next
,
18 CHAIN_BUFFER_ON_STACK
| (freeData
? CHAIN_BUFFER_FREE_DATA
: 0));
22 ChainBuffer::~ChainBuffer()
29 ChainBuffer::DetachNext()
34 ChainBuffer
*next
= fNext
;
37 next
->fFlags
|= CHAIN_BUFFER_HEAD
;
45 ChainBuffer::Append(ChainBuffer
*next
)
55 fTotalSize
= fSize
+ fNext
->fTotalSize
;
60 ChainBuffer::Flatten(void *_buffer
) const
62 if (uint8
*buffer
= (uint8
*)_buffer
) {
63 if (fData
&& fSize
> 0) {
64 memcpy(buffer
, fData
, fSize
);
69 fNext
->Flatten(buffer
);
75 ChainBuffer::_Init(void *data
, uint32 size
, ChainBuffer
*next
, uint32 flags
)
77 fFlags
= flags
| CHAIN_BUFFER_HEAD
;
87 ChainBuffer::_Destroy()
89 ChainBuffer
*next
= fNext
;
91 if ((fFlags
& CHAIN_BUFFER_FREE_DATA
) && fData
) {
96 if (!(fFlags
& CHAIN_BUFFER_EMBEDDED_DATA
))
101 if (next
->fFlags
& CHAIN_BUFFER_ON_STACK
)