[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/25] add qemu_send_full and qemu_recv_full
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 01/25] add qemu_send_full and qemu_recv_full |
Date: |
Tue, 6 Dec 2011 16:27:28 +0100 |
Signed-off-by: Paolo Bonzini <address@hidden>
---
osdep.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
qemu-common.h | 4 +++
2 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/osdep.c b/osdep.c
index 56e6963..70bad27 100644
--- a/osdep.c
+++ b/osdep.c
@@ -166,3 +166,70 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t
*addrlen)
return ret;
}
+
+/*
+ * A variant of send(2) which handles partial write.
+ *
+ * Return the number of bytes transferred, which is only
+ * smaller than `count' if there is an error.
+ *
+ * This function won't work with non-blocking fd's.
+ * Any of the possibilities with non-bloking fd's is bad:
+ * - return a short write (then name is wrong)
+ * - busy wait adding (errno == EAGAIN) to the loop
+ */
+ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags)
+{
+ ssize_t ret = 0;
+ ssize_t total = 0;
+
+ while (count) {
+ ret = send(fd, buf, count, flags);
+ if (ret < 0) {
+ if (errno == EINTR) {
+ continue;
+ }
+ break;
+ }
+
+ count -= ret;
+ buf += ret;
+ total += ret;
+ }
+
+ return total;
+}
+
+/*
+ * A variant of recv(2) which handles partial write.
+ *
+ * Return the number of bytes transferred, which is only
+ * smaller than `count' if there is an error.
+ *
+ * This function won't work with non-blocking fd's.
+ * Any of the possibilities with non-bloking fd's is bad:
+ * - return a short write (then name is wrong)
+ * - busy wait adding (errno == EAGAIN) to the loop
+ */
+ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
+{
+ ssize_t ret = 0;
+ ssize_t total = 0;
+
+ while (count) {
+ ret = qemu_recv(fd, buf, count, flags);
+ if (ret <= 0) {
+ if (ret < 0 && errno == EINTR) {
+ continue;
+ }
+ break;
+ }
+
+ count -= ret;
+ buf += ret;
+ total += ret;
+ }
+
+ return total;
+}
+
diff --git a/qemu-common.h b/qemu-common.h
index 44870fe..bb60a5a 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -173,6 +173,10 @@ void *qemu_oom_check(void *ptr);
int qemu_open(const char *name, int flags, ...);
ssize_t qemu_write_full(int fd, const void *buf, size_t count)
QEMU_WARN_UNUSED_RESULT;
+ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags)
+ QEMU_WARN_UNUSED_RESULT;
+ssize_t qemu_recv_full(int fd, const void *buf, size_t count, int flags)
+ QEMU_WARN_UNUSED_RESULT;
void qemu_set_cloexec(int fd);
#ifndef _WIN32
--
1.7.7.1
- [Qemu-devel] [PATCH 00/25] nbd asynchronous operation, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 01/25] add qemu_send_full and qemu_recv_full,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 03/25] nbd: switch to asynchronous operation, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 05/25] nbd: allow multiple in-flight requests, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 04/25] nbd: split requests, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 02/25] sheepdog: move coroutine send/recv function to generic code, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 06/25] nbd: fix error handling in the server, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 08/25] nbd: add support for NBD_CMD_FLUSH, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 07/25] nbd: add support for NBD_CMD_FLAG_FUA, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 09/25] nbd: add support for NBD_CMD_TRIM, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 11/25] qemu-nbd: remove offset argument to nbd_trip, Paolo Bonzini, 2011/12/06
- [Qemu-devel] [PATCH 10/25] Update ioctl order in nbd_init() to detect EBUSY, Paolo Bonzini, 2011/12/06