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

Unified Diff: content/browser/renderer_host/p2p/socket_host_tcp.cc

Issue 13926013: Fix P2PSocketHostTcp to handle async write correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
Index: content/browser/renderer_host/p2p/socket_host_tcp.cc
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp.cc b/content/browser/renderer_host/p2p/socket_host_tcp.cc
index be59f72645186d4d98a60bb8245cf53a3dd5774d..8acbe3ac8aad19eb0ba0a907a6aebc48add3ff92 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp.cc
+++ b/content/browser/renderer_host/p2p/socket_host_tcp.cc
@@ -21,6 +21,7 @@ namespace content {
P2PSocketHostTcp::P2PSocketHostTcp(IPC::Sender* message_sender, int id)
: P2PSocketHost(message_sender, id),
+ write_pending_(false),
connected_(false) {
}
@@ -226,7 +227,7 @@ void P2PSocketHostTcp::Send(const net::IPEndPoint& to,
}
void P2PSocketHostTcp::DoWrite() {
- while (write_buffer_ && state_ == STATE_OPEN) {
+ while (write_buffer_ && state_ == STATE_OPEN && !write_pending_) {
int result = socket_->Write(write_buffer_, write_buffer_->BytesRemaining(),
base::Bind(&P2PSocketHostTcp::OnWritten,
base::Unretained(this)));
@@ -235,7 +236,10 @@ void P2PSocketHostTcp::DoWrite() {
}
void P2PSocketHostTcp::OnWritten(int result) {
+ DCHECK(write_pending_);
DCHECK_NE(result, net::ERR_IO_PENDING);
+
+ write_pending_ = false;
HandleWriteResult(result);
DoWrite();
}
@@ -253,7 +257,9 @@ void P2PSocketHostTcp::HandleWriteResult(int result) {
write_queue_.pop();
}
}
- } else if (result != net::ERR_IO_PENDING) {
+ } else if (result == net::ERR_IO_PENDING) {
+ write_pending_ = true;
+ } else {
LOG(ERROR) << "Error when sending data in TCP socket: " << result;
OnError();
}
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp.h ('k') | content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698