Skip to contentSkip to conversation

chardev/char-socket: Properly make qio connections non blocking

PATCH Applied Sai Pavan Boddu 3 participants 3 messages Apr 19, 2020 – Apr 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 chardev/char-socket: Properly make qio connections non blocking

In tcp_chr_sync_read function, there is a possibility of socket disconnection during blocking read, then tcp_chr_hup function would clean up the qio channel pointers(i.e ioc, sioc).

---
Changes for V2:
Place the guard around 'qio_channel_set_blocking' call to check connection status This fix is simpler than v1 and explains better about the issue.

 chardev/char-socket.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
chardev/char-socket.c +3 -1
index 185fe38..e56b2f0 100644
@@ -549,7 +549,9 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
 
     qio_channel_set_blocking(s->ioc, true, NULL);
     size = tcp_chr_recv(chr, (void *) buf, len);
-    qio_channel_set_blocking(s->ioc, false, NULL);
+    if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
+        qio_channel_set_blocking(s->ioc, false, NULL);
+    }
     if (size == 0) {
         /* connection closed */
         tcp_chr_disconnect(chr);
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 18 lines · Sai Pavan Boddu

In tcp_chr_sync_read function, there is a possibility of socket disconnection during blocking read, then tcp_chr_hup function would clean up the qio channel pointers(i.e ioc, sioc).

---
Changes for V2:
Place the guard around 'qio_channel_set_blocking' call to check connection status This fix is simpler than v1 and explains better about the issue.

 chardev/char-socket.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
chardev/char-socket.c +0 -0
index 185fe38..e56b2f0 100644

chardev/char-socket.c static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len) · line 557

Quoted 10 lines
chardev/char-socket.c +3 -1
@@ -549,7 +549,9 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
 
     qio_channel_set_blocking(s->ioc, true, NULL);
     size = tcp_chr_recv(chr, (void *) buf, len);
-    qio_channel_set_blocking(s->ioc, false, NULL);
+    if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
+        qio_channel_set_blocking(s->ioc, false, NULL);
+    }
     if (size == 0) {
         /* connection closed */
         tcp_chr_disconnect(chr);

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 33 lines · Daniel P. Berrangé
Quoted 18 lines · Sai Pavan Boddu

In tcp_chr_sync_read function, there is a possibility of socket disconnection during blocking read, then tcp_chr_hup function would clean up the qio channel pointers(i.e ioc, sioc).

---
Changes for V2:
Place the guard around 'qio_channel_set_blocking' call to check connection status This fix is simpler than v1 and explains better about the issue.

 chardev/char-socket.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
chardev/char-socket.c +0 -0
index 185fe38..e56b2f0 100644

chardev/char-socket.c static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len) · line 557

Quoted 10 lines
chardev/char-socket.c +3 -1
@@ -549,7 +549,9 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
 
     qio_channel_set_blocking(s->ioc, true, NULL);
     size = tcp_chr_recv(chr, (void *) buf, len);
-    qio_channel_set_blocking(s->ioc, false, NULL);
+    if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
+        qio_channel_set_blocking(s->ioc, false, NULL);
+    }
     if (size == 0) {
         /* connection closed */
         tcp_chr_disconnect(chr);
Quoted 3 lines

Regards,
Daniel

Queued, thanks.

Paolo