In next patches we'll add stream state checks to this function that applicable to all call paths. This is handy place because we hold client lock here. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- src/libvirt_remote.syms | 2 +- src/rpc/virnetclient.c | 13 ++++++++----- src/rpc/virnetclient.h | 6 +++--- src/rpc/virnetclientstream.c | 12 ++++-------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 9a33626..704f7ea 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -39,8 +39,8 @@ virNetClientRemoteAddrStringSASL; virNetClientRemoveStream; virNetClientSendNonBlock; virNetClientSendNoReply; +virNetClientSendStream; virNetClientSendWithReply; -virNetClientSendWithReplyStream; virNetClientSetCloseCallback; virNetClientSetTLSSession; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 7aa5223..29c4dc5 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -2205,18 +2205,21 @@ int virNetClientSendNonBlock(virNetClientPtr client, /* * @msg: a message allocated on heap or stack * - * Send a message synchronously, and wait for the reply synchronously + * Send a message synchronously, and wait for the reply synchronously if + * message is dummy (just to wait for incoming data) or abort/finish message. * * The caller is responsible for free'ing @msg if it was allocated * on the heap * * Returns 0 on success, -1 on failure */ -int virNetClientSendWithReplyStream(virNetClientPtr client, - virNetMessagePtr msg, - virNetClientStreamPtr st) +int virNetClientSendStream(virNetClientPtr client, + virNetMessagePtr msg, + virNetClientStreamPtr st) { int ret = -1; + bool expectReply = !msg->bufferLength || + msg->header.status != VIR_NET_CONTINUE; virObjectLock(client); @@ -2229,7 +2232,7 @@ int virNetClientSendWithReplyStream(virNetClientPtr client, goto cleanup; } - if (virNetClientSendInternal(client, msg, true, false) < 0) + if (virNetClientSendInternal(client, msg, expectReply, false) < 0) goto cleanup; ret = 0; diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h index 39a6176..12ac2b5 100644 --- a/src/rpc/virnetclient.h +++ b/src/rpc/virnetclient.h @@ -115,9 +115,9 @@ int virNetClientSendNoReply(virNetClientPtr client, int virNetClientSendNonBlock(virNetClientPtr client, virNetMessagePtr msg); -int virNetClientSendWithReplyStream(virNetClientPtr client, - virNetMessagePtr msg, - virNetClientStreamPtr st); +int virNetClientSendStream(virNetClientPtr client, + virNetMessagePtr msg, + virNetClientStreamPtr st); # ifdef WITH_SASL void virNetClientSetSASLSession(virNetClientPtr client, diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 3b0db52..65aa583 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -343,17 +343,13 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st, if (status == VIR_NET_CONTINUE) { if (virNetMessageEncodePayloadRaw(msg, data, nbytes) < 0) goto error; - - if (virNetClientSendNoReply(client, msg) < 0) - goto error; } else { if (virNetMessageEncodePayloadRaw(msg, NULL, 0) < 0) goto error; - - if (virNetClientSendWithReplyStream(client, msg, st) < 0) - goto error; } + if (virNetClientSendStream(client, msg, st) < 0) + goto error; virNetMessageFree(msg); @@ -500,7 +496,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st, VIR_DEBUG("Dummy packet to wait for stream data"); virObjectUnlock(st); - ret = virNetClientSendWithReplyStream(client, msg, st); + ret = virNetClientSendStream(client, msg, st); virObjectLock(st); virNetMessageFree(msg); @@ -627,7 +623,7 @@ virNetClientStreamSendHole(virNetClientStreamPtr st, &data) < 0) goto cleanup; - if (virNetClientSendNoReply(client, msg) < 0) + if (virNetClientSendStream(client, msg, st) < 0) goto cleanup; ret = 0; -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list