12 #include <gpxe/list.h>
15 * A persistent I/O buffer
17 * This data structure encapsulates a long-lived I/O buffer. The
18 * buffer may be passed between multiple owners, queued for possible
19 * retransmission, etc.
22 /** List of which this buffer is a member
24 * The list must belong to the current owner of the buffer.
25 * Different owners may maintain different lists (e.g. a
26 * retransmission list for TCP).
28 struct list_head list;
30 /** Start of the buffer */
36 /** End of the buffer */
41 * Reserve space at start of I/O buffer
44 * @v len Length to reserve
45 * @ret data Pointer to new start of buffer
47 static inline void * iob_reserve ( struct io_buffer *iob, size_t len ) {
50 assert ( iob->tail <= iob->end );
55 * Add data to start of I/O buffer
58 * @v len Length to add
59 * @ret data Pointer to new start of buffer
61 static inline void * iob_push ( struct io_buffer *iob, size_t len ) {
63 assert ( iob->data >= iob->head );
68 * Remove data from start of I/O buffer
71 * @v len Length to remove
72 * @ret data Pointer to new start of buffer
74 static inline void * iob_pull ( struct io_buffer *iob, size_t len ) {
76 assert ( iob->data <= iob->tail );
81 * Add data to end of I/O buffer
84 * @v len Length to add
85 * @ret data Pointer to newly added space
87 static inline void * iob_put ( struct io_buffer *iob, size_t len ) {
88 void *old_tail = iob->tail;
90 assert ( iob->tail <= iob->end );
95 * Remove data from end of I/O buffer
98 * @v len Length to remove
100 static inline void iob_unput ( struct io_buffer *iob, size_t len ) {
102 assert ( iob->tail >= iob->data );
106 * Empty an I/O buffer
110 static inline void iob_empty ( struct io_buffer *iob ) {
111 iob->tail = iob->data;
115 * Calculate length of data in an I/O buffer
118 * @ret len Length of data in buffer
120 static inline size_t iob_len ( struct io_buffer *iob ) {
121 return ( iob->tail - iob->data );
125 * Calculate available space at start of an I/O buffer
128 * @ret len Length of data available at start of buffer
130 static inline size_t iob_headroom ( struct io_buffer *iob ) {
131 return ( iob->data - iob->head );
135 * Calculate available space at end of an I/O buffer
138 * @ret len Length of data available at end of buffer
140 static inline size_t iob_tailroom ( struct io_buffer *iob ) {
141 return ( iob->end - iob->tail );
144 extern struct io_buffer * alloc_iob ( size_t len );
145 extern void free_iob ( struct io_buffer *iob );
146 extern void iob_pad ( struct io_buffer *iob, size_t min_len );
148 #endif /* _GPXE_IOBUF_H */