Patchwork [v2,04/15] coroutine-io: handle zero returns from recv

login
register
mail settings
Submitter Paolo Bonzini
Date Sept. 16, 2011, 2:25 p.m.
Message ID <1316183152-5481-5-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/114930/
State New
Headers show

Comments

Paolo Bonzini - Sept. 16, 2011, 2:25 p.m.
When the other side is shutdown, read returns zero (writes return EPIPE).
In this case, care must be taken to avoid infinite loops.  This error
was already present in sheepdog.

Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cutils.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
MORITA Kazutaka - Sept. 17, 2011, 6:50 a.m.
At Fri, 16 Sep 2011 16:25:41 +0200,
Paolo Bonzini wrote:
> 
> When the other side is shutdown, read returns zero (writes return EPIPE).
> In this case, care must be taken to avoid infinite loops.  This error
> was already present in sheepdog.
> 
> Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  cutils.c |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/cutils.c b/cutils.c
> index b302020..295187f 100644
> --- a/cutils.c
> +++ b/cutils.c
> @@ -501,8 +501,11 @@ static int do_sendv_recvv(int sockfd, struct iovec *iov, int len, int offset,
>                  }
>                  break;
>              }
> -            iovlen--, p++;
> +            if (rc == 0) {
> +                break;
> +            }
>              ret += rc;
> +            iovlen--, p++;
>          }
>  #endif
>      }
> @@ -567,6 +570,9 @@ int coroutine_fn qemu_co_sendv(int sockfd, struct iovec *iov,
>              }
>              break;
>          }
> +        if (ret == 0) {
> +            break;
> +        }
>          total += ret, len -= ret;
>      }

When EPIPE is set, write() returns -1 doesn't it?

It looks like qemu_co_recvv() handles a zero return correctly, so I
think this patch is not needed.


Thanks,

Kazutaka

Patch

diff --git a/cutils.c b/cutils.c
index b302020..295187f 100644
--- a/cutils.c
+++ b/cutils.c
@@ -501,8 +501,11 @@  static int do_sendv_recvv(int sockfd, struct iovec *iov, int len, int offset,
                 }
                 break;
             }
-            iovlen--, p++;
+            if (rc == 0) {
+                break;
+            }
             ret += rc;
+            iovlen--, p++;
         }
 #endif
     }
@@ -567,6 +570,9 @@  int coroutine_fn qemu_co_sendv(int sockfd, struct iovec *iov,
             }
             break;
         }
+        if (ret == 0) {
+            break;
+        }
         total += ret, len -= ret;
     }