mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
Change interaction when accepting new RPC client connections
Currently the virNetServerServicePtr is responsible for creating the virNetServerClientPtr instance when accepting a new connection. Change this so that the virNetServerServicePtr merely gives virNetServerPtr a virNetSocketPtr instance. The virNetServerPtr can then create the virNetServerClientPtr as it desires Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
2241582c6a
commit
95e49be5e2
@ -1492,8 +1492,6 @@ virNetServerKeepAliveRequired;
|
|||||||
virNetServerNew;
|
virNetServerNew;
|
||||||
virNetServerQuit;
|
virNetServerQuit;
|
||||||
virNetServerRun;
|
virNetServerRun;
|
||||||
virNetServerServiceNewTCP;
|
|
||||||
virNetServerServiceNewUNIX;
|
|
||||||
virNetServerSetTLSContext;
|
virNetServerSetTLSContext;
|
||||||
virNetServerUpdateServices;
|
virNetServerUpdateServices;
|
||||||
|
|
||||||
@ -1558,7 +1556,9 @@ virNetServerProgramUnknownError;
|
|||||||
# virnetserverservice.h
|
# virnetserverservice.h
|
||||||
virNetServerServiceClose;
|
virNetServerServiceClose;
|
||||||
virNetServerServiceGetAuth;
|
virNetServerServiceGetAuth;
|
||||||
|
virNetServerServiceGetMaxRequests;
|
||||||
virNetServerServiceGetPort;
|
virNetServerServiceGetPort;
|
||||||
|
virNetServerServiceGetTLSContext;
|
||||||
virNetServerServiceIsReadonly;
|
virNetServerServiceIsReadonly;
|
||||||
virNetServerServiceNewTCP;
|
virNetServerServiceNewTCP;
|
||||||
virNetServerServiceNewUNIX;
|
virNetServerServiceNewUNIX;
|
||||||
|
@ -261,11 +261,12 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int virNetServerDispatchNewClient(virNetServerServicePtr svc ATTRIBUTE_UNUSED,
|
static int virNetServerDispatchNewClient(virNetServerServicePtr svc,
|
||||||
virNetServerClientPtr client,
|
virNetSocketPtr clientsock,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virNetServerPtr srv = opaque;
|
virNetServerPtr srv = opaque;
|
||||||
|
virNetServerClientPtr client = NULL;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virNetServerLock(srv);
|
||||||
|
|
||||||
@ -276,6 +277,13 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc ATTRIBUTE_UN
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(client = virNetServerClientNew(clientsock,
|
||||||
|
virNetServerServiceGetAuth(svc),
|
||||||
|
virNetServerServiceIsReadonly(svc),
|
||||||
|
virNetServerServiceGetMaxRequests(svc),
|
||||||
|
virNetServerServiceGetTLSContext(svc))))
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (virNetServerClientInit(client) < 0)
|
if (virNetServerClientInit(client) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -301,6 +309,8 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc ATTRIBUTE_UN
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
virNetServerClientClose(client);
|
||||||
|
virObjectUnref(client);
|
||||||
virNetServerUnlock(srv);
|
virNetServerUnlock(srv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,7 @@ virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
client->sock = sock;
|
client->sock = virObjectRef(sock);
|
||||||
client->auth = auth;
|
client->auth = auth;
|
||||||
client->readonly = readonly;
|
client->readonly = readonly;
|
||||||
client->tlsCtxt = virObjectRef(tls);
|
client->tlsCtxt = virObjectRef(tls);
|
||||||
@ -385,8 +385,6 @@ virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
|
|||||||
return client;
|
return client;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
/* XXX ref counting is better than this */
|
|
||||||
client->sock = NULL; /* Caller owns 'sock' upon failure */
|
|
||||||
virObjectUnref(client);
|
virObjectUnref(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -69,40 +69,21 @@ static void virNetServerServiceAccept(virNetSocketPtr sock,
|
|||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virNetServerServicePtr svc = opaque;
|
virNetServerServicePtr svc = opaque;
|
||||||
virNetServerClientPtr client = NULL;
|
|
||||||
virNetSocketPtr clientsock = NULL;
|
virNetSocketPtr clientsock = NULL;
|
||||||
|
|
||||||
if (virNetSocketAccept(sock, &clientsock) < 0)
|
if (virNetSocketAccept(sock, &clientsock) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (!clientsock) /* Connection already went away */
|
if (!clientsock) /* Connection already went away */
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(client = virNetServerClientNew(clientsock,
|
|
||||||
svc->auth,
|
|
||||||
svc->readonly,
|
|
||||||
svc->nrequests_client_max,
|
|
||||||
svc->tls)))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!svc->dispatchFunc)
|
if (!svc->dispatchFunc)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (svc->dispatchFunc(svc, client, svc->dispatchOpaque) < 0)
|
svc->dispatchFunc(svc, clientsock, svc->dispatchOpaque);
|
||||||
virNetServerClientClose(client);
|
|
||||||
|
|
||||||
virObjectUnref(client);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
return;
|
virObjectUnref(clientsock);
|
||||||
|
|
||||||
error:
|
|
||||||
if (client) {
|
|
||||||
virNetServerClientClose(client);
|
|
||||||
virObjectUnref(client);
|
|
||||||
} else {
|
|
||||||
virObjectUnref(clientsock);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -240,6 +221,17 @@ bool virNetServerServiceIsReadonly(virNetServerServicePtr svc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t virNetServerServiceGetMaxRequests(virNetServerServicePtr svc)
|
||||||
|
{
|
||||||
|
return svc->nrequests_client_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
virNetTLSContextPtr virNetServerServiceGetTLSContext(virNetServerServicePtr svc)
|
||||||
|
{
|
||||||
|
return svc->tls;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
||||||
virNetServerServiceDispatchFunc func,
|
virNetServerServiceDispatchFunc func,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
|
@ -34,7 +34,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef int (*virNetServerServiceDispatchFunc)(virNetServerServicePtr svc,
|
typedef int (*virNetServerServiceDispatchFunc)(virNetServerServicePtr svc,
|
||||||
virNetServerClientPtr client,
|
virNetSocketPtr sock,
|
||||||
void *opaque);
|
void *opaque);
|
||||||
|
|
||||||
virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
|
virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
|
||||||
@ -55,6 +55,8 @@ int virNetServerServiceGetPort(virNetServerServicePtr svc);
|
|||||||
|
|
||||||
int virNetServerServiceGetAuth(virNetServerServicePtr svc);
|
int virNetServerServiceGetAuth(virNetServerServicePtr svc);
|
||||||
bool virNetServerServiceIsReadonly(virNetServerServicePtr svc);
|
bool virNetServerServiceIsReadonly(virNetServerServicePtr svc);
|
||||||
|
size_t virNetServerServiceGetMaxRequests(virNetServerServicePtr svc);
|
||||||
|
virNetTLSContextPtr virNetServerServiceGetTLSContext(virNetServerServicePtr svc);
|
||||||
|
|
||||||
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
||||||
virNetServerServiceDispatchFunc func,
|
virNetServerServiceDispatchFunc func,
|
||||||
|
Loading…
Reference in New Issue
Block a user