diff options
author | John Levon <john.levon@nutanix.com> | 2021-04-06 15:30:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 15:30:25 +0100 |
commit | f7f0ea6c4beedbb3cd2c010e84feecb76db3f46f (patch) | |
tree | 722c23bdabdd2652e33a0f1c5edc40c0d16714ca /lib/tran_sock.c | |
parent | 996d4f3cdae229fee9b5c8867d87beeb9172b97f (diff) | |
download | libvfio-user-f7f0ea6c4beedbb3cd2c010e84feecb76db3f46f.zip libvfio-user-f7f0ea6c4beedbb3cd2c010e84feecb76db3f46f.tar.gz libvfio-user-f7f0ea6c4beedbb3cd2c010e84feecb76db3f46f.tar.bz2 |
tran_sock_send_iovec(): check for full write (#416)
Report -ECONNRESET to the caller if we failed to write the full expected message.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/tran_sock.c')
-rw-r--r-- | lib/tran_sock.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/tran_sock.c b/lib/tran_sock.c index ea01a68..46b5f6b 100644 --- a/lib/tran_sock.c +++ b/lib/tran_sock.c @@ -115,10 +115,16 @@ MOCK_DEFINE(tran_sock_send_iovec)(int sock, uint16_t msg_id, bool is_reply, memcpy(CMSG_DATA(cmsg), fds, size); } - // FIXME: this doesn't check the entire data was sent? ret = sendmsg(sock, &msg, MSG_NOSIGNAL); + if (ret == -1) { + /* Treat a failed write due to EPIPE the same as a short write. */ + if (errno == EPIPE) { + return -ECONNRESET; + } return -errno; + } else if ((size_t)ret < hdr.msg_size) { + return -ECONNRESET; } return 0; |