OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 | 324 |
325 net::Error SpdySession::InitializeWithSocket( | 325 net::Error SpdySession::InitializeWithSocket( |
326 ClientSocketHandle* connection, | 326 ClientSocketHandle* connection, |
327 bool is_secure, | 327 bool is_secure, |
328 int certificate_error_code) { | 328 int certificate_error_code) { |
329 base::StatsCounter spdy_sessions("spdy.sessions"); | 329 base::StatsCounter spdy_sessions("spdy.sessions"); |
330 spdy_sessions.Increment(); | 330 spdy_sessions.Increment(); |
331 | 331 |
332 state_ = CONNECTED; | 332 state_ = CONNECTED; |
333 connection_.reset(connection); | 333 connection_.reset(connection); |
334 connection_->AddLayeredPool(this); | |
334 is_secure_ = is_secure; | 335 is_secure_ = is_secure; |
335 certificate_error_code_ = certificate_error_code; | 336 certificate_error_code_ = certificate_error_code; |
336 | 337 |
337 // Write out any data that we might have to send, such as the settings frame. | 338 // Write out any data that we might have to send, such as the settings frame. |
338 WriteSocketLater(); | 339 WriteSocketLater(); |
339 net::Error error = ReadSocket(); | 340 net::Error error = ReadSocket(); |
340 if (error == ERR_IO_PENDING) | 341 if (error == ERR_IO_PENDING) |
341 return OK; | 342 return OK; |
342 return error; | 343 return error; |
343 } | 344 } |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
960 return connection_->socket()->GetPeerAddress(address); | 961 return connection_->socket()->GetPeerAddress(address); |
961 } | 962 } |
962 | 963 |
963 int SpdySession::GetLocalAddress(IPEndPoint* address) const { | 964 int SpdySession::GetLocalAddress(IPEndPoint* address) const { |
964 if (!connection_->socket()) | 965 if (!connection_->socket()) |
965 return ERR_SOCKET_NOT_CONNECTED; | 966 return ERR_SOCKET_NOT_CONNECTED; |
966 | 967 |
967 return connection_->socket()->GetLocalAddress(address); | 968 return connection_->socket()->GetLocalAddress(address); |
968 } | 969 } |
969 | 970 |
971 bool SpdySession::CloseOneIdleConnection() { | |
972 if (num_active_streams() == 0) { | |
973 // Should delete this. | |
974 RemoveFromPool(); | |
mmenke
2011/10/27 18:52:37
Is this safe? It looks to me like there may be no
willchan no longer on Chromium
2011/11/08 22:26:13
I'm not sure I understand the worry. When we call
mmenke
2011/11/08 22:41:04
We don't dereference |this|, but RemoveFromPool do
willchan no longer on Chromium
2011/11/15 18:44:06
Again, great catch. I've fixed this.
| |
975 return true; | |
976 } | |
977 return false; | |
978 } | |
979 | |
970 void SpdySession::ActivateStream(SpdyStream* stream) { | 980 void SpdySession::ActivateStream(SpdyStream* stream) { |
971 const spdy::SpdyStreamId id = stream->stream_id(); | 981 const spdy::SpdyStreamId id = stream->stream_id(); |
972 DCHECK(!IsStreamActive(id)); | 982 DCHECK(!IsStreamActive(id)); |
973 | 983 |
974 active_streams_[id] = stream; | 984 active_streams_[id] = stream; |
975 } | 985 } |
976 | 986 |
977 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { | 987 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { |
978 // For push streams, if they are being deleted normally, we leave | 988 // For push streams, if they are being deleted normally, we leave |
979 // the stream in the unclaimed_pushed_streams_ list. However, if | 989 // the stream in the unclaimed_pushed_streams_ list. However, if |
(...skipping 14 matching lines...) Expand all Loading... | |
994 ActiveStreamMap::iterator it2 = active_streams_.find(id); | 1004 ActiveStreamMap::iterator it2 = active_streams_.find(id); |
995 if (it2 == active_streams_.end()) | 1005 if (it2 == active_streams_.end()) |
996 return; | 1006 return; |
997 | 1007 |
998 // If this is an active stream, call the callback. | 1008 // If this is an active stream, call the callback. |
999 const scoped_refptr<SpdyStream> stream(it2->second); | 1009 const scoped_refptr<SpdyStream> stream(it2->second); |
1000 active_streams_.erase(it2); | 1010 active_streams_.erase(it2); |
1001 if (stream) | 1011 if (stream) |
1002 stream->OnClose(status); | 1012 stream->OnClose(status); |
1003 ProcessPendingCreateStreams(); | 1013 ProcessPendingCreateStreams(); |
1014 if (num_active_streams() == 0 && connection_->IsPoolStalled()) { | |
1015 // Should delete this. | |
1016 RemoveFromPool(); | |
1017 } | |
1004 } | 1018 } |
1005 | 1019 |
1006 void SpdySession::RemoveFromPool() { | 1020 void SpdySession::RemoveFromPool() { |
1007 if (spdy_session_pool_) { | 1021 if (spdy_session_pool_) { |
1008 spdy_session_pool_->Remove(make_scoped_refptr(this)); | 1022 spdy_session_pool_->Remove(make_scoped_refptr(this)); |
1009 spdy_session_pool_ = NULL; | 1023 spdy_session_pool_ = NULL; |
1010 } | 1024 } |
1011 } | 1025 } |
1012 | 1026 |
1013 scoped_refptr<SpdyStream> SpdySession::GetActivePushStream( | 1027 scoped_refptr<SpdyStream> SpdySession::GetActivePushStream( |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1720 if (it == pending_callback_map_.end()) | 1734 if (it == pending_callback_map_.end()) |
1721 return; | 1735 return; |
1722 | 1736 |
1723 OldCompletionCallback* callback = it->second.callback; | 1737 OldCompletionCallback* callback = it->second.callback; |
1724 int result = it->second.result; | 1738 int result = it->second.result; |
1725 pending_callback_map_.erase(it); | 1739 pending_callback_map_.erase(it); |
1726 callback->Run(result); | 1740 callback->Run(result); |
1727 } | 1741 } |
1728 | 1742 |
1729 } // namespace net | 1743 } // namespace net |
OLD | NEW |