Turn virNetClient* into virObject instances

Make all the virNetClient* objects use virObject APIs for
reference counting

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-07-30 10:14:56 +01:00
parent 958499b0c1
commit 05e4e7b46e
12 changed files with 111 additions and 150 deletions

3
cfg.mk
View File

@ -145,9 +145,6 @@ useless_free_options = \
--name=virJSONValueFree \ --name=virJSONValueFree \
--name=virLastErrFreeData \ --name=virLastErrFreeData \
--name=virNetMessageFree \ --name=virNetMessageFree \
--name=virNetClientFree \
--name=virNetClientProgramFree \
--name=virNetClientStreamFree \
--name=virNetServerMDNSFree \ --name=virNetServerMDNSFree \
--name=virNetServerMDNSEntryFree \ --name=virNetServerMDNSEntryFree \
--name=virNetServerMDNSGroupFree \ --name=virNetServerMDNSGroupFree \

View File

@ -1304,7 +1304,6 @@ virNetClientAddProgram;
virNetClientAddStream; virNetClientAddStream;
virNetClientClose; virNetClientClose;
virNetClientDupFD; virNetClientDupFD;
virNetClientFree;
virNetClientGetFD; virNetClientGetFD;
virNetClientGetTLSKeySize; virNetClientGetTLSKeySize;
virNetClientHasPassFD; virNetClientHasPassFD;
@ -1318,7 +1317,6 @@ virNetClientNewExternal;
virNetClientNewSSH; virNetClientNewSSH;
virNetClientNewTCP; virNetClientNewTCP;
virNetClientNewUNIX; virNetClientNewUNIX;
virNetClientRef;
virNetClientRemoteAddrString; virNetClientRemoteAddrString;
virNetClientRemoveStream; virNetClientRemoveStream;
virNetClientSendNoReply; virNetClientSendNoReply;
@ -1333,12 +1331,10 @@ virNetClientSetTLSSession;
# virnetclientprogram.h # virnetclientprogram.h
virNetClientProgramCall; virNetClientProgramCall;
virNetClientProgramDispatch; virNetClientProgramDispatch;
virNetClientProgramFree;
virNetClientProgramGetProgram; virNetClientProgramGetProgram;
virNetClientProgramGetVersion; virNetClientProgramGetVersion;
virNetClientProgramMatches; virNetClientProgramMatches;
virNetClientProgramNew; virNetClientProgramNew;
virNetClientProgramRef;
# virnetclientstream.h # virnetclientstream.h
@ -1346,13 +1342,11 @@ virNetClientStreamEOF;
virNetClientStreamEventAddCallback; virNetClientStreamEventAddCallback;
virNetClientStreamEventRemoveCallback; virNetClientStreamEventRemoveCallback;
virNetClientStreamEventUpdateCallback; virNetClientStreamEventUpdateCallback;
virNetClientStreamFree;
virNetClientStreamMatches; virNetClientStreamMatches;
virNetClientStreamNew; virNetClientStreamNew;
virNetClientStreamQueuePacket; virNetClientStreamQueuePacket;
virNetClientStreamRaiseError; virNetClientStreamRaiseError;
virNetClientStreamRecvPacket; virNetClientStreamRecvPacket;
virNetClientStreamRef;
virNetClientStreamSendPacket; virNetClientStreamSendPacket;
virNetClientStreamSetError; virNetClientStreamSetError;

View File

@ -40,9 +40,7 @@ provider libvirt {
# file: src/rpc/virnetclient.c # file: src/rpc/virnetclient.c
# prefix: rpc # prefix: rpc
probe rpc_client_new(void *client, int refs, void *sock); probe rpc_client_new(void *client, void *sock);
probe rpc_client_ref(void *client, int refs);
probe rpc_client_free(void *client, int refs);
probe rpc_client_msg_tx_queue(void *client, int len, int prog, int vers, int proc, int type, int status, int serial); probe rpc_client_msg_tx_queue(void *client, int len, int prog, int vers, int proc, int type, int status, int serial);
probe rpc_client_msg_rx(void *client, int len, int prog, int vers, int proc, int type, int status, int serial); probe rpc_client_msg_rx(void *client, int len, int prog, int vers, int proc, int type, int status, int serial);

View File

@ -170,7 +170,7 @@ static void virLXCMonitorFree(virLXCMonitorPtr mon)
if (mon->cb && mon->cb->destroy) if (mon->cb && mon->cb->destroy)
(mon->cb->destroy)(mon, mon->vm); (mon->cb->destroy)(mon, mon->vm);
virMutexDestroy(&mon->lock); virMutexDestroy(&mon->lock);
virNetClientProgramFree(mon->program); virObjectUnref(mon->program);
VIR_FREE(mon); VIR_FREE(mon);
} }
@ -199,7 +199,7 @@ void virLXCMonitorClose(virLXCMonitorPtr mon)
{ {
if (mon->client) { if (mon->client) {
virNetClientClose(mon->client); virNetClientClose(mon->client);
virNetClientFree(mon->client); virObjectUnref(mon->client);
mon->client = NULL; mon->client = NULL;
} }
} }

