aboutsummaryrefslogtreecommitdiff
path: root/lib/libmuser.c
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2020-07-09 06:21:49 -0400
committerThanos Makatos <thanos.makatos@nutanix.com>2020-07-09 06:21:49 -0400
commit346fb417008f99b25c6b95775f372ab1626f6a5b (patch)
tree2ac3424ff9bde4f33fe46f2503427edd6e91e8a3 /lib/libmuser.c
parent8b6b6d6b79280ea9fcf57f63dc0370419beb4cdc (diff)
downloadlibvfio-user-346fb417008f99b25c6b95775f372ab1626f6a5b.zip
libvfio-user-346fb417008f99b25c6b95775f372ab1626f6a5b.tar.gz
libvfio-user-346fb417008f99b25c6b95775f372ab1626f6a5b.tar.bz2
minor improvements in non-blocking receive path
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/libmuser.c')
-rw-r--r--lib/libmuser.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/libmuser.c b/lib/libmuser.c
index dc173de..6dcae8f 100644
--- a/lib/libmuser.c
+++ b/lib/libmuser.c
@@ -92,9 +92,11 @@ struct lm_ctx {
char *uuid;
int (*unmap_dma) (void *pvt, uint64_t iova);
+ /* TODO there should be a void * variable to store transport-specific stuff */
/* LM_TRANS_SOCK */
char *iommu_dir;
int iommu_dir_fd;
+ int sock_flags;
lm_irqs_t irqs; /* XXX must be last */
};
@@ -201,6 +203,9 @@ init_sock(lm_ctx_t *lm_ctx)
assert(false); /* FIXME */
return -1;
}
+ lm_ctx->sock_flags = MSG_DONTWAIT | MSG_WAITALL;
+ } else {
+ lm_ctx->sock_flags = 0;
}
if ((lm_ctx->iommu_dir_fd = open(lm_ctx->iommu_dir, O_DIRECTORY)) == -1) {
@@ -257,21 +262,12 @@ close_sock(lm_ctx_t *lm_ctx)
static int
get_request_sock(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
{
- int flags;
- ssize_t ret;
-
- if ((lm_ctx->flags & LM_FLAG_ATTACH_NB) == 0) {
- flags = 0;
- } else {
- flags = MSG_DONTWAIT;
- }
-
- ret = recv(lm_ctx->fd, cmd, sizeof(*cmd), flags);
-
- /* TODO: Handle partial receives */
- assert(ret <= 0 || (size_t)ret == sizeof(*cmd));
-
- return ret;
+ /*
+ * TODO ideally we should set O_NONBLOCK on the fd so that the syscall is
+ * faster (?). I tried that and get short reads, so we need to store the
+ * partially received buffer somewhere and retry.
+ */
+ return recv(lm_ctx->fd, cmd, sizeof(*cmd), lm_ctx->sock_flags);
}
static int
@@ -1346,6 +1342,8 @@ process_request(lm_ctx_t *lm_ctx)
return -ENOTCONN;
}
+ assert(err == sizeof cmd);
+
switch (cmd.type) {
case MUSER_IOCTL:
err = muser_ioctl(lm_ctx, &cmd);