[PATCH] chg: just take it as EOF if recv() returns 0
Jun Wu
quark at fb.com
Sat Aug 6 05:42:30 EDT 2016
Yes, please.
Excerpts from Yuya Nishihara's message of 2016-08-06 13:51:39 +0900:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1470399693 -32400
> # Fri Aug 05 21:21:33 2016 +0900
> # Node ID e59b4315a3f8602582f0d39e1c531faaa3119982
> # Parent 56e9357be6b2704678331999e8b4b02777fc724b
> chg: just take it as EOF if recv() returns 0
>
> hgc->sockfd is a blocking stream socket. recv() should never return 0 other
> than EOF.
>
> See 4fc4b8cc9957 for the original problem.
>
> diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
> --- a/contrib/chg/hgclient.c
> +++ b/contrib/chg/hgclient.c
> @@ -126,15 +126,10 @@ 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);
> - /* 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)
> + if (rsize < 1)
> abortmsg("failed to read data block");
> cursize += rsize;
> }
More information about the Mercurial-devel
mailing list