Separate the "is data ready" function of xfer_seek() into an

xfer_window() function, which can return a scalar rather than a
boolean.
This commit is contained in:
Michael Brown
2007-07-08 14:11:07 +01:00
parent ca4c6f9eee
commit b34d4d0449
14 changed files with 94 additions and 45 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,
};

View File

@@ -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,

View File

@@ -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,