[Spice-devel] [PATCH spice-server] reds-stream: Simplify error logic
Frediano Ziglio
fziglio at redhat.com
Thu Jan 26 16:00:55 UTC 2017
Handling read returning 0 (usually end of connection/pipe)
is the same of handling an error (read result -1) with errno == 0
so merge the two paths to reuse code and simplify.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
Patch is much smaller without space changes.
---
server/reds-stream.c | 31 ++++++++++++-------------------
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/server/reds-stream.c b/server/reds-stream.c
index 2730549..d0dadb9 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -499,28 +499,21 @@ static void async_read_handler(G_GNUC_UNUSED int fd,
spice_assert(n > 0);
n = reds_stream_read(stream, async->now, n);
if (n <= 0) {
- if (n < 0) {
- switch (errno) {
- case EAGAIN:
- if (!stream->watch) {
- stream->watch = reds_core_watch_add(reds, stream->socket,
- SPICE_WATCH_EVENT_READ,
- async_read_handler, async);
- }
- return;
- case EINTR:
- break;
- default:
- async_read_clear_handlers(async);
- if (async->error) {
- async->error(async->opaque, errno);
- }
- return;
+ int err = n < 0 ? errno: 0;
+ switch (err) {
+ case EAGAIN:
+ if (!stream->watch) {
+ stream->watch = reds_core_watch_add(reds, stream->socket,
+ SPICE_WATCH_EVENT_READ,
+ async_read_handler, async);
}
- } else {
+ return;
+ case EINTR:
+ break;
+ default:
async_read_clear_handlers(async);
if (async->error) {
- async->error(async->opaque, 0);
+ async->error(async->opaque, err);
}
return;
}
--
2.9.3
More information about the Spice-devel
mailing list