View File

@ -792,10 +792,10 @@ doRemoteOpen (virConnectPtr conn,
virReportOOMError(); virReportOOMError();
failed: failed:
virNetClientProgramFree(priv->remoteProgram); virObjectUnref(priv->remoteProgram);
virNetClientProgramFree(priv->qemuProgram); virObjectUnref(priv->qemuProgram);
virNetClientClose(priv->client); virNetClientClose(priv->client);
virNetClientFree(priv->client); virObjectUnref(priv->client);
priv->client = NULL; priv->client = NULL;
VIR_FREE(priv->hostname); VIR_FREE(priv->hostname);
@ -946,10 +946,10 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
virObjectUnref(priv->tls); virObjectUnref(priv->tls);
priv->tls = NULL; priv->tls = NULL;
virNetClientClose(priv->client); virNetClientClose(priv->client);
virNetClientFree(priv->client); virObjectUnref(priv->client);
priv->client = NULL; priv->client = NULL;
virNetClientProgramFree(priv->remoteProgram); virObjectUnref(priv->remoteProgram);
virNetClientProgramFree(priv->qemuProgram); virObjectUnref(priv->qemuProgram);
priv->remoteProgram = priv->qemuProgram = NULL; priv->remoteProgram = priv->qemuProgram = NULL;
/* Free hostname copy */ /* Free hostname copy */
@ -4171,7 +4171,7 @@ remoteStreamFinish(virStreamPtr st)
cleanup: cleanup:
virNetClientRemoveStream(priv->client, privst); virNetClientRemoveStream(priv->client, privst);
virNetClientStreamFree(privst); virObjectUnref(privst);
st->privateData = NULL; st->privateData = NULL;
st->driver = NULL; st->driver = NULL;
@ -4206,7 +4206,7 @@ remoteStreamAbort(virStreamPtr st)
cleanup: cleanup:
virNetClientRemoveStream(priv->client, privst); virNetClientRemoveStream(priv->client, privst);
virNetClientStreamFree(privst); virObjectUnref(privst);
st->privateData = NULL; st->privateData = NULL;
st->driver = NULL; st->driver = NULL;
@ -4507,7 +4507,7 @@ remoteDomainMigratePrepareTunnel3(virConnectPtr dconn,
goto done; goto done;
if (virNetClientAddStream(priv->client, netst) < 0) { if (virNetClientAddStream(priv->client, netst) < 0) {
virNetClientStreamFree(netst); virObjectUnref(netst);
goto done; goto done;
} }
@ -4525,7 +4525,7 @@ remoteDomainMigratePrepareTunnel3(virConnectPtr dconn,
(xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_args, (char *) &args, (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_args, (char *) &args,
(xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_ret, (char *) &ret) == -1) { (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_ret, (char *) &ret) == -1) {
virNetClientRemoveStream(priv->client, netst); virNetClientRemoveStream(priv->client, netst);
virNetClientStreamFree(netst); virObjectUnref(netst);
goto done; goto done;
} }

View File

@ -1450,7 +1450,7 @@ elsif ($opt_k) {
print " goto done;\n"; print " goto done;\n";
print "\n"; print "\n";
print " if (virNetClientAddStream(priv->client, netst) < 0) {\n"; print " if (virNetClientAddStream(priv->client, netst) < 0) {\n";
print " virNetClientStreamFree(netst);\n"; print " virObjectUnref(netst);\n";
print " goto done;\n"; print " goto done;\n";
print " }"; print " }";
print "\n"; print "\n";
@ -1526,7 +1526,7 @@ elsif ($opt_k) {
if ($call->{streamflag} ne "none") { if ($call->{streamflag} ne "none") {
print " virNetClientRemoveStream(priv->client, netst);\n"; print " virNetClientRemoveStream(priv->client, netst);\n";
print " virNetClientStreamFree(netst);\n"; print " virObjectUnref(netst);\n";
print " st->driver = NULL;\n"; print " st->driver = NULL;\n";
print " st->privateData = NULL;\n"; print " st->privateData = NULL;\n";
} }

View File

@ -63,7 +63,7 @@ struct _virNetClientCall {
struct _virNetClient { struct _virNetClient {
int refs; virObject object;
virMutex lock; virMutex lock;
@ -109,6 +109,21 @@ struct _virNetClient {
}; };
static virClassPtr virNetClientClass;
static void virNetClientDispose(void *obj);
static int virNetClientOnceInit(void)
{
if (!(virNetClientClass = virClassNew("virNetClient",
sizeof(virNetClient),
virNetClientDispose)))
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(virNetClient)
static void virNetClientIOEventLoopPassTheBuck(virNetClientPtr client, static void virNetClientIOEventLoopPassTheBuck(virNetClientPtr client,
virNetClientCallPtr thiscall); virNetClientCallPtr thiscall);
static int virNetClientQueueNonBlocking(virNetClientPtr client, static int virNetClientQueueNonBlocking(virNetClientPtr client,
@ -237,13 +252,6 @@ static bool virNetClientCallMatchPredicate(virNetClientCallPtr head,
} }
static void virNetClientEventFree(void *opaque)
{
virNetClientPtr client = opaque;
virNetClientFree(client);
}
bool bool
virNetClientKeepAliveIsSupported(virNetClientPtr client) virNetClientKeepAliveIsSupported(virNetClientPtr client)
{ {
@ -303,20 +311,23 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
int wakeupFD[2] = { -1, -1 }; int wakeupFD[2] = { -1, -1 };
virKeepAlivePtr ka = NULL; virKeepAlivePtr ka = NULL;
if (virNetClientInitialize() < 0)
return NULL;
if (pipe2(wakeupFD, O_CLOEXEC) < 0) { if (pipe2(wakeupFD, O_CLOEXEC) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("unable to make pipe")); _("unable to make pipe"));
goto error; goto error;
} }
if (VIR_ALLOC(client) < 0) if (!(client = virObjectNew(virNetClientClass)))
goto no_memory;
client->refs = 1;
if (virMutexInit(&client->lock) < 0)
goto error; goto error;
if (virMutexInit(&client->lock) < 0) {
VIR_FREE(client);
goto error;
}
client->sock = sock; client->sock = sock;
client->wakeupReadFD = wakeupFD[0]; client->wakeupReadFD = wakeupFD[0];
client->wakeupSendFD = wakeupFD[1]; client->wakeupSendFD = wakeupFD[1];
@ -327,13 +338,13 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
goto no_memory; goto no_memory;
/* Set up a callback to listen on the socket data */ /* Set up a callback to listen on the socket data */
client->refs++; virObjectRef(client);
if (virNetSocketAddIOCallback(client->sock, if (virNetSocketAddIOCallback(client->sock,
VIR_EVENT_HANDLE_READABLE, VIR_EVENT_HANDLE_READABLE,
virNetClientIncomingEvent, virNetClientIncomingEvent,
client, client,
virNetClientEventFree) < 0) { virObjectFreeCallback) < 0) {
client->refs--; virObjectUnref(client);
VIR_DEBUG("Failed to add event watch, disabling events and support for" VIR_DEBUG("Failed to add event watch, disabling events and support for"
" keepalive messages"); " keepalive messages");
} else { } else {
@ -342,16 +353,16 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
if (!(ka = virKeepAliveNew(-1, 0, client, if (!(ka = virKeepAliveNew(-1, 0, client,
virNetClientKeepAliveSendCB, virNetClientKeepAliveSendCB,
virNetClientKeepAliveDeadCB, virNetClientKeepAliveDeadCB,
virNetClientEventFree))) virObjectFreeCallback)))
goto error; goto error;
/* keepalive object has a reference to client */ /* keepalive object has a reference to client */
client->refs++; virObjectRef(client);
} }
client->keepalive = ka; client->keepalive = ka;
PROBE(RPC_CLIENT_NEW, PROBE(RPC_CLIENT_NEW,
"client=%p refs=%d sock=%p", "client=%p sock=%p",
client, client->refs, client->sock); client, client->sock);
return client; return client;
no_memory: no_memory:
@ -363,7 +374,7 @@ error:
virKeepAliveStop(ka); virKeepAliveStop(ka);
virObjectUnref(ka); virObjectUnref(ka);
} }
virNetClientFree(client); virObjectUnref(client);
return NULL; return NULL;
} }
@ -422,17 +433,6 @@ virNetClientPtr virNetClientNewExternal(const char **cmdargv)
} }
void virNetClientRef(virNetClientPtr client)
{
virNetClientLock(client);
client->refs++;
PROBE(RPC_CLIENT_REF,
"client=%p refs=%d",
client, client->refs);
virNetClientUnlock(client);
}
int virNetClientGetFD(virNetClientPtr client) int virNetClientGetFD(virNetClientPtr client)
{ {
int fd; int fd;
@ -463,28 +463,16 @@ bool virNetClientHasPassFD(virNetClientPtr client)
} }
void virNetClientFree(virNetClientPtr client) void virNetClientDispose(void *obj)
{ {
virNetClientPtr client = obj;
int i; int i;
if (!client)
return;
virNetClientLock(client);
PROBE(RPC_CLIENT_FREE,
"client=%p refs=%d",
client, client->refs);
client->refs--;
if (client->refs > 0) {
virNetClientUnlock(client);
return;
}
if (client->closeFf) if (client->closeFf)
client->closeFf(client->closeOpaque); client->closeFf(client->closeOpaque);
for (i = 0 ; i < client->nprograms ; i++) for (i = 0 ; i < client->nprograms ; i++)
virNetClientProgramFree(client->programs[i]); virObjectUnref(client->programs[i]);
VIR_FREE(client->programs); VIR_FREE(client->programs);
VIR_FORCE_CLOSE(client->wakeupSendFD); VIR_FORCE_CLOSE(client->wakeupSendFD);
@ -504,8 +492,6 @@ void virNetClientFree(virNetClientPtr client)
virNetClientUnlock(client); virNetClientUnlock(client);
virMutexDestroy(&client->lock); virMutexDestroy(&client->lock);
VIR_FREE(client);
} }
@ -546,7 +532,7 @@ virNetClientCloseLocked(virNetClientPtr client)
virNetClientCloseFunc closeCb = client->closeCb; virNetClientCloseFunc closeCb = client->closeCb;
void *closeOpaque = client->closeOpaque; void *closeOpaque = client->closeOpaque;
int closeReason = client->closeReason; int closeReason = client->closeReason;
client->refs++; virObjectRef(client);
virNetClientUnlock(client); virNetClientUnlock(client);
if (ka) { if (ka) {
@ -557,7 +543,7 @@ virNetClientCloseLocked(virNetClientPtr client)
closeCb(client, closeReason, closeOpaque); closeCb(client, closeReason, closeOpaque);
virNetClientLock(client); virNetClientLock(client);
client->refs--; virObjectUnref(client);
} }
} }
@ -754,8 +740,7 @@ int virNetClientAddProgram(virNetClientPtr client,
if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0) if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0)
goto no_memory; goto no_memory;
client->programs[client->nprograms-1] = prog; client->programs[client->nprograms-1] = virObjectRef(prog);
virNetClientProgramRef(prog);
virNetClientUnlock(client); virNetClientUnlock(client);
return 0; return 0;
@ -775,8 +760,7 @@ int virNetClientAddStream(virNetClientPtr client,
if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0) if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0)
goto no_memory; goto no_memory;
client->streams[client->nstreams-1] = st; client->streams[client->nstreams-1] = virObjectRef(st);
virNetClientStreamRef(st);
virNetClientUnlock(client); virNetClientUnlock(client);
return 0; return 0;
@ -810,7 +794,7 @@ void virNetClientRemoveStream(virNetClientPtr client,
VIR_FREE(client->streams); VIR_FREE(client->streams);
client->nstreams = 0; client->nstreams = 0;
} }
virNetClientStreamFree(st); virObjectUnref(st);
cleanup: cleanup:
virNetClientUnlock(client); virNetClientUnlock(client);

