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

Side by Side Diff: net/spdy/spdy_session.cc

Issue 9667016: Close idle connections / SPDY sessions when needed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 net::Error SpdySession::InitializeWithSocket( 373 net::Error SpdySession::InitializeWithSocket(
374 ClientSocketHandle* connection, 374 ClientSocketHandle* connection,
375 bool is_secure, 375 bool is_secure,
376 int certificate_error_code) { 376 int certificate_error_code) {
377 base::StatsCounter spdy_sessions("spdy.sessions"); 377 base::StatsCounter spdy_sessions("spdy.sessions");
378 spdy_sessions.Increment(); 378 spdy_sessions.Increment();
379 379
380 state_ = CONNECTED; 380 state_ = CONNECTED;
381 connection_.reset(connection); 381 connection_.reset(connection);
382 connection_->AddLayeredPool(this);
382 is_secure_ = is_secure; 383 is_secure_ = is_secure;
383 certificate_error_code_ = certificate_error_code; 384 certificate_error_code_ = certificate_error_code;
384 385
385 SSLClientSocket::NextProto protocol = default_protocol_; 386 SSLClientSocket::NextProto protocol = default_protocol_;
386 if (is_secure_) { 387 if (is_secure_) {
387 SSLClientSocket* ssl_socket = GetSSLClientSocket(); 388 SSLClientSocket* ssl_socket = GetSSLClientSocket();
388 389
389 SSLClientSocket::NextProto protocol_negotiated = 390 SSLClientSocket::NextProto protocol_negotiated =
390 ssl_socket->protocol_negotiated(); 391 ssl_socket->protocol_negotiated();
391 if (protocol_negotiated != SSLClientSocket::kProtoUnknown) { 392 if (protocol_negotiated != SSLClientSocket::kProtoUnknown) {
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 return connection_->socket()->GetPeerAddress(address); 1170 return connection_->socket()->GetPeerAddress(address);
1170 } 1171 }
1171 1172
1172 int SpdySession::GetLocalAddress(IPEndPoint* address) const { 1173 int SpdySession::GetLocalAddress(IPEndPoint* address) const {
1173 if (!connection_->socket()) 1174 if (!connection_->socket())
1174 return ERR_SOCKET_NOT_CONNECTED; 1175 return ERR_SOCKET_NOT_CONNECTED;
1175 1176
1176 return connection_->socket()->GetLocalAddress(address); 1177 return connection_->socket()->GetLocalAddress(address);
1177 } 1178 }
1178 1179
1180 bool SpdySession::CloseOneIdleConnection() {
1181 if (spdy_session_pool_ && num_active_streams() == 0) {
1182 // Should delete this.
1183 RemoveFromPool();
1184 return true;
1185 }
1186 return false;
1187 }
1188
1179 void SpdySession::ActivateStream(SpdyStream* stream) { 1189 void SpdySession::ActivateStream(SpdyStream* stream) {
1180 const spdy::SpdyStreamId id = stream->stream_id(); 1190 const spdy::SpdyStreamId id = stream->stream_id();
1181 DCHECK(!IsStreamActive(id)); 1191 DCHECK(!IsStreamActive(id));
1182 1192
1183 active_streams_[id] = stream; 1193 active_streams_[id] = stream;
1184 } 1194 }
1185 1195
1186 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { 1196 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) {
1187 // For push streams, if they are being deleted normally, we leave 1197 // For push streams, if they are being deleted normally, we leave
1188 // the stream in the unclaimed_pushed_streams_ list. However, if 1198 // the stream in the unclaimed_pushed_streams_ list. However, if
(...skipping 14 matching lines...) Expand all
1203 ActiveStreamMap::iterator it2 = active_streams_.find(id); 1213 ActiveStreamMap::iterator it2 = active_streams_.find(id);
1204 if (it2 == active_streams_.end()) 1214 if (it2 == active_streams_.end())
1205 return; 1215 return;
1206 1216
1207 // If this is an active stream, call the callback. 1217 // If this is an active stream, call the callback.
1208 const scoped_refptr<SpdyStream> stream(it2->second); 1218 const scoped_refptr<SpdyStream> stream(it2->second);
1209 active_streams_.erase(it2); 1219 active_streams_.erase(it2);
1210 if (stream) 1220 if (stream)
1211 stream->OnClose(status); 1221 stream->OnClose(status);
1212 ProcessPendingCreateStreams(); 1222 ProcessPendingCreateStreams();
1223 if (num_active_streams() == 0 && connection_->is_initialized() &&
1224 connection_->IsPoolStalled()) {
mmenke 2012/03/16 18:01:15 Think we should have a test for this, or even land
Ryan Hamilton 2012/03/16 22:21:03 Removed for now.
1225 // Should delete this.
1226 RemoveFromPool();
1227 }
1213 } 1228 }
1214 1229
1215 void SpdySession::RemoveFromPool() { 1230 void SpdySession::RemoveFromPool() {
1216 if (spdy_session_pool_) { 1231 if (spdy_session_pool_) {
1217 SpdySessionPool* pool = spdy_session_pool_; 1232 SpdySessionPool* pool = spdy_session_pool_;
1218 spdy_session_pool_ = NULL; 1233 spdy_session_pool_ = NULL;
1219 pool->Remove(make_scoped_refptr(this)); 1234 pool->Remove(make_scoped_refptr(this));
1220 } 1235 }
1221 } 1236 }
1222 1237
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 SSLClientSocket* SpdySession::GetSSLClientSocket() const { 1956 SSLClientSocket* SpdySession::GetSSLClientSocket() const {
1942 if (!is_secure_) 1957 if (!is_secure_)
1943 return NULL; 1958 return NULL;
1944 SSLClientSocket* ssl_socket = 1959 SSLClientSocket* ssl_socket =
1945 reinterpret_cast<SSLClientSocket*>(connection_->socket()); 1960 reinterpret_cast<SSLClientSocket*>(connection_->socket());
1946 DCHECK(ssl_socket); 1961 DCHECK(ssl_socket);
1947 return ssl_socket; 1962 return ssl_socket;
1948 } 1963 }
1949 1964
1950 } // namespace net 1965 } // namespace net
OLDNEW
« net/socket/client_socket_pool_base.cc ('K') | « net/spdy/spdy_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698