diff options
author | Michael Brown | 2015-07-20 18:53:30 +0200 |
---|---|---|
committer | Michael Brown | 2015-07-22 22:17:47 +0200 |
commit | 0dc85aed03239c13b31d2712ef28739879e12336 (patch) | |
tree | a30685b03194d83912bc420850286c43cf678b0e /src/core/xfer.c | |
parent | [xfer] Use intf_poke() to implement xfer_window_changed() (diff) | |
download | ipxe-0dc85aed03239c13b31d2712ef28739879e12336.tar.gz ipxe-0dc85aed03239c13b31d2712ef28739879e12336.tar.xz ipxe-0dc85aed03239c13b31d2712ef28739879e12336.zip |
[xfer] Add xfer_check_order() utility function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/xfer.c')
-rw-r--r-- | src/core/xfer.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/core/xfer.c b/src/core/xfer.c index 8d12a9ef..112fee1b 100644 --- a/src/core/xfer.c +++ b/src/core/xfer.c @@ -359,3 +359,34 @@ int xfer_seek ( struct interface *intf, off_t offset ) { return xfer_deliver ( intf, iobuf, &meta ); } + +/** + * Check that data is delivered strictly in order + * + * @v meta Data transfer metadata + * @v pos Current position + * @v len Length of data + * @ret rc Return status code + */ +int xfer_check_order ( struct xfer_metadata *meta, size_t *pos, size_t len ) { + size_t new_pos; + + /* Allow out-of-order zero-length packets (as used by xfer_seek()) */ + if ( len == 0 ) + return 0; + + /* Calculate position of this delivery */ + new_pos = *pos; + if ( meta->flags & XFER_FL_ABS_OFFSET ) + new_pos = 0; + new_pos += meta->offset; + + /* Fail if delivery position is not equal to current position */ + if ( new_pos != *pos ) + return -EPROTO; + + /* Update current position */ + *pos += len; + + return 0; +} |