aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2012-07-11 14:35:52 +0100
committerDaniel P. Berrange <berrange@redhat.com>2012-08-07 11:47:55 +0100
commit958499b0c12072e36d20effeddf4a400d9919bb8 (patch)
treebc6693bd9b1288f0c80ec6e6800c6c905c362113 /src/rpc/virnetserverservice.c
parentTurn virSocket into a virObject (diff)
downloadlibvirt-958499b0c12072e36d20effeddf4a400d9919bb8.tar.gz
libvirt-958499b0c12072e36d20effeddf4a400d9919bb8.tar.bz2
libvirt-958499b0c12072e36d20effeddf4a400d9919bb8.zip
Turn virNetServer* into virObject instances
Make all the virNetServer* objects use the virObject APIs for reference counting Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'src/rpc/virnetserverservice.c')
-rw-r--r--src/rpc/virnetserverservice.c83
1 files changed, 39 insertions, 44 deletions
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index 93c057441..000b5b6b9 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -27,12 +27,12 @@
#include "memory.h"
#include "virterror_internal.h"
-
+#include "threads.h"
#define VIR_FROM_THIS VIR_FROM_RPC
struct _virNetServerService {
- int refs;
+ virObject object;
size_t nsocks;
virNetSocketPtr *socks;
@@ -48,6 +48,21 @@ struct _virNetServerService {
};
+static virClassPtr virNetServerServiceClass;
+static void virNetServerServiceDispose(void *obj);
+
+static int virNetServerServiceOnceInit(void)
+{
+ if (!(virNetServerServiceClass = virClassNew("virNetServerService",
+ sizeof(virNetServerService),
+ virNetServerServiceDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virNetServerService)
+
static void virNetServerServiceAccept(virNetSocketPtr sock,
int events ATTRIBUTE_UNUSED,
@@ -76,7 +91,7 @@ static void virNetServerServiceAccept(virNetSocketPtr sock,
if (svc->dispatchFunc(svc, client, svc->dispatchOpaque) < 0)
virNetServerClientClose(client);
- virNetServerClientFree(client);
+ virObjectUnref(client);
cleanup:
return;
@@ -84,21 +99,13 @@ cleanup:
error:
if (client) {
virNetServerClientClose(client);
- virNetServerClientFree(client);
+ virObjectUnref(client);
} else {
virObjectUnref(clientsock);
}
}
-static void virNetServerServiceEventFree(void *opaque)
-{
- virNetServerServicePtr svc = opaque;
-
- virNetServerServiceFree(svc);
-}
-
-
virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
const char *service,
int auth,
@@ -109,10 +116,12 @@ virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
virNetServerServicePtr svc;
size_t i;
- if (VIR_ALLOC(svc) < 0)
- goto no_memory;
+ if (virNetServerServiceInitialize() < 0)
+ return NULL;
+
+ if (!(svc = virObjectNew(virNetServerServiceClass)))
+ return NULL;
- svc->refs = 1;
svc->auth = auth;
svc->readonly = readonly;
svc->nrequests_client_max = nrequests_client_max;
@@ -130,13 +139,13 @@ virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
/* IO callback is initially disabled, until we're ready
* to deal with incoming clients */
- virNetServerServiceRef(svc);
+ virObjectRef(svc);
if (virNetSocketAddIOCallback(svc->socks[i],
0,
virNetServerServiceAccept,
svc,
- virNetServerServiceEventFree) < 0) {
- virNetServerServiceFree(svc);
+ virObjectFreeCallback) < 0) {
+ virObjectUnref(svc);
goto error;
}
}
@@ -144,10 +153,8 @@ virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
return svc;
-no_memory:
- virReportOOMError();
error:
- virNetServerServiceFree(svc);
+ virObjectUnref(svc);
return NULL;
}
@@ -163,10 +170,12 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
virNetServerServicePtr svc;
int i;
- if (VIR_ALLOC(svc) < 0)
- goto no_memory;
+ if (virNetServerServiceInitialize() < 0)
+ return NULL;
+
+ if (!(svc = virObjectNew(virNetServerServiceClass)))
+ return NULL;
- svc->refs = 1;
svc->auth = auth;
svc->readonly = readonly;
svc->nrequests_client_max = nrequests_client_max;
@@ -189,13 +198,13 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
/* IO callback is initially disabled, until we're ready
* to deal with incoming clients */
- virNetServerServiceRef(svc);
+ virObjectRef(svc);
if (virNetSocketAddIOCallback(svc->socks[i],
0,
virNetServerServiceAccept,
svc,
- virNetServerServiceEventFree) < 0) {
- virNetServerServiceFree(svc);
+ virObjectFreeCallback) < 0) {
+ virObjectUnref(svc);
goto error;
}
}
@@ -206,7 +215,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
no_memory:
virReportOOMError();
error:
- virNetServerServiceFree(svc);
+ virObjectUnref(svc);
return NULL;
}
@@ -231,12 +240,6 @@ bool virNetServerServiceIsReadonly(virNetServerServicePtr svc)
}
-void virNetServerServiceRef(virNetServerServicePtr svc)
-{
- svc->refs++;
-}
-
-
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
virNetServerServiceDispatchFunc func,
void *opaque)
@@ -246,24 +249,16 @@ void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
}
-void virNetServerServiceFree(virNetServerServicePtr svc)
+void virNetServerServiceDispose(void *obj)
{
+ virNetServerServicePtr svc = obj;
int i;
- if (!svc)
- return;
-
- svc->refs--;
- if (svc->refs > 0)
- return;
-
for (i = 0 ; i < svc->nsocks ; i++)
virObjectUnref(svc->socks[i]);
VIR_FREE(svc->socks);
virObjectUnref(svc->tls);
-
- VIR_FREE(svc);
}
void virNetServerServiceToggle(virNetServerServicePtr svc,