# include <sys/socket.h>
#endif
-size_t iov_from_buf(struct iovec *iov, unsigned int iov_cnt,
+size_t iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
size_t offset, const void *buf, size_t bytes)
{
size_t done;
#else
/* else send piece-by-piece */
/*XXX Note: windows has WSASend() and WSARecv() */
- unsigned i;
- size_t count = 0;
- for (i = 0; i < iov_cnt; ++i) {
+ unsigned i = 0;
+ ssize_t ret = 0;
+ while (i < iov_cnt) {
ssize_t r = do_send
? send(sockfd, iov[i].iov_base, iov[i].iov_len, 0)
: recv(sockfd, iov[i].iov_base, iov[i].iov_len, 0);
/* else it is some "other" error,
* only return if there was no data processed. */
if (ret == 0) {
- return -1;
+ ret = -1;
}
break;
}
+ i++;
}
- return count;
+ return ret;
#endif
}
{
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, */