Skip to contentSkip to conversation

Fix a typo that can cause slow socket response on Windows.

PATCH In review Hafiz Abid Qadeer 2 participants 2 messages Jan 29, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix a typo that can cause slow socket response on Windows.

We observed slow responses on a host forwarded port on Windows. Investigation revealed that qemu_fd_register was being called with fd=-1 and this caused g_poll in qemu_poll_ns timing out. I tracked this behavior to following commit:
748f8f4 slirp: replace qemu_set_nonblock()

@@ -482,7 +483,8 @@ void tcp_connect(struct socket *inso)

         tcp_close(sototcpcb(so)); /* This will sofree() as well */
         return;
     }
-    qemu_set_nonblock(s);
+    slirp_set_nonblock(s);
+    so->slirp->cb->register_poll_fd(so->s);

It seems that calling register_poll_fd with so->s instead of s may be a typo. Changing it back to s solves this issue. The commit 748f8f4 made similar change in tcp_fconnect but I have not touched it.

---
 src/tcp_subr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/tcp_subr.c +1 -1
index a1016d9..1b6d602 100644
@@ -493,7 +493,7 @@ void tcp_connect(struct socket *inso)
         return;
     }
     slirp_set_nonblock(s);
-    so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
+    so->slirp->cb->register_poll_fd(s, so->slirp->opaque);
     slirp_socket_set_fast_reuse(s);
     opt = 1;
     setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
Signature · 1 line
2.25.1
#1 lore raw
Quoted 13 lines · Hafiz Abid Qadeer

We observed slow responses on a host forwarded port on Windows. Investigation revealed that qemu_fd_register was being called with fd=-1 and this caused g_poll in qemu_poll_ns timing out. I tracked this behavior to following commit:
748f8f4 slirp: replace qemu_set_nonblock()

(quoted diff) +2 -1
@@ -482,7 +483,8 @@ void tcp_connect(struct socket *inso)
         tcp_close(sototcpcb(so)); /* This will sofree() as well */
         return;
     }
-    qemu_set_nonblock(s);
+    slirp_set_nonblock(s);
+    so->slirp->cb->register_poll_fd(so->s);
 

It seems that calling register_poll_fd with so->s instead of s may be a typo. Changing it back to s solves this issue. The commit 748f8f4 made similar change in tcp_fconnect but I have not touched it.

Quoted 4 lines
---
 src/tcp_subr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks for your suggested patch, however, slirp is now spun off into its own standalone project. You can submit patches using merge requests at

https://gitlab.freedesktop.org/slirp/libslirp

QEMU will periodically pull in updates from slirp.

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 :|