aboutsummaryrefslogtreecommitdiff
path: root/lib/tran_sock.c
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-02-09 15:01:05 +0000
committerGitHub <noreply@github.com>2021-02-09 15:01:05 +0000
commit2358bc9c610a50c542b3cb33a8eba0363c9e5315 (patch)
tree4a386a4df5b3fd3cb22419bc23bb4c7d1d07a41b /lib/tran_sock.c
parent687f2a333d7dd0aeed741c2781dd6ef151a22040 (diff)
downloadlibvfio-user-2358bc9c610a50c542b3cb33a8eba0363c9e5315.zip
libvfio-user-2358bc9c610a50c542b3cb33a8eba0363c9e5315.tar.gz
libvfio-user-2358bc9c610a50c542b3cb33a8eba0363c9e5315.tar.bz2
remove recv_blocking() (#316)
It has the incorrect implication that other socket I/O is necessarily non-blocking. Replace with an explicit recv(..., MSG_WAITALL). Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'lib/tran_sock.c')
-rw-r--r--lib/tran_sock.c25
1 files changed, 3 insertions, 22 deletions
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index fe54736..c756d39 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -51,25 +51,6 @@
// FIXME: is this the value we want?
#define SERVER_MAX_FDS 8
-static inline int
-recv_blocking(int sock, void *buf, size_t len, int flags)
-{
- int f = fcntl(sock, F_GETFL, 0);
- int ret, fret;
-
- fret = fcntl(sock, F_SETFL, f & ~O_NONBLOCK);
- assert(fret != -1);
-
- // FIXME: be more explicit about EOF
-
- ret = recv(sock, buf, len, flags);
-
- fret = fcntl(sock, F_SETFL, f);
- assert(fret != -1);
-
- return ret;
-}
-
static int
tran_sock_init(vfu_ctx_t *vfu_ctx)
{
@@ -316,8 +297,8 @@ tran_sock_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
}
if (len != NULL && *len > 0 && hdr->msg_size > sizeof *hdr) {
- ret = recv_blocking(sock, data, MIN(hdr->msg_size - sizeof *hdr, *len),
- 0);
+ ret = recv(sock, data, MIN(hdr->msg_size - sizeof *hdr, *len),
+ MSG_WAITALL);
if (ret < 0) {
return ret;
}
@@ -372,7 +353,7 @@ tran_sock_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
return -errno;
}
- ret = recv_blocking(sock, data, len, 0);
+ ret = recv(sock, data, len, MSG_WAITALL);
if (ret < 0) {
free(data);
return -errno;