From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: jasowang@redhat.com, "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH] net: refactor net_socket_send()
Date: Sat, 10 Nov 2018 00:13:25 +0400 [thread overview]
Message-ID: <20181109201325.26177-1-marcandre.lureau@redhat.com> (raw)
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
reply other threads:[~2018-11-09 20:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181109201325.26177-1-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).