Re: [PATCH spice-server] reds-stream: Simplify error logic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
> 
> 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@xxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]