[libvirt] [PATCH] Tweak EOF handling of streams

From: "Daniel P. Berrange" <berrange@redhat.com> Typically when you get EOF on a stream, poll will return POLLIN|POLLHUP at the same time. Thus when we deal with stream reads, if we see EOF during the read, we can then clear the VIR_STREAM_EVENT_HANGUP & VIR_STREAM_EVENT_ERROR event bits. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- daemon/stream.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/daemon/stream.c b/daemon/stream.c index 4df1145..0fb5c85 100644 --- a/daemon/stream.c +++ b/daemon/stream.c @@ -148,6 +148,14 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque) virNetServerClientClose(client); goto cleanup; } + /* If we detected EOF during read processing, + * then clear hangup/error conditions, since + * we want the client to see the EOF message + * we just sent them + */ + if (stream->recvEOF) + events = events & ~(VIR_STREAM_EVENT_HANGUP | + VIR_STREAM_EVENT_ERROR); } /* If we have a completion/abort message, always process it */ -- 1.8.1.4

On 04/09/2013 06:25 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
Typically when you get EOF on a stream, poll will return POLLIN|POLLHUP at the same time. Thus when we deal with stream reads, if we see EOF during the read, we can then clear the VIR_STREAM_EVENT_HANGUP & VIR_STREAM_EVENT_ERROR event bits.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- daemon/stream.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/daemon/stream.c b/daemon/stream.c index 4df1145..0fb5c85 100644 --- a/daemon/stream.c +++ b/daemon/stream.c @@ -148,6 +148,14 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque) virNetServerClientClose(client); goto cleanup; } + /* If we detected EOF during read processing, + * then clear hangup/error conditions, since + * we want the client to see the EOF message + * we just sent them + */ + if (stream->recvEOF) + events = events & ~(VIR_STREAM_EVENT_HANGUP | + VIR_STREAM_EVENT_ERROR);
Ignoring HANGUP makes sense, but do we really want to suppress errors? I would feel a bit more comfortable if this were just: events &= ~VIR_STREAM_EVENT_HANGUP; but I'll leave it up to you. Either way, having EOF take priority over HANGUP makes sense, so: ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Tue, Apr 09, 2013 at 07:57:11AM -0600, Eric Blake wrote:
On 04/09/2013 06:25 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
Typically when you get EOF on a stream, poll will return POLLIN|POLLHUP at the same time. Thus when we deal with stream reads, if we see EOF during the read, we can then clear the VIR_STREAM_EVENT_HANGUP & VIR_STREAM_EVENT_ERROR event bits.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- daemon/stream.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/daemon/stream.c b/daemon/stream.c index 4df1145..0fb5c85 100644 --- a/daemon/stream.c +++ b/daemon/stream.c @@ -148,6 +148,14 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque) virNetServerClientClose(client); goto cleanup; } + /* If we detected EOF during read processing, + * then clear hangup/error conditions, since + * we want the client to see the EOF message + * we just sent them + */ + if (stream->recvEOF) + events = events & ~(VIR_STREAM_EVENT_HANGUP | + VIR_STREAM_EVENT_ERROR);
Ignoring HANGUP makes sense, but do we really want to suppress errors?
You get EVENT_ERROR if you are polling for writability and HUP occurs, so it needs to be treated in the same way as HANGUP. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Eric Blake