Skip to content

Commit

Permalink
Make sure to send the SpdySettings frame as soon as possible.
Browse files Browse the repository at this point in the history
We weren't sending out the SpdySettings frame until the first SYN_STREAM.

BUG=none
TEST=new unit test

Review URL: http://codereview.chromium.org/5180004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66800 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
willchan@chromium.org committed Nov 19, 2010
1 parent e30a9ea commit 4954fe1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
5 changes: 2 additions & 3 deletions net/spdy/spdy_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ net::Error SpdySession::InitializeWithSocket(
is_secure_ = is_secure;
certificate_error_code_ = certificate_error_code;

// This is a newly initialized session that no client should have a handle to
// yet, so there's no need to start writing data as in OnTCPConnect(), but we
// should start reading data.
// Write out any data that we might have to send, such as the settings frame.
WriteSocketLater();
net::Error error = ReadSocket();
if (error == ERR_IO_PENDING)
return OK;
Expand Down
67 changes: 65 additions & 2 deletions net/spdy/spdy_session_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ TEST_F(SpdySessionTest, CancelPendingCreateStream) {
SpdySessionDependencies session_deps;
session_deps.host_resolver->set_synchronous_mode(true);

// Set up the socket so we read a SETTINGS frame that raises max concurrent
// streams to 2.
MockRead reads[] = {
MockRead(false, ERR_IO_PENDING) // Stall forever.
};
Expand Down Expand Up @@ -325,6 +323,71 @@ TEST_F(SpdySessionTest, CancelPendingCreateStream) {
MessageLoop::current()->RunAllPending();
}

TEST_F(SpdySessionTest, SendSettingsOnNewSession) {
SpdySessionDependencies session_deps;
session_deps.host_resolver->set_synchronous_mode(true);

MockRead reads[] = {
MockRead(false, ERR_IO_PENDING) // Stall forever.
};

// Create the bogus setting that we want to verify is sent out.
// Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But
// to set it into the SpdySettingsStorage, we need to mark as
// SETTINGS_FLAG_PLEASE_PERSIST.
spdy::SpdySettings settings;
const uint32 kBogusSettingId = 0xABAB;
const uint32 kBogusSettingValue = 0xCDCD;
spdy::SettingsFlagsAndId id(kBogusSettingId);
id.set_id(kBogusSettingId);
id.set_flags(spdy::SETTINGS_FLAG_PERSISTED);
settings.push_back(spdy::SpdySetting(id, kBogusSettingValue));
MockConnect connect_data(false, OK);
scoped_ptr<spdy::SpdyFrame> settings_frame(
ConstructSpdySettings(settings));
MockWrite writes[] = {
CreateMockWrite(*settings_frame),
};

StaticSocketDataProvider data(
reads, arraysize(reads), writes, arraysize(writes));
data.set_connect_data(connect_data);
session_deps.socket_factory->AddSocketDataProvider(&data);

SSLSocketDataProvider ssl(false, OK);
session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);

scoped_refptr<HttpNetworkSession> http_session(
SpdySessionDependencies::SpdyCreateSession(&session_deps));

const std::string kTestHost("www.foo.com");
const int kTestPort = 80;
HostPortPair test_host_port_pair(kTestHost, kTestPort);
HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());

id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
settings.clear();
settings.push_back(spdy::SpdySetting(id, kBogusSettingValue));
http_session->mutable_spdy_settings()->Set(test_host_port_pair, settings);
SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
EXPECT_FALSE(spdy_session_pool->HasSession(pair));
scoped_refptr<SpdySession> session =
spdy_session_pool->Get(pair, http_session->mutable_spdy_settings(),
BoundNetLog());
EXPECT_TRUE(spdy_session_pool->HasSession(pair));

scoped_refptr<TCPSocketParams> tcp_params(
new TCPSocketParams(kTestHost, kTestPort, MEDIUM, GURL(), false));
scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
EXPECT_EQ(OK,
connection->Init(test_host_port_pair.ToString(), tcp_params, MEDIUM,
NULL, http_session->tcp_socket_pool(),
BoundNetLog()));
EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(data.at_write_eof());
}

} // namespace

} // namespace net

0 comments on commit 4954fe1

Please sign in to comment.