[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 4/6] Split virNetClientSend into 2 methods



From: "Daniel P. Berrange" <berrange redhat com>

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
---
 src/rpc/virnetclient.c        |   45 ++++++++++++++++++++++++++++++++++++++--
 src/rpc/virnetclient.h        |    8 ++++--
 src/rpc/virnetclientprogram.c |    2 +-
 src/rpc/virnetclientstream.c  |   13 ++++++-----
 4 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 1f46965..c4136b4 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 fb679e8..eef3eb3 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 36e2384..e1e8846 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 7e2d9ae..a4292e7 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);
 
-- 
1.7.6.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]