[Spice-devel] [PATCH spice-server] reds-stream: Simplify error logic
Christophe Fergeau
cfergeau at redhat.com
Fri Jan 27 10:37:44 UTC 2017
On Thu, Jan 26, 2017 at 04:00:55PM +0000, Frediano Ziglio wrote:
> 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.
Indeed it is, it becomes
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,8 +499,8 @@ 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) {
+ int err = n < 0 ? errno: 0;
+ switch (err) {
case EAGAIN:
if (!stream->watch) {
stream->watch = reds_core_watch_add(reds, stream->socket,
@@ -513,14 +513,7 @@ static void async_read_handler(G_GNUC_UNUSED int fd,
default:
async_read_clear_handlers(async);
if (async->error) {
- async->error(async->opaque, errno);
- }
- return;
- }
- } else {
- async_read_clear_handlers(async);
- if (async->error) {
- async->error(async->opaque, 0);
+ async->error(async->opaque, err);
}
return;
}
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
Christophe
> ---
> 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
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170127/ea08d84d/attachment.sig>
More information about the Spice-devel
mailing list