Skip to content

Commit 5520530

Browse files
committed
Use recvmsg() instead of readv()
1 parent 0347646 commit 5520530

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/lwan-io-wrappers.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,18 @@ ssize_t lwan_readv_fd(struct lwan_request *request,
100100
int curr_iov = 0;
101101

102102
for (int tries = MAX_FAILED_TRIES; tries;) {
103-
ssize_t bytes_read = readv(fd, iov + curr_iov, iov_count - curr_iov);
103+
const int remaining_len = (int)(iov_count - curr_iov);
104+
105+
if (remaining_len == 1) {
106+
const struct iovec *vec = &iov[curr_iov];
107+
return lwan_recv_fd(request, fd, vec->iov_base, vec->iov_len, 0);
108+
}
109+
110+
struct msghdr hdr = {
111+
.msg_iov = iov + curr_iov,
112+
.msg_iovlen = (size_t)remaining_len,
113+
};
114+
ssize_t bytes_read = recvmsg(fd, &hdr, 0);
104115
if (UNLIKELY(bytes_read < 0)) {
105116
/* FIXME: Consider short reads as another try as well? */
106117
tries--;

0 commit comments

Comments
 (0)