[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-trivial] [PATCH] iov_send_recv(): Handle zero bytes case even
From: |
Michael Tokarev |
Subject: |
Re: [Qemu-trivial] [PATCH] iov_send_recv(): Handle zero bytes case even if OS does not |
Date: |
Sun, 12 Aug 2012 09:29:20 +0400 |
User-agent: |
Mozilla/5.0 (X11; Linux i686 on x86_64; rv:10.0.5) Gecko/20120624 Icedove/10.0.5 |
On 12.08.2012 01:24, Peter Maydell wrote:
> POSIX allows sendmsg() and recvmsg() to fail EMSGSIZE if passed a zero
> msg.msg_iovlen (in particular the MacOS X implementation will do this).
> Handle the case where iov_send_recv() is passed a zero byte count
> explicitly, to avoid accidentally depending on the OS to treat zero
> msg_iovlen as a no-op.
> Signed-off-by: Peter Maydell <address@hidden>
> ---
> This is what was causing 'make check' to fail on MacOS X.
> The other option was to declare that a zero bytecount was illegal, I guess.
I don't think sending/receiving zero bytes is a good idea in the
first place. Which test were failed on MacOS? Was it failing at
test-iov "random I/O"?
I thought I ensured that the test does not call any i/o function
with zero "count" argument. Might be I was wrong, and in that
case THAT place should be fixed instead.
Can you provide a bit more details please?
The whole thing is actually interesting: this is indeed a system-
dependent corner case which should be handled in the code to make
the routine consistent. But how to fix this is an open question
I think. Your approach seems to be best, but we as well may
print a warning there...
Thank you!
/mjt
> iov.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/iov.c b/iov.c
> index b333061..60705c7 100644
> --- a/iov.c
> +++ b/iov.c
> @@ -146,6 +146,13 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov,
> unsigned iov_cnt,
> {
> ssize_t ret;
> unsigned si, ei; /* start and end indexes */
> + if (bytes == 0) {
> + /* Catch the do-nothing case early, as otherwise we will pass an
> + * empty iovec to sendmsg/recvmsg(), and not all implementations
> + * accept this.
> + */
> + return 0;
> + }
>
> /* Find the start position, skipping `offset' bytes:
> * first, skip all full-sized vector elements, */