View File

@ -30,6 +30,7 @@
# endif # endif
# include "virnetclientprogram.h" # include "virnetclientprogram.h"
# include "virnetclientstream.h" # include "virnetclientstream.h"
# include "virobject.h"
virNetClientPtr virNetClientNewUNIX(const char *path, virNetClientPtr virNetClientNewUNIX(const char *path,
@ -60,8 +61,6 @@ void virNetClientSetCloseCallback(virNetClientPtr client,
void *opaque, void *opaque,
virFreeCallback ff); virFreeCallback ff);
void virNetClientRef(virNetClientPtr client);
int virNetClientGetFD(virNetClientPtr client); int virNetClientGetFD(virNetClientPtr client);
int virNetClientDupFD(virNetClientPtr client, bool cloexec); int virNetClientDupFD(virNetClientPtr client, bool cloexec);
@ -105,7 +104,6 @@ const char *virNetClientRemoteAddrString(virNetClientPtr client);
int virNetClientGetTLSKeySize(virNetClientPtr client); int virNetClientGetTLSKeySize(virNetClientPtr client);
void virNetClientFree(virNetClientPtr client);
void virNetClientClose(virNetClientPtr client); void virNetClientClose(virNetClientPtr client);
bool virNetClientKeepAliveIsSupported(virNetClientPtr client); bool virNetClientKeepAliveIsSupported(virNetClientPtr client);

View File

@ -33,11 +33,12 @@
#include "logging.h" #include "logging.h"
#include "util.h" #include "util.h"
#include "virfile.h" #include "virfile.h"
#include "threads.h"
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
struct _virNetClientProgram { struct _virNetClientProgram {
int refs; virObject object;
unsigned program; unsigned program;
unsigned version; unsigned version;
@ -46,6 +47,22 @@ struct _virNetClientProgram {
void *eventOpaque; void *eventOpaque;
}; };
static virClassPtr virNetClientProgramClass;
static void virNetClientProgramDispose(void *obj);
static int virNetClientProgramOnceInit(void)
{
if (!(virNetClientProgramClass = virClassNew("virNetClientProgram",
sizeof(virNetClientProgram),
virNetClientProgramDispose)))
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(virNetClientProgram)
virNetClientProgramPtr virNetClientProgramNew(unsigned program, virNetClientProgramPtr virNetClientProgramNew(unsigned program,
unsigned version, unsigned version,
virNetClientProgramEventPtr events, virNetClientProgramEventPtr events,
@ -54,12 +71,12 @@ virNetClientProgramPtr virNetClientProgramNew(unsigned program,
{ {
virNetClientProgramPtr prog; virNetClientProgramPtr prog;
if (VIR_ALLOC(prog) < 0) { if (virNetClientProgramInitialize() < 0)
virReportOOMError(); return NULL;
if (!(prog = virObjectNew(virNetClientProgramClass)))
return NULL; return NULL;
}
prog->refs = 1;
prog->program = program; prog->program = program;
prog->version = version; prog->version = version;
prog->events = events; prog->events = events;
@ -70,22 +87,8 @@ virNetClientProgramPtr virNetClientProgramNew(unsigned program,
} }
void virNetClientProgramRef(virNetClientProgramPtr prog) void virNetClientProgramDispose(void *obj ATTRIBUTE_UNUSED)
{ {
prog->refs++;
}
void virNetClientProgramFree(virNetClientProgramPtr prog)
{
if (!prog)
return;
prog->refs--;
if (prog->refs > 0)
return;
VIR_FREE(prog);
} }

View File

@ -27,6 +27,7 @@
# include <rpc/xdr.h> # include <rpc/xdr.h>
# include "virnetmessage.h" # include "virnetmessage.h"
# include "virobject.h"
typedef struct _virNetClient virNetClient; typedef struct _virNetClient virNetClient;
typedef virNetClient *virNetClientPtr; typedef virNetClient *virNetClientPtr;
@ -62,10 +63,6 @@ virNetClientProgramPtr virNetClientProgramNew(unsigned program,
unsigned virNetClientProgramGetProgram(virNetClientProgramPtr prog); unsigned virNetClientProgramGetProgram(virNetClientProgramPtr prog);
unsigned virNetClientProgramGetVersion(virNetClientProgramPtr prog); unsigned virNetClientProgramGetVersion(virNetClientProgramPtr prog);
void virNetClientProgramRef(virNetClientProgramPtr prog);
void virNetClientProgramFree(virNetClientProgramPtr prog);
int virNetClientProgramMatches(virNetClientProgramPtr prog, int virNetClientProgramMatches(virNetClientProgramPtr prog,
virNetMessagePtr msg); virNetMessagePtr msg);

View File

@ -33,12 +33,13 @@
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
struct _virNetClientStream { struct _virNetClientStream {
virObject object;
virMutex lock; virMutex lock;
virNetClientProgramPtr prog; virNetClientProgramPtr prog;
int proc; int proc;
unsigned serial; unsigned serial;
int refs;
virError err; virError err;
@ -63,6 +64,22 @@ struct _virNetClientStream {
}; };
static virClassPtr virNetClientStreamClass;
static void virNetClientStreamDispose(void *obj);
static int virNetClientStreamOnceInit(void)
{
if (!(virNetClientStreamClass = virClassNew("virNetClientStream",
sizeof(virNetClientStream),
virNetClientStreamDispose)))
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(virNetClientStream)
static void static void
virNetClientStreamEventTimerUpdate(virNetClientStreamPtr st) virNetClientStreamEventTimerUpdate(virNetClientStreamPtr st)
{ {
@ -119,26 +136,18 @@ virNetClientStreamEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
} }
static void
virNetClientStreamEventTimerFree(void *opaque)
{
virNetClientStreamPtr st = opaque;
virNetClientStreamFree(st);
}
virNetClientStreamPtr virNetClientStreamNew(virNetClientProgramPtr prog, virNetClientStreamPtr virNetClientStreamNew(virNetClientProgramPtr prog,
int proc, int proc,
unsigned serial) unsigned serial)
{ {
virNetClientStreamPtr st; virNetClientStreamPtr st;
if (VIR_ALLOC(st) < 0) { if (virNetClientStreamInitialize() < 0)
virReportOOMError(); return NULL;
if (!(st = virObjectNew(virNetClientStreamClass)))
return NULL; return NULL;
}
st->refs = 1;
st->prog = prog; st->prog = prog;
st->proc = proc; st->proc = proc;
st->serial = serial; st->serial = serial;
@ -150,35 +159,19 @@ virNetClientStreamPtr virNetClientStreamNew(virNetClientProgramPtr prog,
return NULL; return NULL;
} }
virNetClientProgramRef(prog); virObjectRef(prog);
return st; return st;
} }
void virNetClientStreamDispose(void *obj)
void virNetClientStreamRef(virNetClientStreamPtr st)
{ {
virMutexLock(&st->lock); virNetClientStreamPtr st = obj;
st->refs++;
virMutexUnlock(&st->lock);
}
void virNetClientStreamFree(virNetClientStreamPtr st)
{
virMutexLock(&st->lock);
st->refs--;
if (st->refs > 0) {
virMutexUnlock(&st->lock);
return;
}
virMutexUnlock(&st->lock);
virResetError(&st->err); virResetError(&st->err);
VIR_FREE(st->incoming); VIR_FREE(st->incoming);
virMutexDestroy(&st->lock); virMutexDestroy(&st->lock);
virNetClientProgramFree(st->prog); virObjectUnref(st->prog);
VIR_FREE(st);
} }
bool virNetClientStreamMatches(virNetClientStreamPtr st, bool virNetClientStreamMatches(virNetClientStreamPtr st,
@ -454,13 +447,13 @@ int virNetClientStreamEventAddCallback(virNetClientStreamPtr st,
goto cleanup; goto cleanup;
} }
st->refs++; virObjectRef(st);
if ((st->cbTimer = if ((st->cbTimer =
virEventAddTimeout(-1, virEventAddTimeout(-1,
virNetClientStreamEventTimer, virNetClientStreamEventTimer,
st, st,
virNetClientStreamEventTimerFree)) < 0) { virObjectFreeCallback)) < 0) {
st->refs--; virObjectUnref(st);
goto cleanup; goto cleanup;
} }

View File

@ -24,6 +24,7 @@
# define __VIR_NET_CLIENT_STREAM_H__ # define __VIR_NET_CLIENT_STREAM_H__
# include "virnetclientprogram.h" # include "virnetclientprogram.h"
# include "virobject.h"
typedef struct _virNetClientStream virNetClientStream; typedef struct _virNetClientStream virNetClientStream;
typedef virNetClientStream *virNetClientStreamPtr; typedef virNetClientStream *virNetClientStreamPtr;
@ -35,10 +36,6 @@ virNetClientStreamPtr virNetClientStreamNew(virNetClientProgramPtr prog,
int proc, int proc,
unsigned serial); unsigned serial);
void virNetClientStreamRef(virNetClientStreamPtr st);
void virNetClientStreamFree(virNetClientStreamPtr st);
bool virNetClientStreamRaiseError(virNetClientStreamPtr st); bool virNetClientStreamRaiseError(virNetClientStreamPtr st);
int virNetClientStreamSetError(virNetClientStreamPtr st, int virNetClientStreamSetError(virNetClientStreamPtr st,