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

Unified Diff: net/socket/socks_client_socket.cc

Issue 169643006: Use sockets with unread data if they've never been used before. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweak SpdySession::IsReused (erf, got mixed in with a rebase) Created 6 years, 9 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: net/socket/socks_client_socket.cc
diff --git a/net/socket/socks_client_socket.cc b/net/socket/socks_client_socket.cc
index 67089589cc50eb6fd425608b565600de62685a20..c7dd95ad02c2cd0fcbdc5650bb155fc01cf6a9d5 100644
--- a/net/socket/socks_client_socket.cc
+++ b/net/socket/socks_client_socket.cc
@@ -6,6 +6,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/callback_helpers.h"
#include "base/compiler_specific.h"
#include "base/sys_byteorder.h"
#include "net/base/io_buffer.h"
@@ -65,6 +66,7 @@ SOCKSClientSocket::SOCKSClientSocket(
completed_handshake_(false),
bytes_sent_(0),
bytes_received_(0),
+ was_used_to_convey_data_(false),
host_resolver_(host_resolver),
host_request_info_(req_info),
priority_(priority),
@@ -137,11 +139,7 @@ void SOCKSClientSocket::SetOmniboxSpeculation() {
}
bool SOCKSClientSocket::WasEverUsed() const {
- if (transport_.get() && transport_->socket()) {
- return transport_->socket()->WasEverUsed();
- }
- NOTREACHED();
- return false;
+ return was_used_to_convey_data_;
}
bool SOCKSClientSocket::UsingTCPFastOpen() const {
@@ -185,7 +183,13 @@ int SOCKSClientSocket::Read(IOBuffer* buf, int buf_len,
DCHECK_EQ(STATE_NONE, next_state_);
DCHECK(user_callback_.is_null());
- return transport_->socket()->Read(buf, buf_len, callback);
+ int rv = transport_->socket()->Read(
+ buf, buf_len,
+ base::Bind(&SOCKSClientSocket::OnReadWriteComplete,
+ base::Unretained(this), callback));
+ if (rv > 0)
+ was_used_to_convey_data_ = true;
+ return rv;
}
// Write is called by the transport layer. This can only be done if the
@@ -196,7 +200,13 @@ int SOCKSClientSocket::Write(IOBuffer* buf, int buf_len,
DCHECK_EQ(STATE_NONE, next_state_);
DCHECK(user_callback_.is_null());
- return transport_->socket()->Write(buf, buf_len, callback);
+ int rv = transport_->socket()->Write(
+ buf, buf_len,
+ base::Bind(&SOCKSClientSocket::OnReadWriteComplete,
+ base::Unretained(this), callback));
+ if (rv > 0)
+ was_used_to_convey_data_ = true;
+ return rv;
}
bool SOCKSClientSocket::SetReceiveBufferSize(int32 size) {
@@ -213,10 +223,8 @@ void SOCKSClientSocket::DoCallback(int result) {
// Since Run() may result in Read being called,
// clear user_callback_ up front.
- CompletionCallback c = user_callback_;
- user_callback_.Reset();
DVLOG(1) << "Finished setting up SOCKS handshake";
- c.Run(result);
+ base::ResetAndReturn(&user_callback_).Run(result);
}
void SOCKSClientSocket::OnIOComplete(int result) {
@@ -228,6 +236,16 @@ void SOCKSClientSocket::OnIOComplete(int result) {
}
}
+void SOCKSClientSocket::OnReadWriteComplete(const CompletionCallback& callback,
+ int result) {
+ DCHECK_NE(ERR_IO_PENDING, result);
+ DCHECK(!callback.is_null());
+
+ if (result > 0)
+ was_used_to_convey_data_ = true;
+ callback.Run(result);
+}
+
int SOCKSClientSocket::DoLoop(int last_io_result) {
DCHECK_NE(next_state_, STATE_NONE);
int rv = last_io_result;

Powered by Google App Engine
This is Rietveld 408576698