diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 68e1d501c3..95632cb03b 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1337,9 +1337,9 @@ done: } -int virNetClientSend(virNetClientPtr client, - virNetMessagePtr msg, - bool expectReply) +static int virNetClientSendInternal(virNetClientPtr client, + virNetMessagePtr msg, + bool expectReply) { virNetClientCallPtr call; int ret = -1; @@ -1387,3 +1387,42 @@ cleanup: virNetClientUnlock(client); return ret; } + +/* + * @msg: a message allocated on heap or stack + * + * Send a message synchronously, and wait for the reply synchronously + * + * The caller is responsible for free'ing @msg if it was allocated + * on the heap + * + * Returns 0 on success, -1 on failure + */ +int virNetClientSendWithReply(virNetClientPtr client, + virNetMessagePtr msg) +{ + int ret = virNetClientSendInternal(client, msg, true); + if (ret < 0) + return -1; + return 0; +} + + +/* + * @msg: a message allocated on heap or stack + * + * Send a message synchronously, without any reply + * + * The caller is responsible for free'ing @msg if it was allocated + * on the heap + * + * Returns 0 on success, -1 on failure + */ +int virNetClientSendNoReply(virNetClientPtr client, + virNetMessagePtr msg) +{ + int ret = virNetClientSendInternal(client, msg, false); + if (ret < 0) + return -1; + return 0; +} diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h index fb679e8973..eef3eb3bce 100644 --- a/src/rpc/virnetclient.h +++ b/src/rpc/virnetclient.h @@ -67,9 +67,11 @@ int virNetClientAddStream(virNetClientPtr client, void virNetClientRemoveStream(virNetClientPtr client, virNetClientStreamPtr st); -int virNetClientSend(virNetClientPtr client, - virNetMessagePtr msg, - bool expectReply); +int virNetClientSendWithReply(virNetClientPtr client, + virNetMessagePtr msg); + +int virNetClientSendNoReply(virNetClientPtr client, + virNetMessagePtr msg); # ifdef HAVE_SASL void virNetClientSetSASLSession(virNetClientPtr client, diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c index 36e23841e1..e1e88462f5 100644 --- a/src/rpc/virnetclientprogram.c +++ b/src/rpc/virnetclientprogram.c @@ -327,7 +327,7 @@ int virNetClientProgramCall(virNetClientProgramPtr prog, if (virNetMessageEncodePayload(msg, args_filter, args) < 0) goto error; - if (virNetClientSend(client, msg, true) < 0) + if (virNetClientSendWithReply(client, msg) < 0) goto error; /* None of these 3 should ever happen here, because diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 7e2d9aeff0..a4292e77a4 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -328,7 +328,6 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st, size_t nbytes) { virNetMessagePtr msg; - bool wantReply; VIR_DEBUG("st=%p status=%d data=%p nbytes=%zu", st, status, data, nbytes); if (!(msg = virNetMessageNew(false))) @@ -354,15 +353,17 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st, if (status == VIR_NET_CONTINUE) { if (virNetMessageEncodePayloadRaw(msg, data, nbytes) < 0) goto error; - wantReply = false; + + if (virNetClientSendNoReply(client, msg) < 0) + goto error; } else { if (virNetMessageEncodePayloadRaw(msg, NULL, 0) < 0) goto error; - wantReply = true; + + if (virNetClientSendWithReply(client, msg) < 0) + goto error; } - if (virNetClientSend(client, msg, wantReply) < 0) - goto error; virNetMessageFree(msg); @@ -407,7 +408,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st, VIR_DEBUG("Dummy packet to wait for stream data"); virMutexUnlock(&st->lock); - ret = virNetClientSend(client, msg, true); + ret = virNetClientSendWithReply(client, msg); virMutexLock(&st->lock); virNetMessageFree(msg);