Refactor the way new clients are registered with the server

Currently the virNetServerDispatchNewClient both creates the
virNetServerClientPtr instance and registers it with the
virNetServerPtr internal state. Split the client registration
code out into a separate virNetServerAddClient method to
allow future reuse from other contexts

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-08-09 12:35:43 +01:00
parent ee7b4e551e
commit 42c60a7843

View File

@ -262,13 +262,9 @@ cleanup:
}
static int virNetServerDispatchNewClient(virNetServerServicePtr svc,
virNetSocketPtr clientsock,
void *opaque)
static int virNetServerAddClient(virNetServerPtr srv,
virNetServerClientPtr client)
{
virNetServerPtr srv = opaque;
virNetServerClientPtr client = NULL;
virNetServerLock(srv);
if (srv->nclients >= srv->nclients_max) {
@ -278,16 +274,6 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc,
goto error;
}
if (!(client = virNetServerClientNew(clientsock,
virNetServerServiceGetAuth(svc),
virNetServerServiceIsReadonly(svc),
virNetServerServiceGetMaxRequests(svc),
virNetServerServiceGetTLSContext(svc),
srv->clientPrivNew,
srv->clientPrivFree,
srv->clientPrivOpaque)))
goto error;
if (virNetServerClientInit(client) < 0)
goto error;
@ -309,12 +295,36 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc,
return 0;
error:
virNetServerClientClose(client);
virObjectUnref(client);
virNetServerUnlock(srv);
return -1;
}
static int virNetServerDispatchNewClient(virNetServerServicePtr svc,
virNetSocketPtr clientsock,
void *opaque)
{
virNetServerPtr srv = opaque;
virNetServerClientPtr client;
if (!(client = virNetServerClientNew(clientsock,
virNetServerServiceGetAuth(svc),
virNetServerServiceIsReadonly(svc),
virNetServerServiceGetMaxRequests(svc),
virNetServerServiceGetTLSContext(svc),
srv->clientPrivNew,
srv->clientPrivFree,
srv->clientPrivOpaque)))
return -1;
if (virNetServerAddClient(srv, client) < 0) {
virNetServerClientClose(client);
virObjectUnref(client);
return -1;
}
virObjectUnref(client);
return 0;
}
static void
virNetServerFatalSignal(int sig, siginfo_t *siginfo ATTRIBUTE_UNUSED,