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

Unified Diff: net/spdy/spdy_session.cc

Issue 13834009: SPDY - Re-land greedy read support for SpdySession (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: histograms to track bytes_read during init 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
« no previous file with comments | « net/spdy/spdy_session.h ('k') | net/spdy/spdy_session_spdy2_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_session.cc
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 9943190e72dd5117fcde19b242da7d05b02941c6..1bc0b0da0ba63677d30d03d50d88cdcff78c246b 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -329,14 +329,13 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair,
http_server_properties_(http_server_properties),
connection_(new ClientSocketHandle),
read_buffer_(new IOBuffer(kReadBufferSize)),
- read_pending_(false),
stream_hi_water_mark_(kFirstStreamId),
write_pending_(false),
delayed_write_pending_(false),
is_secure_(false),
certificate_error_code_(OK),
error_(OK),
- state_(IDLE),
+ state_(STATE_IDLE),
max_concurrent_streams_(initial_max_concurrent_streams == 0 ?
kInitialMaxConcurrentStreams :
initial_max_concurrent_streams),
@@ -347,7 +346,8 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair,
streams_pushed_count_(0),
streams_pushed_and_claimed_count_(0),
streams_abandoned_count_(0),
- bytes_received_(0),
+ total_bytes_received_(0),
+ bytes_read_(0),
sent_settings_(false),
received_settings_(false),
stalled_streams_(0),
@@ -388,8 +388,8 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair,
}
SpdySession::~SpdySession() {
- if (state_ != CLOSED) {
- state_ = CLOSED;
+ if (state_ != STATE_CLOSED) {
+ state_ = STATE_CLOSED;
// Cleanup all the streams.
CloseAllStreams(net::ERR_ABORTED);
@@ -421,7 +421,7 @@ net::Error SpdySession::InitializeWithSocket(
base::StatsCounter spdy_sessions("spdy.sessions");
spdy_sessions.Increment();
- state_ = CONNECTED;
+ state_ = STATE_DO_READ;
connection_.reset(connection);
is_secure_ = is_secure;
certificate_error_code_ = certificate_error_code;
@@ -472,17 +472,20 @@ net::Error SpdySession::InitializeWithSocket(
// Write out any data that we might have to send, such as the settings frame.
WriteSocketLater();
- net::Error error = ReadSocket();
+ int error = DoLoop(OK);
+ UMA_HISTOGRAM_COUNTS("Net.SpdySession.Init.BytesRead", bytes_read_);
if (error == ERR_IO_PENDING)
return OK;
- return error;
+ if (error != OK)
+ UMA_HISTOGRAM_COUNTS("Net.SpdySession.InitAndError.BytesRead", bytes_read_);
Ryan Hamilton 2013/04/14 02:21:46 We had also talked about adding a histogram of the
ramant (doing other things) 2013/04/16 19:12:23 Added new histograms per our discussion. Done.
+ return static_cast<net::Error>(error);
}
bool SpdySession::VerifyDomainAuthentication(const std::string& domain) {
if (!verify_domain_authentication_)
return true;
- if (state_ != CONNECTED)
+ if (!IsConnected())
return false;
SSLInfo ssl_info;
@@ -510,7 +513,7 @@ int SpdySession::GetPushStream(
const GURL& url,
scoped_refptr<SpdyStream>* stream,
const BoundNetLog& stream_net_log) {
- CHECK_NE(state_, CLOSED);
+ CHECK_NE(state_, STATE_CLOSED);
*stream = NULL;
@@ -880,7 +883,7 @@ LoadState SpdySession::GetLoadState() const {
// If we're connecting, defer to the connection to give us the actual
// LoadState.
- if (state_ == CONNECTING)
+ if (state_ == STATE_CONNECTING)
return connection_->GetLoadState();
// Just report that we're idle since the session could be doing
@@ -889,44 +892,97 @@ LoadState SpdySession::GetLoadState() const {
}
void SpdySession::OnReadComplete(int bytes_read) {
+ DCHECK_NE(state_, STATE_DO_READ);
+ DoLoop(bytes_read);
+}
+
+void SpdySession::StartRead() {
+ DCHECK_NE(state_, STATE_DO_READ_COMPLETE);
+ DoLoop(OK);
+}
+
+int SpdySession::DoLoop(int result) {
+ bytes_read_ = 0;
+
+ // The SpdyFramer will use callbacks onto |this| as it parses frames.
+ // When errors occur, those callbacks can lead to teardown of all references
+ // to |this|, so maintain a reference to self during this call for safe
+ // cleanup.
+ scoped_refptr<SpdySession> self(this);
+
+ do {
+ switch (state_) {
+ case STATE_DO_READ:
+ DCHECK_EQ(result, OK);
+ result = DoRead();
+ break;
+ case STATE_DO_READ_COMPLETE:
+ result = DoReadComplete(result);
+ break;
+ case STATE_CLOSED:
+ result = ERR_CONNECTION_CLOSED;
+ break;
+ default:
+ NOTREACHED() << "state_: " << state_;
+ break;
+ }
+ } while (result != ERR_IO_PENDING && state_ != STATE_CLOSED);
+
+ return result;
+}
+
+int SpdySession::DoRead() {
+ if (bytes_read_ > kMaxReadBytes) {
+ state_ = STATE_DO_READ;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&SpdySession::StartRead,
+ weak_factory_.GetWeakPtr()));
+ return ERR_IO_PENDING;
+ }
+
+ CHECK(connection_.get());
+ CHECK(connection_->socket());
+ state_ = STATE_DO_READ_COMPLETE;
+ return connection_->socket()->Read(
+ read_buffer_.get(),
+ kReadBufferSize,
+ base::Bind(&SpdySession::OnReadComplete, weak_factory_.GetWeakPtr()));
+}
+
+int SpdySession::DoReadComplete(int result) {
// Parse a frame. For now this code requires that the frame fit into our
// buffer (32KB).
// TODO(mbelshe): support arbitrarily large frames!
- read_pending_ = false;
-
- if (bytes_read <= 0) {
+ if (result <= 0) {
// Session is tearing down.
- net::Error error = static_cast<net::Error>(bytes_read);
- if (bytes_read == 0)
+ net::Error error = static_cast<net::Error>(result);
+ if (result == 0)
error = ERR_CONNECTION_CLOSED;
- CloseSessionOnError(error, true, "bytes_read is <= 0.");
- return;
+ CloseSessionOnError(error, true, "result is <= 0.");
+ return ERR_CONNECTION_CLOSED;
}
- bytes_received_ += bytes_read;
+ total_bytes_received_ += result;
+ bytes_read_ += result;
last_activity_time_ = base::TimeTicks::Now();
- // The SpdyFramer will use callbacks onto |this| as it parses frames.
- // When errors occur, those callbacks can lead to teardown of all references
- // to |this|, so maintain a reference to self during this call for safe
- // cleanup.
- scoped_refptr<SpdySession> self(this);
-
DCHECK(buffered_spdy_framer_.get());
char* data = read_buffer_->data();
- while (bytes_read &&
+ while (result &&
buffered_spdy_framer_->error_code() ==
SpdyFramer::SPDY_NO_ERROR) {
uint32 bytes_processed =
- buffered_spdy_framer_->ProcessInput(data, bytes_read);
- bytes_read -= bytes_processed;
+ buffered_spdy_framer_->ProcessInput(data, result);
+ result -= bytes_processed;
data += bytes_processed;
}
- if (state_ != CLOSED)
- ReadSocket();
+ if (IsConnected())
+ state_ = STATE_DO_READ;
+ return OK;
}
void SpdySession::OnWriteComplete(int result) {
@@ -983,49 +1039,11 @@ void SpdySession::OnWriteComplete(int result) {
}
}
-net::Error SpdySession::ReadSocket() {
- if (read_pending_)
- return OK;
-
- if (state_ == CLOSED) {
- NOTREACHED();
- return ERR_UNEXPECTED;
- }
-
- CHECK(connection_.get());
- CHECK(connection_->socket());
- int bytes_read = connection_->socket()->Read(
- read_buffer_.get(),
- kReadBufferSize,
- base::Bind(&SpdySession::OnReadComplete, base::Unretained(this)));
- switch (bytes_read) {
- case 0:
- // Socket is closed!
- CloseSessionOnError(ERR_CONNECTION_CLOSED, true, "bytes_read is 0.");
- return ERR_CONNECTION_CLOSED;
- case net::ERR_IO_PENDING:
- // Waiting for data. Nothing to do now.
- read_pending_ = true;
- return ERR_IO_PENDING;
- default:
- // Data was read, process it.
- // Schedule the work through the message loop to avoid recursive
- // callbacks.
- read_pending_ = true;
- MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&SpdySession::OnReadComplete,
- weak_factory_.GetWeakPtr(), bytes_read));
- break;
- }
- return OK;
-}
-
void SpdySession::WriteSocketLater() {
if (delayed_write_pending_)
return;
- if (state_ < CONNECTED)
+ if (!IsConnected())
return;
delayed_write_pending_ = true;
@@ -1042,7 +1060,7 @@ void SpdySession::WriteSocket() {
// If the socket isn't connected yet, just wait; we'll get called
// again when the socket connection completes. If the socket is
// closed, just return.
- if (state_ < CONNECTED || state_ == CLOSED)
+ if (!IsConnected())
return;
if (write_pending_) // Another write is in progress still.
@@ -1165,8 +1183,8 @@ void SpdySession::CloseSessionOnError(net::Error err,
// Don't close twice. This can occur because we can have both
// a read and a write outstanding, and each can complete with
// an error.
- if (state_ != CLOSED) {
- state_ = CLOSED;
+ if (!IsClosed()) {
+ state_ = STATE_CLOSED;
error_ = err;
if (remove_from_pool)
RemoveFromPool();
@@ -2123,16 +2141,16 @@ void SpdySession::RecordHistograms() {
// for larger volumes of data being sent.
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd",
val, 1, 200, 100);
- if (bytes_received_ > 10 * 1024) {
+ if (total_bytes_received_ > 10 * 1024) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd10K",
val, 1, 200, 100);
- if (bytes_received_ > 25 * 1024) {
+ if (total_bytes_received_ > 25 * 1024) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd25K",
val, 1, 200, 100);
- if (bytes_received_ > 50 * 1024) {
+ if (total_bytes_received_ > 50 * 1024) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd50K",
val, 1, 200, 100);
- if (bytes_received_ > 100 * 1024) {
+ if (total_bytes_received_ > 100 * 1024) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd100K",
val, 1, 200, 100);
}
« no previous file with comments | « net/spdy/spdy_session.h ('k') | net/spdy/spdy_session_spdy2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698