Skip to contentSkip to conversation

io: fix handling of EOF / error conditions in websock GSource

PATCH In review Daniel P. Berrangé 2 participants 2 messages Mar 7, 2019 – Apr 1, 2019 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 io: fix handling of EOF / error conditions in websock GSource

We were never reporting the G_IO_HUP event when an end of file was hit on the websocket channel.

We also didn't report G_IO_ERR when we hit a fatal error processing the websocket protocol.

The latter in particular meant that the chardev code would not notice when an eof/error was encountered on the websocket channel, unless the guest OS happened to trigger a write operation.

This meant that once the first client had quit, the chardev would never listen to accept a new client.

Fixes launchpad bug 1816819

---

Changed in v2:
- Fix typo
- Remove use of G_IO_IN at same time as HUP/ERR since. It is not required since the websock source doesn't do a real poll itself.

 io/channel-websock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
io/channel-websock.c +7 -1
index dc43dc6bb9..77d30f0e4a 100644
@@ -1225,12 +1225,18 @@ qio_channel_websock_source_check(GSource *source)
     QIOChannelWebsockSource *wsource = (QIOChannelWebsockSource *)source;
     GIOCondition cond = 0;
 
-    if (wsource->wioc->rawinput.offset || wsource->wioc->io_eof) {
+    if (wsource->wioc->rawinput.offset) {
         cond |= G_IO_IN;
     }
     if (wsource->wioc->encoutput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER) {
         cond |= G_IO_OUT;
     }
+    if (wsource->wioc->io_eof) {
+        cond |= G_IO_HUP;
+    }
+    if (wsource->wioc->io_err) {
+        cond |= G_IO_ERR;
+    }
 
     return cond & wsource->condition;
 }
Signature · 1 line
2.20.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 52 lines · Daniel P. Berrangé

ping

Quoted 48 lines · Daniel P. Berrangé

We were never reporting the G_IO_HUP event when an end of file was hit on the websocket channel.

We also didn't report G_IO_ERR when we hit a fatal error processing the websocket protocol.

The latter in particular meant that the chardev code would not notice when an eof/error was encountered on the websocket channel, unless the guest OS happened to trigger a write operation.

This meant that once the first client had quit, the chardev would never listen to accept a new client.

Fixes launchpad bug 1816819

---

Changed in v2:
- Fix typo
- Remove use of G_IO_IN at same time as HUP/ERR since. It is not required since the websock source doesn't do a real poll itself.

 io/channel-websock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
io/channel-websock.c +7 -1
index dc43dc6bb9..77d30f0e4a 100644
@@ -1225,12 +1225,18 @@ qio_channel_websock_source_check(GSource *source)
     QIOChannelWebsockSource *wsource = (QIOChannelWebsockSource *)source;
     GIOCondition cond = 0;
 
-    if (wsource->wioc->rawinput.offset || wsource->wioc->io_eof) {
+    if (wsource->wioc->rawinput.offset) {
         cond |= G_IO_IN;
     }
     if (wsource->wioc->encoutput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER) {
         cond |= G_IO_OUT;
     }
+    if (wsource->wioc->io_eof) {
+        cond |= G_IO_HUP;
+    }
+    if (wsource->wioc->io_err) {
+        cond |= G_IO_ERR;
+    }
 
Quoted 5 lines
Quoted 5 lines
io/channel-websock.c +0 -1
     return cond & wsource->condition;
 }
--

2.20.1