On 05/05/2016 08:37 AM, Eric Blake wrote:
> /**
> + * virStreamSkip:
> + * @stream: pointer to the stream object
> + * @offset: number of bytes to skip
> + *
> + * Skip @offset bytes in the stream. This is useful when there's
> + * no actual data in the stream, just a hole. If that's the case,
> + * this API can be used to skip the hole properly instead of
> + * transmitting zeroes to the other side.
> + *
> + * Returns 0 on success,
> + * -1 error
> + */
> +int
> +virStreamSkip(virStreamPtr stream,
> + unsigned long long offset)
'offset' is a bit misleading - you're not skipping _to_ the given
offset, so much as _over_ length bytes. I'd name it 'length'.
Otherwise looks okay.
Also, the interface doesn't show it, but I hope the implementation
recognizes a malicious remote side that tries to skip beyond the end of
the stream. Do we need to specifically call out in the docs what happens
if 'offset' (or renamed 'length') attempts to go beyond the stream size?
Do you skip to EOF, or leave the current position unchanged, so that
the next real attempt will just work? Would this be a way to probe
whether a stream supports skips, by attempting to skip to ULLONG_MAX
(which is ALWAYS beyond the current stream size, since it is larger than
the maximum signed off_t value), then detecting a difference in errors
between 'sparse stream but seek too large' vs. 'not sparse stream')?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org