From 4fc9c40fccaa2feef9fbe08ea85d226ea53dc6ea Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 19 Apr 2007 15:17:35 +0000 Subject: [PATCH] When we have some amount of a chunk header, but not all of it, we need to read more from the fd. The semantics we _really_ want for that read operation is "wait until at least one char is available, then return as many as N to us". This can be done with a combination of system calls, but it is likely just as cheap to just read one char at a time, so we do that. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1359 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_fetch.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 15d913e3..c9e17074 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -113,7 +113,22 @@ fetch_chunked(const struct sess *sp, int fd, struct http *hp) /* If we didn't succeed, add to buffer, try again */ if (q == NULL || q == buf || *q != '\n') { xxxassert(be > bp); - i = http_Read(hp, fd, bp, be - bp); + /* + * The sematics we need here is "read until you have + * received at least one character, but feel free to + * return up to (be-bp) if they are available, but do + * not wait for those extra characters. + * + * The canonical way to do that is to do a blocking + * read(2) of one char, then change to nonblocking, + * read as many as we find, then change back to + * blocking reads again. + * + * Hardly much more efficient and certainly a good + * deal more complex than reading a single character + * at a time. + */ + i = http_Read(hp, fd, bp, 1); if (i <= 0) return (-1); bp += i; -- 2.39.5