Split virNetClientSend into 2 methods

Stop multiplexing virNetClientSend for two different purposes,
instead add virNetClientSendWithReply and virNetClientSendNoReply

* src/rpc/virnetclient.c, src/rpc/virnetclient.h: Replace
  virNetClientSend with virNetClientSendWithReply and
  virNetClientSendNoReply
* src/rpc/virnetclientprogram.c, src/rpc/virnetclientstream.c:
  Update for new API names
This commit is contained in:
Daniel P. Berrange 2011-11-11 15:42:46 +00:00
parent 9f28ad0026
commit 5990f227e9
4 changed files with 55 additions and 13 deletions

View File

@ -1337,9 +1337,9 @@ done:
} }
int virNetClientSend(virNetClientPtr client, static int virNetClientSendInternal(virNetClientPtr client,
virNetMessagePtr msg, virNetMessagePtr msg,
bool expectReply) bool expectReply)
{ {
virNetClientCallPtr call; virNetClientCallPtr call;
int ret = -1; int ret = -1;
@ -1387,3 +1387,42 @@ cleanup:
virNetClientUnlock(client); virNetClientUnlock(client);
return ret; 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;
}

View File

@ -67,9 +67,11 @@ int virNetClientAddStream(virNetClientPtr client,
void virNetClientRemoveStream(virNetClientPtr client, void virNetClientRemoveStream(virNetClientPtr client,
virNetClientStreamPtr st); virNetClientStreamPtr st);
int virNetClientSend(virNetClientPtr client, int virNetClientSendWithReply(virNetClientPtr client,
virNetMessagePtr msg, virNetMessagePtr msg);
bool expectReply);
int virNetClientSendNoReply(virNetClientPtr client,
virNetMessagePtr msg);
# ifdef HAVE_SASL # ifdef HAVE_SASL
void virNetClientSetSASLSession(virNetClientPtr client, void virNetClientSetSASLSession(virNetClientPtr client,

View File

@ -327,7 +327,7 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
if (virNetMessageEncodePayload(msg, args_filter, args) < 0) if (virNetMessageEncodePayload(msg, args_filter, args) < 0)
goto error; goto error;
if (virNetClientSend(client, msg, true) < 0) if (virNetClientSendWithReply(client, msg) < 0)
goto error; goto error;
/* None of these 3 should ever happen here, because /* None of these 3 should ever happen here, because

View File

@ -328,7 +328,6 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
size_t nbytes) size_t nbytes)
{ {
virNetMessagePtr msg; virNetMessagePtr msg;
bool wantReply;
VIR_DEBUG("st=%p status=%d data=%p nbytes=%zu", st, status, data, nbytes); VIR_DEBUG("st=%p status=%d data=%p nbytes=%zu", st, status, data, nbytes);
if (!(msg = virNetMessageNew(false))) if (!(msg = virNetMessageNew(false)))
@ -354,15 +353,17 @@ 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;
wantReply = false;
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;
wantReply = true;
if (virNetClientSendWithReply(client, msg) < 0)
goto error;
} }
if (virNetClientSend(client, msg, wantReply) < 0)
goto error;
virNetMessageFree(msg); virNetMessageFree(msg);
@ -407,7 +408,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
VIR_DEBUG("Dummy packet to wait for stream data"); VIR_DEBUG("Dummy packet to wait for stream data");
virMutexUnlock(&st->lock); virMutexUnlock(&st->lock);
ret = virNetClientSend(client, msg, true); ret = virNetClientSendWithReply(client, msg);
virMutexLock(&st->lock); virMutexLock(&st->lock);
virNetMessageFree(msg); virNetMessageFree(msg);