diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2012-08-11 22:24:35 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2012-08-15 15:21:33 +0100 |
commit | bb9558679ffaae062ea26ef97d2273b148e9c515 (patch) | |
tree | 20374cfc720cd6fee4c9c17097d324fc27b6c6ce /iov.c | |
parent | 9c6bb55b864d34d78aa617440fc055e1c61cd2a6 (diff) |
iov_send_recv(): Handle zero bytes case even if OS does not
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 <peter.maydell@linaro.org>
Acked-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Diffstat (limited to 'iov.c')
-rw-r--r-- | iov.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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, */ |