summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2016-03-07 20:36:03 +0000
committerDaniel P. Berrange <berrange@redhat.com>2016-03-10 17:19:34 +0000
commitb16a44e13e89ee397a3d9a9e3cfa1605c3c1dc68 (patch)
tree894551b8e7841e2fddfd790c204b7ef453d6f2eb /util
parenta2d96af4bb267bd1844f71f593d07273c7fc134c (diff)
downloadqemu-b16a44e13e89ee397a3d9a9e3cfa1605c3c1dc68.zip
osdep: remove use of socket_error() from all code
Now that QEMU wraps the Win32 sockets methods to automatically set errno upon failure, there is no reason for callers to use the socket_error() method. They can rely on accessing errno even on Win32. Remove all use of socket_error() from general code, leaving it as a static method in oslib-win32.c only. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/oslib-win32.c2
-rw-r--r--util/qemu-coroutine-io.c6
-rw-r--r--util/qemu-sockets.c10
3 files changed, 8 insertions, 10 deletions
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index a6256de0fc..a3f0664763 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -145,7 +145,7 @@ int socket_set_fast_reuse(int fd)
}
-int socket_error(void)
+static int socket_error(void)
{
switch (WSAGetLastError()) {
case 0:
diff --git a/util/qemu-coroutine-io.c b/util/qemu-coroutine-io.c
index 0d5041c1c3..91b9357d4a 100644
--- a/util/qemu-coroutine-io.c
+++ b/util/qemu-coroutine-io.c
@@ -35,18 +35,16 @@ qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,
{
size_t done = 0;
ssize_t ret;
- int err;
while (done < bytes) {
ret = iov_send_recv(sockfd, iov, iov_cnt,
offset + done, bytes - done, do_send);
if (ret > 0) {
done += ret;
} else if (ret < 0) {
- err = socket_error();
- if (err == EAGAIN || err == EWOULDBLOCK) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
qemu_coroutine_yield();
} else if (done == 0) {
- return -err;
+ return -errno;
} else {
break;
}
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index ad7c00c9ad..fd37ac209b 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -268,7 +268,7 @@ static void wait_for_connect(void *opaque)
do {
rc = qemu_getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &val, &valsize);
- } while (rc == -1 && socket_error() == EINTR);
+ } while (rc == -1 && errno == EINTR);
/* update rc to contain error */
if (!rc && val) {
@@ -330,7 +330,7 @@ static int inet_connect_addr(struct addrinfo *addr, bool *in_progress,
do {
rc = 0;
if (connect(sock, addr->ai_addr, addr->ai_addrlen) < 0) {
- rc = -socket_error();
+ rc = -errno;
}
} while (rc == -EINTR);
@@ -787,7 +787,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp,
do {
rc = 0;
if (connect(sock, (struct sockaddr *) &un, sizeof(un)) < 0) {
- rc = -socket_error();
+ rc = -errno;
}
} while (rc == -EINTR);
@@ -1082,7 +1082,7 @@ SocketAddress *socket_local_address(int fd, Error **errp)
socklen_t sslen = sizeof(ss);
if (getsockname(fd, (struct sockaddr *)&ss, &sslen) < 0) {
- error_setg_errno(errp, socket_error(), "%s",
+ error_setg_errno(errp, errno, "%s",
"Unable to query local socket address");
return NULL;
}
@@ -1097,7 +1097,7 @@ SocketAddress *socket_remote_address(int fd, Error **errp)
socklen_t sslen = sizeof(ss);
if (getpeername(fd, (struct sockaddr *)&ss, &sslen) < 0) {
- error_setg_errno(errp, socket_error(), "%s",
+ error_setg_errno(errp, errno, "%s",
"Unable to query remote socket address");
return NULL;
}