mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
remote_daemon_stream: Use automatic memory management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
20d2cf47bc
commit
183804c043
@ -119,8 +119,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
virNetServerClient *client = opaque;
|
virNetServerClient *client = opaque;
|
||||||
daemonClientStream *stream;
|
daemonClientStream *stream;
|
||||||
daemonClientPrivate *priv = virNetServerClientGetPrivateData(client);
|
daemonClientPrivate *priv = virNetServerClientGetPrivateData(client);
|
||||||
|
VIR_LOCK_GUARD lock = virLockGuardLock(&priv->lock);
|
||||||
virMutexLock(&priv->lock);
|
|
||||||
|
|
||||||
stream = priv->streams;
|
stream = priv->streams;
|
||||||
while (stream) {
|
while (stream) {
|
||||||
@ -132,7 +131,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
if (!stream) {
|
if (!stream) {
|
||||||
VIR_WARN("event for client=%p stream st=%p, but missing stream state", client, st);
|
VIR_WARN("event for client=%p stream st=%p, but missing stream state", client, st);
|
||||||
virStreamEventRemoveCallback(st);
|
virStreamEventRemoveCallback(st);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("st=%p events=%d EOF=%d closed=%d", st, events, stream->recvEOF, stream->closed);
|
VIR_DEBUG("st=%p events=%d EOF=%d closed=%d", st, events, stream->recvEOF, stream->closed);
|
||||||
@ -142,7 +141,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
if (daemonStreamHandleWrite(client, stream) < 0) {
|
if (daemonStreamHandleWrite(client, stream) < 0) {
|
||||||
daemonRemoveClientStream(client, stream);
|
daemonRemoveClientStream(client, stream);
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +151,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
if (daemonStreamHandleRead(client, stream) < 0) {
|
if (daemonStreamHandleRead(client, stream) < 0) {
|
||||||
daemonRemoveClientStream(client, stream);
|
daemonRemoveClientStream(client, stream);
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
/* If we detected EOF during read processing,
|
/* If we detected EOF during read processing,
|
||||||
* then clear hangup/error conditions, since
|
* then clear hangup/error conditions, since
|
||||||
@ -177,7 +176,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
virNetMessageFree(msg);
|
virNetMessageFree(msg);
|
||||||
daemonRemoveClientStream(client, stream);
|
daemonRemoveClientStream(client, stream);
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VIR_NET_ERROR:
|
case VIR_NET_ERROR:
|
||||||
@ -187,7 +186,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
virNetMessageFree(msg);
|
virNetMessageFree(msg);
|
||||||
daemonRemoveClientStream(client, stream);
|
daemonRemoveClientStream(client, stream);
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -206,7 +205,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
if (!(msg = virNetMessageNew(false))) {
|
if (!(msg = virNetMessageNew(false))) {
|
||||||
daemonRemoveClientStream(client, stream);
|
daemonRemoveClientStream(client, stream);
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
msg->cb = daemonStreamMessageFinished;
|
msg->cb = daemonStreamMessageFinished;
|
||||||
msg->opaque = stream;
|
msg->opaque = stream;
|
||||||
@ -220,7 +219,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
virNetMessageFree(msg);
|
virNetMessageFree(msg);
|
||||||
daemonRemoveClientStream(client, stream);
|
daemonRemoveClientStream(client, stream);
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +262,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
daemonRemoveClientStream(client, stream);
|
daemonRemoveClientStream(client, stream);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream->closed) {
|
if (stream->closed) {
|
||||||
@ -271,9 +270,6 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
|
|||||||
} else {
|
} else {
|
||||||
daemonStreamUpdateEvents(stream);
|
daemonStreamUpdateEvents(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virMutexUnlock(&priv->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -460,13 +456,11 @@ int daemonAddClientStream(virNetServerClient *client,
|
|||||||
if (transmit)
|
if (transmit)
|
||||||
stream->tx = true;
|
stream->tx = true;
|
||||||
|
|
||||||
virMutexLock(&priv->lock);
|
VIR_WITH_MUTEX_LOCK_GUARD(&priv->lock) {
|
||||||
stream->next = priv->streams;
|
stream->next = priv->streams;
|
||||||
priv->streams = stream;
|
priv->streams = stream;
|
||||||
|
|
||||||
daemonStreamUpdateEvents(stream);
|
daemonStreamUpdateEvents(stream);
|
||||||
|
}
|
||||||
virMutexUnlock(&priv->lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user