From e9c00cbc634730a6e8d38949d3c2c4c1fc8f14dd Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 12 Jun 2012 14:32:27 +0200 Subject: [PATCH] client rpc: Send keepalive requests from IO event loop In addition to keepalive responses, we also need to send keepalive requests from client IO loop to properly detect dead connection in case a libvirt API is called from the main loop, which prevents any timers to be called. (cherry picked from commit 4d971dc7ef1a9d0dc830c243b5731e862ad0eb5c) --- src/rpc/virnetclient.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 64738c3e97..d8bb4174c0 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1272,6 +1272,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client, char ignore; sigset_t oldmask, blockedsigs; int timeout = -1; + virNetMessagePtr msg = NULL; /* If we have existing SASL decoded data we don't want to sleep in * the poll(), just check if any other FDs are also ready. @@ -1285,6 +1286,10 @@ static int virNetClientIOEventLoop(virNetClientPtr client, if (thiscall->nonBlock) timeout = 0; + /* Limit timeout so that we can send keepalive request in time */ + if (timeout == -1) + timeout = virKeepAliveTimeout(client->keepalive); + fds[0].events = fds[0].revents = 0; fds[1].events = fds[1].revents = 0; @@ -1330,6 +1335,13 @@ static int virNetClientIOEventLoop(virNetClientPtr client, virNetClientLock(client); + if (virKeepAliveTrigger(client->keepalive, &msg)) { + client->wantClose = true; + } else if (msg && virNetClientQueueNonBlocking(client, msg) < 0) { + VIR_WARN("Could not queue keepalive request"); + virNetMessageFree(msg); + } + /* If we have existing SASL decoded data, pretend * the socket became readable so we consume it */