diff options
author | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-10 14:44:04 +0200 |
---|---|---|
committer | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-10 14:44:04 +0200 |
commit | bc960cddc702323d6261dcb067210989ded616d6 (patch) | |
tree | 8b7fb547d11019e24a924bdcfb492978609f9b39 /fbench | |
parent | c313649c622f12a9fc2ef52858d46c1771127f12 (diff) |
simplify newline adding
also, account for space for full URL to follow
Diffstat (limited to 'fbench')
-rw-r--r-- | fbench/src/fbench/client.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/fbench/src/fbench/client.cpp b/fbench/src/fbench/client.cpp index 5981c2dfcf2..94d0a78631b 100644 --- a/fbench/src/fbench/client.cpp +++ b/fbench/src/fbench/client.cpp @@ -122,27 +122,29 @@ int UrlReader::nextContent() { char *buf = _contentbuf; int totLen = 0; - int nl = 0; - while (totLen + 1 < _contentbufsize) { - int left = _contentbufsize - totLen; + // make sure we don't chop leftover URL + while (totLen + _args._maxLineSize < _contentbufsize) { // allow space for newline: - int len = _reader.ReadLine(buf, left - 1); + int room = _contentbufsize - totLen - 1; + int len = _reader.ReadLine(buf, room); if (len < 0) { // reached EOF - return totLen; + break; } + len = std::min(len, room); if (len > 0 && buf[0] == '/') { // reached next URL _leftOvers = buf; _leftOversLen = len; - return totLen; + break; } buf += len; + totLen += len; *buf++ = '\n'; - totLen += nl + len; - nl = 1; + totLen++; } - return totLen; + // ignore last newline + return (totLen > 0) ? totLen-1 : 0; } |