Modules/IPStack - Moving to reduction of memcpy usage
[tpg/acess2.git] / KernelLand / Modules / IPStack / include / buffer.h
1 /*
2  * Acess2 Networking Stack
3  * - By John Hodge (thePowersGang)
4  *
5  * include/buffer.h
6  * - Outbound packet buffer management
7  */
8 #ifndef _IPSTACK__BUFFER_H_
9 #define _IPSTACK__BUFFER_H_
10
11 typedef struct sIPStackBuffer   tIPStackBuffer;
12 typedef void    (*tIPStackBufferCb)(void *Arg, size_t HeadLen, size_t FootLen, const void *Data);
13
14 /**
15  * \brief Create a buffer object, with space for \a MaxSubBuffers calls to IPStack_Buffer_AppendSubBuffer
16  */
17 extern tIPStackBuffer   *IPStack_Buffer_CreateBuffer(int MaxSubBuffers);
18 /**
19  * \brief Destory a created buffer object
20  */
21 extern void     IPStack_Buffer_DestroyBuffer(tIPStackBuffer *Buffer);
22
23 /**
24  * \brief Append a buffer to the object
25  * \param Buffer        Buffer object from IPStack_Buffer_CreateBuffer
26  * \param HeadLength    Number of bytes in \a Data that should be at the beginning of the packet
27  * \param FootLength    Number of bytes in \a Data that should be at the end of the packet
28  * \param Data  Actual data
29  * \param Cb    Unused - eventually will be called when object is destroyed
30  * \param Arg   Unused - will be argument for \a Cb
31  */
32 extern void     IPStack_Buffer_AppendSubBuffer(tIPStackBuffer *Buffer,
33         size_t HeadLength, size_t FootLength, const void *Data,
34         tIPStackBufferCb Cb, void *Arg
35         );
36
37 /**
38  * \brief Get the total length of a buffer
39  */
40 extern size_t   IPStack_Buffer_GetLength(tIPStackBuffer *Buffer);
41 /**
42  * \brief Get a sub-buffer from the buffer object
43  * \param PrevID        Previous return value, or -1 to start
44  * \return -1 when the last buffer has been returned (*Length is not valid in this case)
45  * \note Used to iterate though the buffer without compacting it
46  */
47 extern int      IPStack_Buffer_GetBuffer(tIPStackBuffer *Buffer, int PrevID, size_t *Length, const void **Data);
48
49 /**
50  * \brief Compact a buffer into a single contiguous malloc'd buffer
51  * \param Buffer        Input buffer object
52  * \param Length        Pointer in which to store the length of the allocated buffer
53  * \return malloc'd packet data
54  */
55 extern void     *IPStack_Buffer_CompactBuffer(tIPStackBuffer *Buffer, size_t *Length);
56
57 #endif
58

UCC git Repository :: git.ucc.asn.au