From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> 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@xxxxxxxxxx> --- src/rpc/virnetserver.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 03cf0b7..0a6ecdc 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -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, -- 1.7.11.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list