Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Unified Diff: net/socket_stream/socket_stream.cc

Issue 326009: Fix read loop in SocketStream. (Closed)
Patch Set: return OK if Read/Write succeeded Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket_stream/socket_stream.cc
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index 3980c529e5def92f71a28056ccaf38de51e2bd8b..a90aca6fed0eb4400af67c5f8de910a9b4c2ceda 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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698