From b34d4d044978714abe771ca8d7d07153ad048d82 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 8 Jul 2007 14:11:07 +0100 Subject: [PATCH] Separate the "is data ready" function of xfer_seek() into an xfer_window() function, which can return a scalar rather than a boolean. --- src/core/downloader.c | 1 + src/core/hw.c | 3 ++- src/core/posix_io.c | 1 + src/core/resolv.c | 17 ++------------- src/core/xfer.c | 43 +++++++++++++++++++++++++++++++++++++ src/include/gpxe/xfer.h | 33 +++++++++++++++++----------- src/interface/pxe/pxe_udp.c | 1 + src/net/tcp.c | 28 +++++++++++------------- src/net/tcp/ftp.c | 3 +++ src/net/tcp/http.c | 4 +++- src/net/udp.c | 1 + src/net/udp/dhcp.c | 1 + src/net/udp/dns.c | 1 + src/net/udp/tftp.c | 2 ++ 14 files changed, 94 insertions(+), 45 deletions(-) diff --git a/src/core/downloader.c b/src/core/downloader.c index 4a74589f..3726c6e1 100644 --- a/src/core/downloader.c +++ b/src/core/downloader.c @@ -228,6 +228,7 @@ static struct xfer_interface_operations downloader_xfer_operations = { .close = downloader_xfer_close, .vredirect = xfer_vopen, .seek = downloader_xfer_seek, + .window = unlimited_xfer_window, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = downloader_xfer_deliver_raw, }; diff --git a/src/core/hw.c b/src/core/hw.c index 2cb912b1..3502dbfb 100644 --- a/src/core/hw.c +++ b/src/core/hw.c @@ -37,6 +37,7 @@ static struct xfer_interface_operations hw_xfer_operations = { .close = hw_xfer_close, .vredirect = ignore_xfer_vredirect, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = ignore_xfer_deliver_raw, }; @@ -45,7 +46,7 @@ static void hw_step ( struct process *process ) { struct hw *hw = container_of ( process, struct hw, process ); int rc; - if ( xfer_ready ( &hw->xfer ) == 0 ) { + if ( xfer_window ( &hw->xfer ) ) { rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) ); hw_finished ( hw, rc ); } diff --git a/src/core/posix_io.c b/src/core/posix_io.c index 03d440a6..21f818bf 100644 --- a/src/core/posix_io.c +++ b/src/core/posix_io.c @@ -160,6 +160,7 @@ static struct xfer_interface_operations posix_file_xfer_operations = { .close = posix_file_xfer_close, .vredirect = xfer_vopen, .seek = posix_file_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = posix_file_xfer_deliver_iob, .deliver_raw = xfer_deliver_as_iob, diff --git a/src/core/resolv.c b/src/core/resolv.c index 7ca62cd8..5c25ddb1 100644 --- a/src/core/resolv.c +++ b/src/core/resolv.c @@ -308,25 +308,12 @@ struct named_socket { int have_local; }; -/** - * Handle seek() event - * - * @v xfer Data transfer interface - * @v offset Offset to new position - * @v whence Basis for new position - * @ret rc Return status code - */ -static int resolv_xfer_seek ( struct xfer_interface *xfer __unused, - off_t offset __unused, int whence __unused ) { - /* Never ready to accept data */ - return -EAGAIN; -} - /** Named socket opener data transfer interface operations */ static struct xfer_interface_operations named_xfer_ops = { .close = ignore_xfer_close, .vredirect = ignore_xfer_vredirect, - .seek = resolv_xfer_seek, + .seek = ignore_xfer_seek, + .window = no_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = ignore_xfer_deliver_raw, diff --git a/src/core/xfer.c b/src/core/xfer.c index 3e55ebaf..3e6b7eb6 100644 --- a/src/core/xfer.c +++ b/src/core/xfer.c @@ -110,6 +110,22 @@ int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence ) { return rc; } +/** + * Check flow control window + * + * @v xfer Data transfer interface + * @ret len Length of window + */ +size_t xfer_window ( struct xfer_interface *xfer ) { + struct xfer_interface *dest = xfer_get_dest ( xfer ); + size_t len; + + len = dest->op->window ( dest ); + + xfer_put ( dest ); + return len; +} + /** * Test to see if interface is ready to accept data * @@ -297,6 +313,32 @@ int ignore_xfer_seek ( struct xfer_interface *xfer __unused, return 0; } +/** + * Unlimited flow control window + * + * @v xfer Data transfer interface + * @ret len Length of window + * + * This handler indicates that the interface is always ready to accept + * data. + */ +size_t unlimited_xfer_window ( struct xfer_interface *xfer __unused ) { + return ~( ( size_t ) 0 ); +} + +/** + * No flow control window + * + * @v xfer Data transfer interface + * @ret len Length of window + * + * This handler indicates that the interface is never ready to accept + * data. + */ +size_t no_xfer_window ( struct xfer_interface *xfer __unused ) { + return 0; +} + /** * Allocate I/O buffer * @@ -374,6 +416,7 @@ struct xfer_interface_operations null_xfer_ops = { .close = ignore_xfer_close, .vredirect = ignore_xfer_vredirect, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = ignore_xfer_deliver_raw, diff --git a/src/include/gpxe/xfer.h b/src/include/gpxe/xfer.h index edf553f7..68c1169e 100644 --- a/src/include/gpxe/xfer.h +++ b/src/include/gpxe/xfer.h @@ -39,13 +39,26 @@ struct xfer_interface_operations { * @v whence Basis for new position * @ret rc Return status code * - * @c whence must be one of @c SEEK_SET or @c SEEK_CUR. A - * successful return indicates that the interface is ready to - * immediately accept datagrams; return -EAGAIN if this is not - * the case. + * @c whence must be one of @c SEEK_SET or @c SEEK_CUR. */ int ( * seek ) ( struct xfer_interface *xfer, off_t offset, int whence ); + /** Check flow control window + * + * @v xfer Data transfer interface + * @ret len Length of window + * + * Flow control is regarded as advisory but not mandatory. + * Users who have control over their own rate of data + * generation should perform a flow control check before + * generating new data. Users who have no control (such as + * NIC drivers or filter layers) are not obliged to check. + * + * Data transfer interfaces must be prepared to accept + * datagrams even if they are advertising a window of zero + * bytes. + */ + size_t ( * window ) ( struct xfer_interface *xfer ); /** Allocate I/O buffer * * @v xfer Data transfer interface @@ -64,10 +77,6 @@ struct xfer_interface_operations { * A data transfer interface that wishes to support only raw * data delivery should set this method to * xfer_deliver_as_raw(). - * - * Interfaces may not temporarily refuse to accept data by - * returning -EAGAIN; such a response may be treated as a - * fatal error. */ int ( * deliver_iob ) ( struct xfer_interface *xfer, struct io_buffer *iobuf, @@ -82,10 +91,6 @@ struct xfer_interface_operations { * A data transfer interface that wishes to support only I/O * buffer delivery should set this method to * xfer_deliver_as_iob(). - * - * Interfaces may not temporarily refuse to accept data by - * returning -EAGAIN; such a response may be treated as a - * fatal error. */ int ( * deliver_raw ) ( struct xfer_interface *xfer, const void *data, size_t len ); @@ -137,7 +142,7 @@ extern int xfer_vredirect ( struct xfer_interface *xfer, int type, va_list args ); extern int xfer_redirect ( struct xfer_interface *xfer, int type, ... ); extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence ); -extern int xfer_ready ( struct xfer_interface *xfer ); +extern size_t xfer_window ( struct xfer_interface *xfer ); extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer, size_t len ); extern int xfer_deliver_iob ( struct xfer_interface *xfer, @@ -157,6 +162,8 @@ extern int ignore_xfer_vredirect ( struct xfer_interface *xfer, int type, va_list args ); extern int ignore_xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence ); +extern size_t unlimited_xfer_window ( struct xfer_interface *xfer ); +extern size_t no_xfer_window ( struct xfer_interface *xfer ); 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, diff --git a/src/interface/pxe/pxe_udp.c b/src/interface/pxe/pxe_udp.c index 153d758c..745366f2 100644 --- a/src/interface/pxe/pxe_udp.c +++ b/src/interface/pxe/pxe_udp.c @@ -104,6 +104,7 @@ static struct xfer_interface_operations pxe_udp_xfer_operations = { .close = ignore_xfer_close, .vredirect = ignore_xfer_vredirect, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = pxe_udp_deliver_iob, .deliver_raw = xfer_deliver_as_iob, diff --git a/src/net/tcp.c b/src/net/tcp.c index 12ca65a6..410be737 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -897,31 +897,28 @@ static void tcp_xfer_close ( struct xfer_interface *xfer, int rc ) { } /** - * Seek to position + * Check flow control window * * @v xfer Data transfer interface - * @v offset Offset to new position - * @v whence Basis for new position - * @ret rc Return status code + * @ret len Length of window */ -static int tcp_xfer_seek ( struct xfer_interface *xfer, off_t offset, - int whence ) { +static size_t tcp_xfer_window ( struct xfer_interface *xfer ) { struct tcp_connection *tcp = container_of ( xfer, struct tcp_connection, xfer ); - /* TCP doesn't support seeking to arbitrary positions */ - if ( ( whence != SEEK_CUR ) || ( offset != 0 ) ) - return -EINVAL; - /* Not ready if we're not in a suitable connection state */ if ( ! TCP_CAN_SEND_DATA ( tcp->tcp_state ) ) - return -EAGAIN; + return 0; - /* Not ready if data queue is non-empty */ + /* Not ready if data queue is non-empty. This imposes a limit + * of only one unACKed packet in the TX queue at any time; we + * do this to conserve memory usage. + */ if ( ! list_empty ( &tcp->queue ) ) - return -EAGAIN; + return 0; - return 0; + /* Return TCP window length */ + return tcp->snd_win; } /** @@ -951,7 +948,8 @@ static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer, static struct xfer_interface_operations tcp_xfer_operations = { .close = tcp_xfer_close, .vredirect = ignore_xfer_vredirect, - .seek = tcp_xfer_seek, + .seek = ignore_xfer_seek, + .window = tcp_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = tcp_xfer_deliver_iob, .deliver_raw = xfer_deliver_as_iob, diff --git a/src/net/tcp/ftp.c b/src/net/tcp/ftp.c index 6c09edff..646638ab 100644 --- a/src/net/tcp/ftp.c +++ b/src/net/tcp/ftp.c @@ -297,6 +297,7 @@ static struct xfer_interface_operations ftp_control_operations = { .close = ftp_control_close, .vredirect = xfer_vopen, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = ftp_control_deliver_raw, @@ -361,6 +362,7 @@ static struct xfer_interface_operations ftp_data_operations = { .close = ftp_data_closed, .vredirect = xfer_vopen, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = ftp_data_deliver_iob, .deliver_raw = xfer_deliver_as_iob, @@ -393,6 +395,7 @@ static struct xfer_interface_operations ftp_xfer_operations = { .close = ftp_xfer_closed, .vredirect = ignore_xfer_vredirect, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = ignore_xfer_deliver_raw, diff --git a/src/net/tcp/http.c b/src/net/tcp/http.c index 287a56a0..0c016413 100644 --- a/src/net/tcp/http.c +++ b/src/net/tcp/http.c @@ -388,7 +388,7 @@ static void http_step ( struct process *process ) { const char *query = http->uri->query; int rc; - if ( xfer_ready ( &http->socket ) == 0 ) { + if ( xfer_window ( &http->socket ) ) { process_del ( &http->process ); if ( ( rc = xfer_printf ( &http->socket, "GET %s%s%s HTTP/1.1\r\n" @@ -425,6 +425,7 @@ static struct xfer_interface_operations http_socket_operations = { .close = http_socket_close, .vredirect = xfer_vopen, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = http_socket_deliver_iob, .deliver_raw = xfer_deliver_as_iob, @@ -451,6 +452,7 @@ static struct xfer_interface_operations http_xfer_operations = { .close = http_xfer_close, .vredirect = ignore_xfer_vredirect, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = ignore_xfer_deliver_raw, diff --git a/src/net/udp.c b/src/net/udp.c index 3e33ff17..b4cd8e6b 100644 --- a/src/net/udp.c +++ b/src/net/udp.c @@ -415,6 +415,7 @@ static struct xfer_interface_operations udp_xfer_operations = { .close = udp_xfer_close, .vredirect = ignore_xfer_vredirect, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = udp_alloc_iob, .deliver_iob = udp_xfer_deliver_iob, .deliver_raw = xfer_deliver_as_iob, diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c index 5a8203a1..26059341 100644 --- a/src/net/udp/dhcp.c +++ b/src/net/udp/dhcp.c @@ -722,6 +722,7 @@ static struct xfer_interface_operations dhcp_xfer_operations = { .close = ignore_xfer_close, .vredirect = xfer_vopen, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = dhcp_deliver_raw, }; diff --git a/src/net/udp/dns.c b/src/net/udp/dns.c index 76d5dd7a..aab9cfc2 100644 --- a/src/net/udp/dns.c +++ b/src/net/udp/dns.c @@ -433,6 +433,7 @@ static struct xfer_interface_operations dns_socket_operations = { .close = dns_xfer_close, .vredirect = xfer_vopen, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = dns_xfer_deliver_raw, diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c index 03a51f9a..106c7047 100644 --- a/src/net/udp/tftp.c +++ b/src/net/udp/tftp.c @@ -583,6 +583,7 @@ static struct xfer_interface_operations tftp_socket_operations = { .close = tftp_socket_close, .vredirect = xfer_vopen, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = tftp_socket_deliver_iob, .deliver_raw = xfer_deliver_as_iob, @@ -609,6 +610,7 @@ static struct xfer_interface_operations tftp_xfer_operations = { .close = tftp_xfer_close, .vredirect = ignore_xfer_vredirect, .seek = ignore_xfer_seek, + .window = unlimited_xfer_window, .alloc_iob = default_xfer_alloc_iob, .deliver_iob = xfer_deliver_as_raw, .deliver_raw = ignore_xfer_deliver_raw,