mirror of
https://github.com/xcat2/xNBA.git
synced 2024-12-23 19:51:46 +00:00
Add concept of transfer metadata, to be used by UDP in order to
implement sendto()/recvfrom() equivalents.
This commit is contained in:
parent
77e575235d
commit
95adce0ce1
@ -141,10 +141,13 @@ static int posix_file_xfer_seek ( struct xfer_interface *xfer, off_t offset,
|
||||
*
|
||||
* @v xfer POSIX file data transfer interface
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf ) {
|
||||
static int
|
||||
posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta __unused ) {
|
||||
struct posix_file *file =
|
||||
container_of ( xfer, struct posix_file, xfer );
|
||||
|
||||
|
@ -174,20 +174,23 @@ struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer, size_t len ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver datagram
|
||||
* Deliver datagram as I/O buffer with metadata
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v iobuf Datagram I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int xfer_deliver_iob ( struct xfer_interface *xfer, struct io_buffer *iobuf ) {
|
||||
int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta ) {
|
||||
struct xfer_interface *dest = xfer_get_dest ( xfer );
|
||||
int rc;
|
||||
|
||||
DBGC ( xfer, "XFER %p->%p deliver_iob %zd\n", xfer, dest,
|
||||
iob_len ( iobuf ) );
|
||||
|
||||
rc = dest->op->deliver_iob ( dest, iobuf );
|
||||
rc = dest->op->deliver_iob ( dest, iobuf, meta );
|
||||
|
||||
if ( rc != 0 ) {
|
||||
DBGC ( xfer, "XFER %p<-%p deliver_iob: %s\n", xfer, dest,
|
||||
@ -197,6 +200,18 @@ int xfer_deliver_iob ( struct xfer_interface *xfer, struct io_buffer *iobuf ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver datagram as I/O buffer with metadata
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v iobuf Datagram I/O buffer
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf ) {
|
||||
return xfer_deliver_iob_meta ( xfer, iobuf, NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver datagram as raw data
|
||||
*
|
||||
@ -341,13 +356,15 @@ default_xfer_alloc_iob ( struct xfer_interface *xfer __unused, size_t len ) {
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v iobuf Datagram I/O buffer
|
||||
* @v meta Data transfer metadata
|
||||
* @ret rc Return status code
|
||||
*
|
||||
* This function is intended to be used as the deliver() method for
|
||||
* data transfer interfaces that prefer to handle raw data.
|
||||
*/
|
||||
int xfer_deliver_as_raw ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf ) {
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta __unused ) {
|
||||
int rc;
|
||||
|
||||
rc = xfer->op->deliver_raw ( xfer, iobuf->data, iob_len ( iobuf ) );
|
||||
@ -375,7 +392,7 @@ int xfer_deliver_as_iob ( struct xfer_interface *xfer,
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy ( iob_put ( iobuf, len ), data, len );
|
||||
return xfer->op->deliver_iob ( xfer, iobuf );
|
||||
return xfer->op->deliver_iob ( xfer, iobuf, NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <gpxe/iobuf.h>
|
||||
|
||||
struct xfer_interface;
|
||||
struct xfer_metadata;
|
||||
|
||||
/** Data transfer interface operations */
|
||||
struct xfer_interface_operations {
|
||||
@ -63,10 +64,11 @@ struct xfer_interface_operations {
|
||||
*/
|
||||
struct io_buffer * ( * alloc_iob ) ( struct xfer_interface *xfer,
|
||||
size_t len );
|
||||
/** Deliver datagram as I/O buffer
|
||||
/** Deliver datagram as I/O buffer with metadata
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v iobuf Datagram I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @ret rc Return status code
|
||||
*
|
||||
* A data transfer interface that wishes to support only raw
|
||||
@ -78,7 +80,8 @@ struct xfer_interface_operations {
|
||||
* fatal error.
|
||||
*/
|
||||
int ( * deliver_iob ) ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf );
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta );
|
||||
/** Deliver datagram as raw data
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
@ -106,6 +109,14 @@ struct xfer_interface {
|
||||
struct xfer_interface_operations *op;
|
||||
};
|
||||
|
||||
/** Data transfer metadata */
|
||||
struct xfer_metadata {
|
||||
/** Source socket address, or NULL */
|
||||
struct sockaddr *src;
|
||||
/** Destination socket address, or NULL */
|
||||
struct sockaddr *dest;
|
||||
};
|
||||
|
||||
/** Basis positions for seek() events */
|
||||
enum seek_whence {
|
||||
SEEK_SET = 0,
|
||||
@ -141,6 +152,9 @@ extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer,
|
||||
size_t len );
|
||||
extern int xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf );
|
||||
extern int xfer_deliver_iob_meta ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta );
|
||||
extern int xfer_deliver_raw ( struct xfer_interface *xfer,
|
||||
const void *data, size_t len );
|
||||
extern int xfer_vprintf ( struct xfer_interface *xfer,
|
||||
@ -158,7 +172,8 @@ extern int ignore_xfer_seek ( struct xfer_interface *xfer, off_t offset,
|
||||
extern struct io_buffer * default_xfer_alloc_iob ( struct xfer_interface *xfer,
|
||||
size_t len );
|
||||
extern int xfer_deliver_as_raw ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf );
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta );
|
||||
extern int xfer_deliver_as_iob ( struct xfer_interface *xfer,
|
||||
const void *data, size_t len );
|
||||
extern int ignore_xfer_deliver_raw ( struct xfer_interface *xfer,
|
||||
|
@ -930,10 +930,12 @@ static int tcp_xfer_seek ( struct xfer_interface *xfer, off_t offset,
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v iobuf Datagram I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf ) {
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta __unused ) {
|
||||
struct tcp_connection *tcp =
|
||||
container_of ( xfer, struct tcp_connection, xfer );
|
||||
|
||||
|
@ -338,10 +338,12 @@ static void ftp_data_closed ( struct xfer_interface *data, int rc ) {
|
||||
*
|
||||
* @v xfer FTP data channel interface
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ftp_data_deliver_iob ( struct xfer_interface *data,
|
||||
struct io_buffer *iobuf ) {
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta __unused ) {
|
||||
struct ftp_request *ftp =
|
||||
container_of ( data, struct ftp_request, data );
|
||||
int rc;
|
||||
|
@ -316,10 +316,12 @@ static int http_rx_data ( struct http_request *http,
|
||||
*
|
||||
* @v socket Transport layer interface
|
||||
* @v iobuf I/O buffer
|
||||
* @v meta Data transfer metadata, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int http_socket_deliver_iob ( struct xfer_interface *socket,
|
||||
struct io_buffer *iobuf ) {
|
||||
struct io_buffer *iobuf,
|
||||
struct xfer_metadata *meta __unused ) {
|
||||
struct http_request *http =
|
||||
container_of ( socket, struct http_request, socket );
|
||||
struct http_line_handler *lh;
|
||||
|
Loading…
Reference in New Issue
Block a user