IPStack - Reworking of network device API
[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 Clear a buffer object without deallocating it
20  */
21 extern void     IPStack_Buffer_ClearBuffer(tIPStackBuffer *Buffer);
22 /**
23  * \brief Destory a created buffer object
24  */
25 extern void     IPStack_Buffer_DestroyBuffer(tIPStackBuffer *Buffer);
26
27 /**
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
35  */
36 extern void     IPStack_Buffer_AppendSubBuffer(tIPStackBuffer *Buffer,
37         size_t HeadLength, size_t FootLength, const void *Data,
38         tIPStackBufferCb Cb, void *Arg
39         );
40
41 /**
42  * \brief Get the total length of a buffer
43  */
44 extern size_t   IPStack_Buffer_GetLength(tIPStackBuffer *Buffer);
45
46 /**
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
51  */
52 extern size_t   IPStack_Buffer_GetData(tIPStackBuffer *Buffer, void *Dest, size_t MaxBytes);
53
54 /**
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
59  */
60 extern int      IPStack_Buffer_GetBuffer(tIPStackBuffer *Buffer, int PrevID, size_t *Length, const void **Data);
61
62 /**
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
67  */
68 extern void     *IPStack_Buffer_CompactBuffer(tIPStackBuffer *Buffer, size_t *Length);
69
70 #endif
71

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