2 * Acess2 Networking Stack
3 * - By John Hodge (thePowersGang)
6 * - Outbound packet buffer management
8 #ifndef _IPSTACK__BUFFER_H_
9 #define _IPSTACK__BUFFER_H_
11 typedef struct sIPStackBuffer tIPStackBuffer;
12 typedef void (*tIPStackBufferCb)(void *Arg, size_t HeadLen, size_t FootLen, const void *Data);
15 * \brief Create a buffer object, with space for \a MaxSubBuffers calls to IPStack_Buffer_AppendSubBuffer
17 extern tIPStackBuffer *IPStack_Buffer_CreateBuffer(int MaxSubBuffers);
19 * \brief Clear a buffer object without deallocating it
21 extern void IPStack_Buffer_ClearBuffer(tIPStackBuffer *Buffer);
23 * \brief Destory a created buffer object
25 extern void IPStack_Buffer_DestroyBuffer(tIPStackBuffer *Buffer);
28 * \brief Append a buffer to the object
29 * \param Buffer Buffer object from IPStack_Buffer_CreateBuffer
30 * \param HeadLength Number of bytes in \a Data that should be at the beginning of the packet
31 * \param FootLength Number of bytes in \a Data that should be at the end of the packet
32 * \param Data Actual data
33 * \param Cb Unused - eventually will be called when object is destroyed
34 * \param Arg Unused - will be argument for \a Cb
36 extern void IPStack_Buffer_AppendSubBuffer(tIPStackBuffer *Buffer,
37 size_t HeadLength, size_t FootLength, const void *Data,
38 tIPStackBufferCb Cb, void *Arg
42 * \brief Get the total length of a buffer
44 extern size_t IPStack_Buffer_GetLength(tIPStackBuffer *Buffer);
47 * \brief Copy data from a buffer to a preallocated flat buffer
48 * \param Dest Destination flat buffer
49 * \param MaxBytes Maximum number of bytes to copy (size of \a Dest)
50 * \return Number of bytes copied
52 extern size_t IPStack_Buffer_GetData(tIPStackBuffer *Buffer, void *Dest, size_t MaxBytes);
55 * \brief Get a sub-buffer from the buffer object
56 * \param PrevID Previous return value, or -1 to start
57 * \return -1 when the last buffer has been returned (*Length is not valid in this case)
58 * \note Used to iterate though the buffer without compacting it
60 extern int IPStack_Buffer_GetBuffer(tIPStackBuffer *Buffer, int PrevID, size_t *Length, const void **Data);
63 * \brief Compact a buffer into a single contiguous malloc'd buffer
64 * \param Buffer Input buffer object
65 * \param Length Pointer in which to store the length of the allocated buffer
66 * \return malloc'd packet data
68 extern void *IPStack_Buffer_CompactBuffer(tIPStackBuffer *Buffer, size_t *Length);
70 extern void IPStack_Buffer_LockBuffer(tIPStackBuffer *Buffer);
71 extern void IPStack_Buffer_UnlockBuffer(tIPStackBuffer *Buffer);