diff options
| author | Michael Brown | 2007-04-27 00:44:52 +0200 |
|---|---|---|
| committer | Michael Brown | 2007-04-27 00:44:52 +0200 |
| commit | 2575ddc8894e04dd333d3e7e7ed038d9c6d5c711 (patch) | |
| tree | 53d17b1822466ee011fe649d783f08b7d23b5498 /src/include/gpxe | |
| parent | Trivial ASN.1 decoding functions. (diff) | |
| download | ipxe-2575ddc8894e04dd333d3e7e7ed038d9c6d5c711.tar.gz ipxe-2575ddc8894e04dd333d3e7e7ed038d9c6d5c711.tar.xz ipxe-2575ddc8894e04dd333d3e7e7ed038d9c6d5c711.zip | |
Initial sketch for the generic data-transfer interface.
Diffstat (limited to 'src/include/gpxe')
| -rw-r--r-- | src/include/gpxe/interface.h | 36 | ||||
| -rw-r--r-- | src/include/gpxe/iobuf.h | 148 | ||||
| -rw-r--r-- | src/include/gpxe/xfer.h | 78 |
3 files changed, 262 insertions, 0 deletions
diff --git a/src/include/gpxe/interface.h b/src/include/gpxe/interface.h new file mode 100644 index 000000000..38e627211 --- /dev/null +++ b/src/include/gpxe/interface.h @@ -0,0 +1,36 @@ +#ifndef _GPXE_INTERFACE_H +#define _GPXE_INTERFACE_H + +/** @file + * + * Object communication interfaces + * + */ + +/** An object communication interface */ +struct interface { + /** Destination interface + * + * When messages are sent via this interface, they will be + * delivered to the destination interface. + * + * This pointer may never be NULL. When the interface is + * unplugged, it should point to a null interface. + */ + struct interface *dest; + /** Update reference count + * + * @v intf Interface + * @v delta Change to apply to reference count + * + * This method updates the reference count for the object + * containing the interface. + */ + void ( * refcnt ) ( struct interface *intf, int delta ); +}; + +extern void plug ( struct interface *intf, struct interface *dest ); + +extern void null_refcnt ( struct interface *intf, int delta ); + +#endif /* _GPXE_INTERFACE_H */ diff --git a/src/include/gpxe/iobuf.h b/src/include/gpxe/iobuf.h new file mode 100644 index 000000000..cf99050d4 --- /dev/null +++ b/src/include/gpxe/iobuf.h @@ -0,0 +1,148 @@ +#ifndef _GPXE_IOBUF_H +#define _GPXE_IOBUF_H + +/** @file + * + * I/O buffers + * + */ + +#include <stdint.h> +#include <assert.h> +#include <gpxe/list.h> + +/** + * A persistent I/O buffer + * + * This data structure encapsulates a long-lived I/O buffer. The + * buffer may be passed between multiple owners, queued for possible + * retransmission, etc. + */ +struct io_buffer { + /** List of which this buffer is a member + * + * The list must belong to the current owner of the buffer. + * Different owners may maintain different lists (e.g. a + * retransmission list for TCP). + */ + struct list_head list; + + /** Start of the buffer */ + void *head; + /** Start of data */ + void *data; + /** End of data */ + void *tail; + /** End of the buffer */ + void *end; +}; + +/** + * Reserve space at start of I/O buffer + * + * @v iob I/O buffer + * @v len Length to reserve + * @ret data Pointer to new start of buffer + */ +static inline void * iob_reserve ( struct io_buffer *iob, size_t len ) { + iob->data += len; + iob->tail += len; + assert ( iob->tail <= iob->end ); + return iob->data; +} + +/** + * Add data to start of I/O buffer + * + * @v iob I/O buffer + * @v len Length to add + * @ret data Pointer to new start of buffer + */ +static inline void * iob_push ( struct io_buffer *iob, size_t len ) { + iob->data -= len; + assert ( iob->data >= iob->head ); + return iob->data; +} + +/** + * Remove data from start of I/O buffer + * + * @v iob I/O buffer + * @v len Length to remove + * @ret data Pointer to new start of buffer + */ +static inline void * iob_pull ( struct io_buffer *iob, size_t len ) { + iob->data += len; + assert ( iob->data <= iob->tail ); + return iob->data; +} + +/** + * Add data to end of I/O buffer + * + * @v iob I/O buffer + * @v len Length to add + * @ret data Pointer to newly added space + */ +static inline void * iob_put ( struct io_buffer *iob, size_t len ) { + void *old_tail = iob->tail; + iob->tail += len; + assert ( iob->tail <= iob->end ); + return old_tail; +} + +/** + * Remove data from end of I/O buffer + * + * @v iob I/O buffer + * @v len Length to remove + */ +static inline void iob_unput ( struct io_buffer *iob, size_t len ) { + iob->tail -= len; + assert ( iob->tail >= iob->data ); +} + +/** + * Empty an I/O buffer + * + * @v iob I/O buffer + */ +static inline void iob_empty ( struct io_buffer *iob ) { + iob->tail = iob->data; +} + +/** + * Calculate length of data in an I/O buffer + * + * @v iob I/O buffer + * @ret len Length of data in buffer + */ +static inline size_t iob_len ( struct io_buffer *iob ) { + return ( iob->tail - iob->data ); +} + +/** + * Calculate available space at start of an I/O buffer + * + * @v iob I/O buffer + * @ret len Length of data available at start of buffer + */ +static inline size_t iob_headroom ( struct io_buffer *iob ) { + return ( iob->data - iob->head ); +} + +/** + * Calculate available space at end of an I/O buffer + * + * @v iob I/O buffer + * @ret len Length of data available at end of buffer + */ +static inline size_t iob_tailroom ( struct io_buffer *iob ) { + return ( iob->end - iob->tail ); +} + +extern struct io_buffer * alloc_iob ( size_t len ); +extern void free_iob ( struct io_buffer *iob ); +extern void iob_pad ( struct io_buffer *iob, size_t min_len ); + +#endif /* _GPXE_IOBUF_H */ diff --git a/src/include/gpxe/xfer.h b/src/include/gpxe/xfer.h new file mode 100644 index 000000000..0e577e933 --- /dev/null +++ b/src/include/gpxe/xfer.h @@ -0,0 +1,78 @@ +#ifndef _GPXE_XFER_H +#define _GPXE_XFER_H + +/** @file + * + * Data transfer interfaces + * + */ + +#include <stddef.h> +#include <gpxe/interface.h> +#include <gpxe/iobuf.h> + +struct xfer_interface; + +/** Data transfer interface operations */ +struct xfer_interface_operations { + /** Deliver datagram + * + * @v xfer Data-transfer interface + * @v src Source interface + * @v iobuf Datagram I/O buffer + * @ret rc Return status code + */ + int ( * deliver ) ( struct xfer_interface *xfer, + struct xfer_interface *src, + struct io_buffer *iobuf ); +}; + +/** A data transfer interface */ +struct xfer_interface { + /** Generic object communication interface */ + struct interface intf; + /** Operations for received messages */ + struct xfer_interface_operations *op; +}; + +extern struct xfer_interface null_xfer; +extern struct xfer_interface_operations null_xfer_ops; + +static inline struct xfer_interface * +xfer_dest ( struct xfer_interface *xfer ) { + return container_of ( xfer->intf.dest, struct xfer_interface, intf ); +} + +/** + * Plug a data-transfer interface into a new destination interface + * + * @v xfer Data-transfer interface + * @v dest New destination interface + */ +static inline void xfer_plug ( struct xfer_interface *xfer, + struct xfer_interface *dest ) { + plug ( &xfer->intf, &dest->intf ); +} + +/** + * Unplug a data-transfer interface + * + * @v xfer Data-transfer interface + */ +static inline void xfer_unplug ( struct xfer_interface *xfer ) { + plug ( &xfer->intf, &null_xfer.intf ); +} + +/** + * Terminate a data-transfer interface + * + * @v xfer Data-transfer interface + * + * After calling this method, no further messages will be received via + * the interface. + */ +static inline void xfer_terminate ( struct xfer_interface *xfer ) { + xfer->op = &null_xfer_ops; +}; + +#endif /* _GPXE_XFER_H */ |
