diff mbox series

net: refactor net_socket_send()

Message ID 20181109201325.26177-1-marcandre.lureau@redhat.com
State New
Headers show
Series net: refactor net_socket_send() | expand

Commit Message

Marc-André Lureau Nov. 9, 2018, 8:13 p.m. UTC
Simplify net_socket_send(), avoid extra buf/buf1 variable, and
backwards goto.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 net/socket.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/net/socket.c b/net/socket.c
index c92354049b..8a9c30892d 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -159,17 +159,12 @@  static void net_socket_send(void *opaque)
 {
     NetSocketState *s = opaque;
     int size;
-    int ret;
-    uint8_t buf1[NET_BUFSIZE];
-    const uint8_t *buf;
-
-    size = qemu_recv(s->fd, buf1, sizeof(buf1), 0);
-    if (size < 0) {
-        if (errno != EWOULDBLOCK)
-            goto eoc;
-    } else if (size == 0) {
+    uint8_t buf[NET_BUFSIZE];
+
+    size = qemu_recv(s->fd, buf, sizeof(buf), 0);
+    if (size == 0 || (size < 0 && errno != EWOULDBLOCK) ||
+        net_fill_rstate(&s->rs, buf, size) == -1) {
         /* end of connection */
-    eoc:
         net_socket_read_poll(s, false);
         net_socket_write_poll(s, false);
         if (s->listen_fd != -1) {
@@ -181,15 +176,6 @@  static void net_socket_send(void *opaque)
         net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
         s->nc.link_down = true;
         memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
-
-        return;
-    }
-    buf = buf1;
-
-    ret = net_fill_rstate(&s->rs, buf, size);
-
-    if (ret == -1) {
-        goto eoc;
     }
 }