* [Qemu-devel] [PATCH] net: refactor net_socket_send()
@ 2018-11-09 20:13 Marc-André Lureau
0 siblings, 0 replies; only message in thread
From: Marc-André Lureau @ 2018-11-09 20:13 UTC (permalink / raw)
To: qemu-devel; +Cc: jasowang, Marc-André Lureau
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-11-09 20:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-09 20:13 [Qemu-devel] [PATCH] net: refactor net_socket_send() Marc-André Lureau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.