slirp: replace qemu_notify_event() with a callback
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 17 Jan 2019 11:43:43 +0000 (15:43 +0400)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Thu, 7 Feb 2019 13:49:08 +0000 (15:49 +0200)
Introduce a SlirpCb callback to kick the main io-thread.

Add an intermediary sodrop() function that will call SlirpCb.notify
callback when sbdrop() returns true.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
net/slirp.c
slirp/libslirp.h
slirp/sbuf.c
slirp/sbuf.h
slirp/socket.c
slirp/socket.h
slirp/tcp_input.c

index 78ba96b63f7228e427992625f160fc08cb96c49b..7b4f9f5c5ee31c3208d4e8d8b8362fb8c1264555 100644 (file)
@@ -205,6 +205,7 @@ static const SlirpCb slirp_cb = {
     .timer_mod = net_slirp_timer_mod,
     .register_poll_fd = net_slirp_register_poll_fd,
     .unregister_poll_fd = net_slirp_unregister_poll_fd,
+    .notify = qemu_notify_event,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
index 8ce69f0be391047c2047ff4e7e55265eaca87550..679a25422b97552bf52d9a931a20fdd28b3035a4 100644 (file)
@@ -31,6 +31,8 @@ typedef struct SlirpCb {
     void (*register_poll_fd)(int fd);
     /* Unregister a fd */
     void (*unregister_poll_fd)(int fd);
+    /* Kick the io-thread, to signal that new events may be processed */
+    void (*notify)(void);
 } SlirpCb;
 
 
index 912f235f6524bf116e4ce687be5d1080d6f56710..17f28e97a63d0742a5a1a8366dfa1a1f2a62a0a8 100644 (file)
@@ -17,7 +17,7 @@ sbfree(struct sbuf *sb)
        free(sb->sb_data);
 }
 
-void
+bool
 sbdrop(struct sbuf *sb, int num)
 {
     int limit = sb->sb_datalen / 2;
@@ -34,8 +34,10 @@ sbdrop(struct sbuf *sb, int num)
                sb->sb_rptr -= sb->sb_datalen;
 
     if (sb->sb_cc < limit && sb->sb_cc + num >= limit) {
-        qemu_notify_event();
+        return true;
     }
+
+    return false;
 }
 
 void
index 644c2013413ecd30ec63e157989fef4ecde08ffa..1cb9a42834162ce507425fb85142fac600b7c9b9 100644 (file)
@@ -21,7 +21,7 @@ struct sbuf {
 };
 
 void sbfree(struct sbuf *);
-void sbdrop(struct sbuf *, int);
+bool sbdrop(struct sbuf *, int);
 void sbreserve(struct sbuf *, int);
 void sbappend(struct socket *, struct mbuf *);
 void sbcopy(struct sbuf *, int, int, char *);
index 5805d30f3d8da3055f4c5d331b5ea7a77b4f6e6a..2e8dc22fb6265720a51b7bc2da30f2186ab0fdd0 100644 (file)
@@ -928,3 +928,10 @@ void sotranslate_accept(struct socket *so)
         break;
     }
 }
+
+void sodrop(struct socket *s, int num)
+{
+    if (sbdrop(&s->so_snd, num)) {
+        s->slirp->cb->notify();
+    }
+}
index fc35ca5f72a5154ba3f6a1ef276dd62289c7eb8e..1c1c8b5871c4b51b278ae8ef4e568bc6b41d7742 100644 (file)
@@ -156,6 +156,7 @@ int soreadbuf(struct socket *so, const char *buf, int size);
 void sotranslate_out(struct socket *, struct sockaddr_storage *);
 void sotranslate_in(struct socket *, struct sockaddr_storage *);
 void sotranslate_accept(struct socket *);
+void sodrop(struct socket *, int num);
 
 
 #endif /* SLIRP_SOCKET_H */
index de5b74a52b17aab24be272d9a7d4830dcdb49b9e..7c1fe18fec1ae4f6f3622b69dd9541dc9671e760 100644 (file)
@@ -506,7 +506,7 @@ findso:
                                    SEQ_GT(ti->ti_ack, tp->t_rtseq))
                                        tcp_xmit_timer(tp, tp->t_rtt);
                                acked = ti->ti_ack - tp->snd_una;
-                               sbdrop(&so->so_snd, acked);
+                               sodrop(so, acked);
                                tp->snd_una = ti->ti_ack;
                                m_free(m);
 
@@ -1118,10 +1118,10 @@ trimthenstep6:
                }
                if (acked > so->so_snd.sb_cc) {
                        tp->snd_wnd -= so->so_snd.sb_cc;
-                       sbdrop(&so->so_snd, (int )so->so_snd.sb_cc);
+                       sodrop(so, (int)so->so_snd.sb_cc);
                        ourfinisacked = 1;
                } else {
-                       sbdrop(&so->so_snd, acked);
+                       sodrop(so, acked);
                        tp->snd_wnd -= acked;
                        ourfinisacked = 0;
                }