[Qemu-devel] [PATCH] net: refactor net_socket_send()

Marc-André Lureau posted 1 patch 5 years, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20181109201325.26177-1-marcandre.lureau@redhat.com
Test docker-clang@ubuntu passed
Test checkpatch passed
Test asan passed
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
net/socket.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
[Qemu-devel] [PATCH] net: refactor net_socket_send()
Posted by Marc-André Lureau 5 years, 5 months ago
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 --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;
     }
 }
 
-- 
2.19.1.708.g4ede3d42df