mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
rpc: use single function to send stream messages
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@virtuozzo.com>
This commit is contained in:
parent
a5445a3706
commit
2fd435b785
@ -39,8 +39,8 @@ virNetClientRemoteAddrStringSASL;
|
|||||||
virNetClientRemoveStream;
|
virNetClientRemoveStream;
|
||||||
virNetClientSendNonBlock;
|
virNetClientSendNonBlock;
|
||||||
virNetClientSendNoReply;
|
virNetClientSendNoReply;
|
||||||
|
virNetClientSendStream;
|
||||||
virNetClientSendWithReply;
|
virNetClientSendWithReply;
|
||||||
virNetClientSendWithReplyStream;
|
|
||||||
virNetClientSetCloseCallback;
|
virNetClientSetCloseCallback;
|
||||||
virNetClientSetTLSSession;
|
virNetClientSetTLSSession;
|
||||||
|
|
||||||
|
@ -2205,18 +2205,21 @@ int virNetClientSendNonBlock(virNetClientPtr client,
|
|||||||
/*
|
/*
|
||||||
* @msg: a message allocated on heap or stack
|
* @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
|
* The caller is responsible for free'ing @msg if it was allocated
|
||||||
* on the heap
|
* on the heap
|
||||||
*
|
*
|
||||||
* Returns 0 on success, -1 on failure
|
* Returns 0 on success, -1 on failure
|
||||||
*/
|
*/
|
||||||
int virNetClientSendWithReplyStream(virNetClientPtr client,
|
int virNetClientSendStream(virNetClientPtr client,
|
||||||
virNetMessagePtr msg,
|
virNetMessagePtr msg,
|
||||||
virNetClientStreamPtr st)
|
virNetClientStreamPtr st)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
bool expectReply = !msg->bufferLength ||
|
||||||
|
msg->header.status != VIR_NET_CONTINUE;
|
||||||
|
|
||||||
virObjectLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
@ -2229,7 +2232,7 @@ int virNetClientSendWithReplyStream(virNetClientPtr client,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNetClientSendInternal(client, msg, true, false) < 0)
|
if (virNetClientSendInternal(client, msg, expectReply, false) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -115,9 +115,9 @@ int virNetClientSendNoReply(virNetClientPtr client,
|
|||||||
int virNetClientSendNonBlock(virNetClientPtr client,
|
int virNetClientSendNonBlock(virNetClientPtr client,
|
||||||
virNetMessagePtr msg);
|
virNetMessagePtr msg);
|
||||||
|
|
||||||
int virNetClientSendWithReplyStream(virNetClientPtr client,
|
int virNetClientSendStream(virNetClientPtr client,
|
||||||
virNetMessagePtr msg,
|
virNetMessagePtr msg,
|
||||||
virNetClientStreamPtr st);
|
virNetClientStreamPtr st);
|
||||||
|
|
||||||
# ifdef WITH_SASL
|
# ifdef WITH_SASL
|
||||||
void virNetClientSetSASLSession(virNetClientPtr client,
|
void virNetClientSetSASLSession(virNetClientPtr client,
|
||||||
|
@ -343,17 +343,13 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
|
|||||||
if (status == VIR_NET_CONTINUE) {
|
if (status == VIR_NET_CONTINUE) {
|
||||||
if (virNetMessageEncodePayloadRaw(msg, data, nbytes) < 0)
|
if (virNetMessageEncodePayloadRaw(msg, data, nbytes) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virNetClientSendNoReply(client, msg) < 0)
|
|
||||||
goto error;
|
|
||||||
} else {
|
} else {
|
||||||
if (virNetMessageEncodePayloadRaw(msg, NULL, 0) < 0)
|
if (virNetMessageEncodePayloadRaw(msg, NULL, 0) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virNetClientSendWithReplyStream(client, msg, st) < 0)
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virNetClientSendStream(client, msg, st) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
virNetMessageFree(msg);
|
virNetMessageFree(msg);
|
||||||
|
|
||||||
@ -500,7 +496,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
|
|||||||
|
|
||||||
VIR_DEBUG("Dummy packet to wait for stream data");
|
VIR_DEBUG("Dummy packet to wait for stream data");
|
||||||
virObjectUnlock(st);
|
virObjectUnlock(st);
|
||||||
ret = virNetClientSendWithReplyStream(client, msg, st);
|
ret = virNetClientSendStream(client, msg, st);
|
||||||
virObjectLock(st);
|
virObjectLock(st);
|
||||||
virNetMessageFree(msg);
|
virNetMessageFree(msg);
|
||||||
|
|
||||||
@ -627,7 +623,7 @@ virNetClientStreamSendHole(virNetClientStreamPtr st,
|
|||||||
&data) < 0)
|
&data) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virNetClientSendNoReply(client, msg) < 0)
|
if (virNetClientSendStream(client, msg, st) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user