| OLD | NEW |
| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 size_t max_concurrent_streams_limit, | 226 size_t max_concurrent_streams_limit, |
| 227 TimeFunc time_func, | 227 TimeFunc time_func, |
| 228 const HostPortPair& trusted_spdy_proxy, | 228 const HostPortPair& trusted_spdy_proxy, |
| 229 NetLog* net_log) | 229 NetLog* net_log) |
| 230 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 230 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 231 host_port_proxy_pair_(host_port_proxy_pair), | 231 host_port_proxy_pair_(host_port_proxy_pair), |
| 232 spdy_session_pool_(spdy_session_pool), | 232 spdy_session_pool_(spdy_session_pool), |
| 233 http_server_properties_(http_server_properties), | 233 http_server_properties_(http_server_properties), |
| 234 connection_(new ClientSocketHandle), | 234 connection_(new ClientSocketHandle), |
| 235 read_buffer_(new IOBuffer(kReadBufferSize)), | 235 read_buffer_(new IOBuffer(kReadBufferSize)), |
| 236 read_pending_(false), | |
| 237 stream_hi_water_mark_(kFirstStreamId), | 236 stream_hi_water_mark_(kFirstStreamId), |
| 238 write_pending_(false), | 237 write_pending_(false), |
| 239 delayed_write_pending_(false), | 238 delayed_write_pending_(false), |
| 240 is_secure_(false), | 239 is_secure_(false), |
| 241 certificate_error_code_(OK), | 240 certificate_error_code_(OK), |
| 242 error_(OK), | 241 error_(OK), |
| 243 state_(STATE_IDLE), | 242 state_(STATE_IDLE), |
| 244 max_concurrent_streams_(initial_max_concurrent_streams == 0 ? | 243 max_concurrent_streams_(initial_max_concurrent_streams == 0 ? |
| 245 kInitialMaxConcurrentStreams : | 244 kInitialMaxConcurrentStreams : |
| 246 initial_max_concurrent_streams), | 245 initial_max_concurrent_streams), |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 if (state_ == STATE_CONNECTING) | 774 if (state_ == STATE_CONNECTING) |
| 776 return connection_->GetLoadState(); | 775 return connection_->GetLoadState(); |
| 777 | 776 |
| 778 // Just report that we're idle since the session could be doing | 777 // Just report that we're idle since the session could be doing |
| 779 // many things concurrently. | 778 // many things concurrently. |
| 780 return LOAD_STATE_IDLE; | 779 return LOAD_STATE_IDLE; |
| 781 } | 780 } |
| 782 | 781 |
| 783 void SpdySession::OnReadComplete(int bytes_read) { | 782 void SpdySession::OnReadComplete(int bytes_read) { |
| 784 DCHECK_NE(state_, STATE_DO_READ); | 783 DCHECK_NE(state_, STATE_DO_READ); |
| 785 read_pending_ = false; | |
| 786 DoLoop(bytes_read); | 784 DoLoop(bytes_read); |
| 787 } | 785 } |
| 788 | 786 |
| 789 void SpdySession::StartRead() { | 787 void SpdySession::StartRead() { |
| 790 DCHECK_NE(state_, STATE_DO_READ_COMPLETE); | 788 DCHECK_NE(state_, STATE_DO_READ_COMPLETE); |
| 791 read_pending_ = false; | |
| 792 DoLoop(OK); | 789 DoLoop(OK); |
| 793 } | 790 } |
| 794 | 791 |
| 795 int SpdySession::DoLoop(int result) { | 792 int SpdySession::DoLoop(int result) { |
| 796 bytes_read_ = 0; | 793 bytes_read_ = 0; |
| 797 | 794 |
| 798 // The SpdyFramer will use callbacks onto |this| as it parses frames. | 795 // The SpdyFramer will use callbacks onto |this| as it parses frames. |
| 799 // When errors occur, those callbacks can lead to teardown of all references | 796 // When errors occur, those callbacks can lead to teardown of all references |
| 800 // to |this|, so maintain a reference to self during this call for safe | 797 // to |this|, so maintain a reference to self during this call for safe |
| 801 // cleanup. | 798 // cleanup. |
| 802 scoped_refptr<SpdySession> self(this); | 799 scoped_refptr<SpdySession> self(this); |
| 803 | 800 |
| 804 do { | 801 do { |
| 805 if (read_pending_) | |
| 806 return OK; | |
| 807 | |
| 808 switch (state_) { | 802 switch (state_) { |
| 809 case STATE_DO_READ: | 803 case STATE_DO_READ: |
| 810 DCHECK_EQ(result, OK); | 804 DCHECK_EQ(result, OK); |
| 811 result = DoRead(); | 805 result = DoRead(); |
| 812 break; | 806 break; |
| 813 case STATE_DO_READ_COMPLETE: | 807 case STATE_DO_READ_COMPLETE: |
| 814 result = DoReadComplete(result); | 808 result = DoReadComplete(result); |
| 815 break; | 809 break; |
| 816 case STATE_CLOSED: | 810 case STATE_CLOSED: |
| 817 result = ERR_CONNECTION_CLOSED; | 811 result = ERR_CONNECTION_CLOSED; |
| 818 break; | 812 break; |
| 819 default: | 813 default: |
| 820 NOTREACHED() << "state_: " << state_; | 814 NOTREACHED() << "state_: " << state_; |
| 821 break; | 815 break; |
| 822 } | 816 } |
| 823 } while (result != ERR_IO_PENDING && result != ERR_CONNECTION_CLOSED); | 817 } while (result != ERR_IO_PENDING && result != ERR_CONNECTION_CLOSED); |
| 824 | 818 |
| 825 return result; | 819 return result; |
| 826 } | 820 } |
| 827 | 821 |
| 828 int SpdySession::DoRead() { | 822 int SpdySession::DoRead() { |
| 829 DCHECK(!read_pending_); | |
| 830 if (bytes_read_ > kMaxReadBytes) { | 823 if (bytes_read_ > kMaxReadBytes) { |
| 831 state_ = STATE_DO_READ; | 824 state_ = STATE_DO_READ; |
| 832 MessageLoop::current()->PostTask( | 825 MessageLoop::current()->PostTask( |
| 833 FROM_HERE, | 826 FROM_HERE, |
| 834 base::Bind(&SpdySession::StartRead, | 827 base::Bind(&SpdySession::StartRead, |
| 835 weak_factory_.GetWeakPtr())); | 828 weak_factory_.GetWeakPtr())); |
| 836 return ERR_IO_PENDING; | 829 return ERR_IO_PENDING; |
| 837 } | 830 } |
| 838 | 831 |
| 839 CHECK(connection_.get()); | 832 CHECK(connection_.get()); |
| 840 CHECK(connection_->socket()); | 833 CHECK(connection_->socket()); |
| 841 state_ = STATE_DO_READ_COMPLETE; | 834 state_ = STATE_DO_READ_COMPLETE; |
| 842 int result = connection_->socket()->Read( | 835 return connection_->socket()->Read( |
| 843 read_buffer_.get(), | 836 read_buffer_.get(), |
| 844 kReadBufferSize, | 837 kReadBufferSize, |
| 845 base::Bind(&SpdySession::OnReadComplete, base::Unretained(this))); | 838 base::Bind(&SpdySession::OnReadComplete, base::Unretained(this))); |
| 846 if (result == net::ERR_IO_PENDING) | |
| 847 read_pending_ = true; | |
| 848 return result; | |
| 849 } | 839 } |
| 850 | 840 |
| 851 int SpdySession::DoReadComplete(int result) { | 841 int SpdySession::DoReadComplete(int result) { |
| 852 // Parse a frame. For now this code requires that the frame fit into our | 842 // Parse a frame. For now this code requires that the frame fit into our |
| 853 // buffer (32KB). | 843 // buffer (32KB). |
| 854 // TODO(mbelshe): support arbitrarily large frames! | 844 // TODO(mbelshe): support arbitrarily large frames! |
| 855 | 845 |
| 856 DCHECK(!read_pending_); | |
| 857 | |
| 858 if (result <= 0) { | 846 if (result <= 0) { |
| 859 // Session is tearing down. | 847 // Session is tearing down. |
| 860 net::Error error = static_cast<net::Error>(result); | 848 net::Error error = static_cast<net::Error>(result); |
| 861 if (result == 0) | 849 if (result == 0) |
| 862 error = ERR_CONNECTION_CLOSED; | 850 error = ERR_CONNECTION_CLOSED; |
| 863 CloseSessionOnError(error, true, "result is <= 0."); | 851 CloseSessionOnError(error, true, "result is <= 0."); |
| 864 return ERR_CONNECTION_CLOSED; | 852 return ERR_CONNECTION_CLOSED; |
| 865 } | 853 } |
| 866 | 854 |
| 867 total_bytes_received_ += result; | 855 total_bytes_received_ += result; |
| (...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1998 SSLClientSocket* SpdySession::GetSSLClientSocket() const { | 1986 SSLClientSocket* SpdySession::GetSSLClientSocket() const { |
| 1999 if (!is_secure_) | 1987 if (!is_secure_) |
| 2000 return NULL; | 1988 return NULL; |
| 2001 SSLClientSocket* ssl_socket = | 1989 SSLClientSocket* ssl_socket = |
| 2002 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 1990 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
| 2003 DCHECK(ssl_socket); | 1991 DCHECK(ssl_socket); |
| 2004 return ssl_socket; | 1992 return ssl_socket; |
| 2005 } | 1993 } |
| 2006 | 1994 |
| 2007 } // namespace net | 1995 } // namespace net |
| OLD | NEW |