[PATCH] chg: handle EOF reading data block
Yuya Nishihara
yuya at tcha.org
Tue Jul 19 12:42:12 UTC 2016
On Mon, 18 Jul 2016 19:34:10 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1468864506 -3600
> # Mon Jul 18 18:55:06 2016 +0100
> # Node ID c063823d664a978415bde11e0e13a6c3983d1dd9
> # Parent 953839de96ab574caa40557c542c262286c6287c
> # Available At https://bitbucket.org/quark-zju/hg-draft
> # hg pull https://bitbucket.org/quark-zju/hg-draft -r c063823d664a
> chg: handle EOF reading data block
> --- a/contrib/chg/hgclient.c
> +++ b/contrib/chg/hgclient.c
> @@ -126,10 +126,15 @@ static void readchannel(hgclient_t *hgc)
> return; /* assumes input request */
>
> size_t cursize = 0;
> + int emptycount = 0;
> while (cursize < hgc->ctx.datasize) {
> rsize = recv(hgc->sockfd, hgc->ctx.data + cursize,
> hgc->ctx.datasize - cursize, 0);
> - if (rsize < 0)
> + /* rsize == 0 normally indicates EOF, while it's also a valid
> + * packet size for unix socket. treat it as EOF and abort if
> + * we get many empty responses in a row. */
> + emptycount = (rsize == 0 ? emptycount + 1 : 0);
> + if (rsize < 0 || emptycount > 20)
I'm curious when blocking recv() may return 0 other than EOF and zero-size
request. I suspect that the original condition "rsize < 0" was totally wrong.
More information about the Mercurial-devel
mailing list