[Spice-commits] server/reds-stream.c
Frediano Ziglio
fziglio at kemper.freedesktop.org
Fri Jan 27 10:51:08 UTC 2017
server/reds-stream.c | 31 ++++++++++++-------------------
1 file changed, 12 insertions(+), 19 deletions(-)
New commits:
commit 8cef0a4e8bb138161975946c0c0c84006f74507e
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Jan 26 15:59:55 2017 +0000
reds-stream: Simplify error logic
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>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
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;
}
More information about the Spice-commits
mailing list