Patchwork [06/14] tap: insert tap_can_send() into tap_send()

login
register
mail settings
Submitter Juan Quintela
Date March 10, 2010, 10:03 a.m.
Message ID <05a971c6373db001152b1d064a3618d90cf2772d.1268214633.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/47221/
State New
Headers show

Comments

Juan Quintela - March 10, 2010, 10:03 a.m.
This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 net/tap.c |   27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)

Patch

diff --git a/net/tap.c b/net/tap.c
index 7a7320c..3ab65a3 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -61,17 +61,15 @@  typedef struct TAPState {

 static int launch_script(const char *setup_script, const char *ifname, int fd);

-static int tap_can_send(void *opaque);
 static void tap_send(void *opaque);
 static void tap_writable(void *opaque);

 static void tap_update_fd_handler(TAPState *s)
 {
-    qemu_set_fd_handler2(s->fd,
-                         s->read_poll  ? tap_can_send : NULL,
-                         s->read_poll  ? tap_send     : NULL,
-                         s->write_poll ? tap_writable : NULL,
-                         s);
+    qemu_set_fd_handler(s->fd,
+                        s->read_poll  ? tap_send     : NULL,
+                        s->write_poll ? tap_writable : NULL,
+                        s);
 }

 static void tap_read_poll(TAPState *s, int enable)
@@ -165,13 +163,6 @@  static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
     return tap_write_packet(s, iov, 1);
 }

-static int tap_can_send(void *opaque)
-{
-    TAPState *s = opaque;
-
-    return qemu_can_send_packet(&s->nc);
-}
-
 #ifndef __sun__
 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
 {
@@ -188,12 +179,10 @@  static void tap_send_completed(VLANClientState *nc, ssize_t len)
 static void tap_send(void *opaque)
 {
     TAPState *s = opaque;
-    int size;

-    do {
+    while (qemu_can_send_packet(&s->nc) > 0) {
         uint8_t *buf = s->buf;
-
-        size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
+        int size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
         if (size <= 0) {
             break;
         }
@@ -206,8 +195,10 @@  static void tap_send(void *opaque)
         size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
         if (size == 0) {
             tap_read_poll(s, 0);
+        } else if (size < 0) {
+            return;
         }
-    } while (size > 0 && qemu_can_send_packet(&s->nc));
+    }
 }

 int tap_has_ufo(VLANClientState *nc)