diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-13 23:08:47 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-13 23:08:47 +0000 |
commit | b2ca508afc56d4b7f6d5b036dd721604440210b3 (patch) | |
tree | 69b9b1146c0af1e063b5f38ce3e2307b7a223399 /net/base/file_stream_posix.cc | |
parent | 2ce5d948eb4ac06b30fc411d276eb6fd70ad1721 (diff) | |
download | chromium_src-b2ca508afc56d4b7f6d5b036dd721604440210b3.zip chromium_src-b2ca508afc56d4b7f6d5b036dd721604440210b3.tar.gz chromium_src-b2ca508afc56d4b7f6d5b036dd721604440210b3.tar.bz2 |
Add a new method ReadUntilComplete to FileStream which ensures that all requested bytes are read from the file in one call, assuming no errors occurr or EOF is reached.
Review URL: http://codereview.chromium.org/21363
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9803 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/file_stream_posix.cc')
-rw-r--r-- | net/base/file_stream_posix.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc index 7b248a4..151cf5d 100644 --- a/net/base/file_stream_posix.cc +++ b/net/base/file_stream_posix.cc @@ -154,6 +154,27 @@ int FileStream::Read( } } +int FileStream::ReadUntilComplete(char *buf, int buf_len) { + int to_read = buf_len; + int bytes_total = 0; + + do { + int bytes_read = Read(buf, to_read, NULL); + if (bytes_read <= 0) { + if (bytes_total == 0) + return bytes_read; + + return bytes_total; + } + + bytes_total += bytes_read; + buf += bytes_read; + to_read -= bytes_read; + } while (bytes_total < buf_len); + + return bytes_total; +} + // TODO(deanm): async. int FileStream::Write( const char* buf, int buf_len, CompletionCallback* callback) { |