aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2019-07-25 12:49:37 +0300
committerEric Blake <eblake@redhat.com>2019-08-15 13:22:13 -0500
commitaec21d31756cbda4ad1d0fc5c60797d2c1eecf33 (patch)
tree5006ab961e9f433a4d431f1eb0f990baa7e46722 /util
parent9e06029aea3b2eca1d5261352e695edc1e7d7b8b (diff)
qapi: Add InetSocketAddress member keep-alive
It's needed to provide keepalive for nbd client to track server availability. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20190725094937.32454-1-vsementsov@virtuozzo.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Acked-by: Daniel P. Berrangé <berrange@redhat.com> [eblake: Fix error message typo] Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/qemu-sockets.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index a5092dbd12..e3a1666578 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -219,6 +219,12 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
bool socket_created = false;
Error *err = NULL;
+ if (saddr->keep_alive) {
+ error_setg(errp, "keep-alive option is not supported for passive "
+ "sockets");
+ return -1;
+ }
+
memset(&ai,0, sizeof(ai));
ai.ai_flags = AI_PASSIVE;
if (saddr->has_numeric && saddr->numeric) {
@@ -458,6 +464,19 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp)
}
freeaddrinfo(res);
+
+ if (saddr->keep_alive) {
+ int val = 1;
+ int ret = qemu_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
+ &val, sizeof(val));
+
+ if (ret < 0) {
+ error_setg_errno(errp, errno, "Unable to set KEEPALIVE");
+ close(sock);
+ return -1;
+ }
+ }
+
return sock;
}
@@ -653,6 +672,15 @@ int inet_parse(InetSocketAddress *addr, const char *str, Error **errp)
}
addr->has_ipv6 = true;
}
+ begin = strstr(optstr, ",keep-alive");
+ if (begin) {
+ if (inet_parse_flag("keep-alive", begin + strlen(",keep-alive"),
+ &addr->keep_alive, errp) < 0)
+ {
+ return -1;
+ }
+ addr->has_keep_alive = true;
+ }
return 0;
}