]> err.no Git - varnish/commitdiff
When we have some amount of a chunk header, but not all of it, we
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 19 Apr 2007 15:17:35 +0000 (15:17 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 19 Apr 2007 15:17:35 +0000 (15:17 +0000)
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

index 15d913e3282efd30a59e94e065e60566c1fa7e7e..c9e17074f6019d66b3c7d7b1643827474982a5bd 100644 (file)
@@ -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;