diff mbox series

[for-3.2,33/41] slirp: replace qemu_notify_event() with a callback

Message ID 20181114123643.24091-34-marcandre.lureau@redhat.com
State New
Headers show
Series RFC: slirp: make it again a standalone project | expand

Commit Message

Marc-André Lureau Nov. 14, 2018, 12:36 p.m. UTC
Use a "slirp socket" helper function to call the callback when
sbdrop() returns true.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h  | 1 +
 slirp/sbuf.h      | 2 +-
 slirp/socket.h    | 1 +
 net/slirp.c       | 1 +
 slirp/sbuf.c      | 6 ++++--
 slirp/socket.c    | 7 +++++++
 slirp/tcp_input.c | 6 +++---
 7 files changed, 18 insertions(+), 6 deletions(-)

Comments

Samuel Thibault Nov. 20, 2018, 1:32 a.m. UTC | #1
Marc-André Lureau, le mer. 14 nov. 2018 16:36:35 +0400, a ecrit:
> Use a "slirp socket" helper function to call the callback when
> sbdrop() returns true.

It's really far from clear what this should be doing :)

I'd say find out how to rephrase 86073017e384 ("slirp: Signal free input
buffer space to io-thread") in a generic way.

Samuel
diff mbox series

Patch

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index c7582e6516..7d04404340 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -22,6 +22,7 @@  typedef struct SlirpCb {
     void (*timer_mod)(void *timer, int64_t expire_timer);
     void (*set_nonblock)(int fd);
     void (*guest_error)(const char *msg);
+    void (*notify)(void);
 } SlirpCb;
 
 
diff --git a/slirp/sbuf.h b/slirp/sbuf.h
index 644c201341..1cb9a42834 100644
--- a/slirp/sbuf.h
+++ b/slirp/sbuf.h
@@ -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 *);
diff --git a/slirp/socket.h b/slirp/socket.h
index 930ed95972..79b6fbd4c1 100644
--- a/slirp/socket.h
+++ b/slirp/socket.h
@@ -154,6 +154,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 */
diff --git a/net/slirp.c b/net/slirp.c
index b36092c948..4c39878933 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -198,6 +198,7 @@  static SlirpCb slirp_cb = {
     .timer_mod = net_slirp_timer_mod,
     .set_nonblock = qemu_set_nonblock,
     .guest_error = net_slirp_guest_error,
+    .notify = qemu_notify_event,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 912f235f65..17f28e97a6 100644
--- a/slirp/sbuf.c
+++ b/slirp/sbuf.c
@@ -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
diff --git a/slirp/socket.c b/slirp/socket.c
index 677fd20c9d..2b1b5052c4 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -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();
+    }
+}
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index e33fb83df5..456d5829e7 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -527,7 +527,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);
 
@@ -1140,10 +1140,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;
 		}