diff options
author | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-09 09:50:04 +0200 |
---|---|---|
committer | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-09 09:50:04 +0200 |
commit | 40e1b9fb8fdebb4471839c2393b0c04d55d60cfb (patch) | |
tree | db06635e616c6130c9077c1acf5561fd4d409924 /fbench | |
parent | dd297ac2a96710fbbc53cd3de896f3b6b89f24df (diff) |
refactor loop for url reading
Diffstat (limited to 'fbench')
-rw-r--r-- | fbench/src/fbench/client.cpp | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/fbench/src/fbench/client.cpp b/fbench/src/fbench/client.cpp index 3141b07482d..b209f4842bd 100644 --- a/fbench/src/fbench/client.cpp +++ b/fbench/src/fbench/client.cpp @@ -56,6 +56,7 @@ public: _contentbuf = new char[_contentbufsize]; } } + bool reset(); int nextUrl(); int getContent(); char *url() const { return _linebuf; } @@ -63,6 +64,21 @@ public: ~UrlReader() {} }; +bool UrlReader::reset() +{ + _reader.Reset(); + // Start reading from offset + if (_args._singleQueryFile) { + _reader.SetFilePos(_args._queryfileOffset); + } + if (_restarts == _args._restartLimit) { + return false; + } else if (_args._restartLimit > 0) { + _restarts++; + } + return true; +} + int UrlReader::nextUrl() { char *buf = _linebuf; @@ -78,40 +94,22 @@ int UrlReader::nextUrl() _leftOvers = NULL; return _leftOversLen; } - // Read maximum to _queryfileOffsetEnd - if ( _args._singleQueryFile && _reader.GetFilePos() >= _args._queryfileEndOffset ) { - _reader.SetFilePos(_args._queryfileOffset); - if (_restarts == _args._restartLimit) { - return 0; - } else if (_args._restartLimit > 0) { - _restarts++; + bool again = true; + for (int retry = 0; again && retry < 100; ++retry) { + // Read maximum to _queryfileEndOffset + if ( _args._singleQueryFile && _reader.GetFilePos() >= _args._queryfileEndOffset ) { + again = reset(); } - } - int ll = _reader.ReadLine(buf, buflen); - while (ll > 0 && _args._usePostMode && buf[0] != '/') { - ll = _reader.ReadLine(buf, buflen); - } - if (ll > 0 && (buf[0] == '/' || !_args._usePostMode)) { - return ll; - } - if (_restarts == _args._restartLimit) { - return 0; - } else if (_args._restartLimit > 0) { - _restarts++; - } - if (ll < 0) { - _reader.Reset(); - // Start reading from offset - if (_args._singleQueryFile) { - _reader.SetFilePos(_args._queryfileOffset); + int ll = _reader.ReadLine(buf, buflen); + if (ll > 0) { + if (buf[0] == '/' || !_args._usePostMode) { + return ll; + } + } + if (ll < 0) { + // reached EOF + again = reset(); } - } - ll = _reader.ReadLine(buf, buflen); - while (ll > 0 && _args._usePostMode && buf[0] != '/') { - ll = _reader.ReadLine(buf, buflen); - } - if (ll > 0 && (buf[0] == '/' || !_args._usePostMode)) { - return ll; } return 0; } |