diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 05:20:19 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 05:20:19 +0000 |
commit | 6017951dcd626f9b910aeb9881985e50fce589e7 (patch) | |
tree | 70d03d79c3d8f35a807c0184665e9e379408d486 /net | |
parent | cf8ceccc0eee7f22a1f61b348e4b851e9a46cf5f (diff) | |
download | chromium_src-6017951dcd626f9b910aeb9881985e50fce589e7.zip chromium_src-6017951dcd626f9b910aeb9881985e50fce589e7.tar.gz chromium_src-6017951dcd626f9b910aeb9881985e50fce589e7.tar.bz2 |
Fix DoReadWrite loop in SocketStream.
If Read in DoReadWrite succeeded synchronously, it failed to call next Read.
Changed to call Read repeatedly after a Read finished both in synchronous return and asynchronous return.
Also fixes Write case as well.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/326009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30034 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/socket_stream/socket_stream.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 3980c52..a90aca6 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -578,18 +578,27 @@ int SocketStream::DoReadWrite(int result) { next_state_ = STATE_READ_WRITE; if (!read_buf_) { + // No read pending. read_buf_ = new IOBuffer(kReadBufferSize); result = socket_->Read(read_buf_, kReadBufferSize, &read_callback_); if (result > 0) { DidReceiveData(result); - result = OK; + return OK; } else if (result == 0) { // 0 indicates end-of-file, so socket was closed. Finish(); return ERR_CONNECTION_CLOSED; } + // If read is pending, try write as well. + // Otherwise, return the result and do next loop. + if (result != ERR_IO_PENDING) + return result; } + // Read is pending. + DCHECK(read_buf_); + if (write_buf_ && !current_write_buf_) { + // No write pending. current_write_buf_ = new DrainableIOBuffer(write_buf_, write_buf_size_); current_write_buf_->SetOffset(write_buf_offset_); result = socket_->Write(current_write_buf_, @@ -597,14 +606,13 @@ int SocketStream::DoReadWrite(int result) { &write_callback_); if (result > 0) { DidSendData(result); - result = OK; + return OK; } + return result; } - // We arrived here when Write is performed and finished. - if (result == OK) - return ERR_IO_PENDING; - return result; + // We arrived here when both operation is pending. + return ERR_IO_PENDING; } int SocketStream::HandleCertificateError(int result) { |