aboutsummaryrefslogtreecommitdiff
path: root/lib/tran_sock.c
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2022-04-19 10:35:24 +0100
committerGitHub <noreply@github.com>2022-04-19 10:35:24 +0100
commit9ad7474568a6c9f1fbb12fb8048f2083078a8144 (patch)
tree291ad39660c6bf075fe72eb3f8539d94200dfb27 /lib/tran_sock.c
parentcdf824cf0229f0cad6679967293eb03aa48919fd (diff)
downloadlibvfio-user-9ad7474568a6c9f1fbb12fb8048f2083078a8144.zip
libvfio-user-9ad7474568a6c9f1fbb12fb8048f2083078a8144.tar.gz
libvfio-user-9ad7474568a6c9f1fbb12fb8048f2083078a8144.tar.bz2
use struct iovec for grouping buffer and length (#658)
This make it tidier and easier to pass to function the buffer and length, instead of passing the whole msg. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
Diffstat (limited to 'lib/tran_sock.c')
-rw-r--r--lib/tran_sock.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index fb2dab7..19bf370 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -806,30 +806,30 @@ tran_sock_recv_body(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg)
ts = vfu_ctx->tran_data;
- assert(msg->in_size <= SERVER_MAX_MSG_SIZE);
+ assert(msg->in.iov.iov_len <= SERVER_MAX_MSG_SIZE);
- msg->in_data = malloc(msg->in_size);
+ msg->in.iov.iov_base = malloc(msg->in.iov.iov_len);
- if (msg->in_data == NULL) {
+ if (msg->in.iov.iov_base == NULL) {
return -1;
}
- ret = recv(ts->conn_fd, msg->in_data, msg->in_size, 0);
+ ret = recv(ts->conn_fd, msg->in.iov.iov_base, msg->in.iov.iov_len, 0);
if (ret < 0) {
ret = errno;
- free(msg->in_data);
- msg->in_data = NULL;
+ free(msg->in.iov.iov_base);
+ msg->in.iov.iov_base = NULL;
return ERROR_INT(ret);
} else if (ret == 0) {
- free(msg->in_data);
- msg->in_data = NULL;
+ free(msg->in.iov.iov_base);
+ msg->in.iov.iov_base = NULL;
return ERROR_INT(ENOMSG);
- } else if (ret != (int)msg->in_size) {
+ } else if (ret != (int)msg->in.iov.iov_len) {
vfu_log(vfu_ctx, LOG_ERR, "msg%#hx: short read: expected=%zu, actual=%d",
- msg->hdr.msg_id, msg->in_size, ret);
- free(msg->in_data);
- msg->in_data = NULL;
+ msg->hdr.msg_id, msg->in.iov.iov_len, ret);
+ free(msg->in.iov.iov_base);
+ msg->in.iov.iov_base = NULL;
return ERROR_INT(EINVAL);
}
@@ -862,13 +862,13 @@ tran_sock_reply(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg, int err)
bcopy(msg->out_iovecs, iovecs + 1,
msg->nr_out_iovecs * sizeof(*iovecs));
} else {
- iovecs[1].iov_base = msg->out_data;
- iovecs[1].iov_len = msg->out_size;
+ iovecs[1].iov_base = msg->out.iov.iov_base;
+ iovecs[1].iov_len = msg->out.iov.iov_len;
}
ret = tran_sock_send_iovec(ts->conn_fd, msg->hdr.msg_id, true, msg->hdr.cmd,
iovecs, nr_iovecs,
- msg->out_fds, msg->nr_out_fds, err);
+ msg->out.fds, msg->out.nr_fds, err);
free(iovecs);