[PATCH 09/23] Refactor impl of the virNetServerClientNew method

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

In preparation for adding further constructors, refactor
the virNetServerClientNew method to move most of the code
into a common virNetServerClientNewInternal helper API.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/rpc/virnetserverclient.c | 52 +++++++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index c9703fd..acd2b4d 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -336,19 +336,15 @@ static void virNetServerClientSockTimerFunc(int timer,
 }
 
 
-virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
-                                            int auth,
-                                            bool readonly,
-                                            size_t nrequests_max,
-                                            virNetTLSContextPtr tls,
-                                            virNetServerClientPrivNew privNew,
-                                            virFreeCallback privFree,
-                                            void *privOpaque)
+static virNetServerClientPtr
+virNetServerClientNewInternal(virNetSocketPtr sock,
+                              int auth,
+                              bool readonly,
+                              size_t nrequests_max,
+                              virNetTLSContextPtr tls)
 {
     virNetServerClientPtr client;
 
-    VIR_DEBUG("sock=%p auth=%d tls=%p", sock, auth, tls);
-
     if (virNetServerClientInitialize() < 0)
         return NULL;
 
@@ -381,14 +377,6 @@ virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
     }
     client->nrequests = 1;
 
-    if (privNew) {
-        if (!(client->privateData = privNew(client, privOpaque))) {
-            virObjectUnref(client);
-            goto error;
-        }
-        client->privateDataFreeFunc = privFree;
-    }
-
     PROBE(RPC_SERVER_CLIENT_NEW,
           "client=%p sock=%p",
           client, client->sock);
@@ -401,6 +389,34 @@ error:
 }
 
 
+virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
+                                            int auth,
+                                            bool readonly,
+                                            size_t nrequests_max,
+                                            virNetTLSContextPtr tls,
+                                            virNetServerClientPrivNew privNew,
+                                            virFreeCallback privFree,
+                                            void *privOpaque)
+{
+    virNetServerClientPtr client;
+
+    VIR_DEBUG("sock=%p auth=%d tls=%p", sock, auth, tls);
+
+    if (!(client = virNetServerClientNewInternal(sock, auth, readonly, nrequests_max, tls)))
+        return NULL;
+
+    if (privNew) {
+        if (!(client->privateData = privNew(client, privOpaque))) {
+            virObjectUnref(client);
+            return NULL;
+        }
+        client->privateDataFreeFunc = privFree;
+    }
+
+    return client;
+}
+
+
 int virNetServerClientGetAuth(virNetServerClientPtr client)
 {
     int auth;
-- 
1.7.11.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]