Refactor impl of the virNetServerClientNew method

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@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-08-09 12:52:48 +01:00
parent 42c60a7843
commit 4eb6cae884

View File

@ -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;