Reading again this code to see if there's a possibility that it goes into a loop -- without the calling code being able to do anything about it... Once the length has been set (i.e. after reading the "header" of the chunked transfer) there is no such possibility. If the old len param was meant to be the size of chunks then it is of course useless. Then the initial read itself might go on forever if it doesn't find a \r.... but it's done by read_crlf which has an optional max param preventing this (and it is set by default). So all is good in the end!