| 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), |
| 236 stream_hi_water_mark_(kFirstStreamId), | 237 stream_hi_water_mark_(kFirstStreamId), |
| 237 write_pending_(false), | 238 write_pending_(false), |
| 238 delayed_write_pending_(false), | 239 delayed_write_pending_(false), |
| 239 is_secure_(false), | 240 is_secure_(false), |
| 240 certificate_error_code_(OK), | 241 certificate_error_code_(OK), |
| 241 error_(OK), | 242 error_(OK), |
| 242 state_(STATE_IDLE), | 243 state_(STATE_IDLE), |
| 243 max_concurrent_streams_(initial_max_concurrent_streams == 0 ? | 244 max_concurrent_streams_(initial_max_concurrent_streams == 0 ? |
| 244 kInitialMaxConcurrentStreams : | 245 kInitialMaxConcurrentStreams : |
| 245 initial_max_concurrent_streams), | 246 initial_max_concurrent_streams), |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 if (state_ == STATE_CONNECTING) | 775 if (state_ == STATE_CONNECTING) |
| 775 return connection_->GetLoadState(); | 776 return connection_->GetLoadState(); |
| 776 | 777 |
| 777 // Just report that we're idle since the session could be doing | 778 // Just report that we're idle since the session could be doing |
| 778 // many things concurrently. | 779 // many things concurrently. |
| 779 return LOAD_STATE_IDLE; | 780 return LOAD_STATE_IDLE; |
| 780 } | 781 } |
| 781 | 782 |
| 782 void SpdySession::OnReadComplete(int bytes_read) { | 783 void SpdySession::OnReadComplete(int bytes_read) { |
| 783 DCHECK_NE(state_, STATE_DO_READ); | 784 DCHECK_NE(state_, STATE_DO_READ); |
| 785 read_pending_ = false; |
| 784 DoLoop(bytes_read); | 786 DoLoop(bytes_read); |
| 785 } | 787 } |
| 786 | 788 |
| 787 void SpdySession::StartRead() { | 789 void SpdySession::StartRead() { |
| 788 DCHECK_NE(state_, STATE_DO_READ_COMPLETE); | 790 DCHECK_NE(state_, STATE_DO_READ_COMPLETE); |
| 791 read_pending_ = false; |
| 789 DoLoop(OK); | 792 DoLoop(OK); |
| 790 } | 793 } |
| 791 | 794 |
| 792 int SpdySession::DoLoop(int result) { | 795 int SpdySession::DoLoop(int result) { |
| 793 bytes_read_ = 0; | 796 bytes_read_ = 0; |
| 794 do { | 797 do { |
| 798 if (read_pending_) |
| 799 return OK; |
| 800 |
| 795 switch (state_) { | 801 switch (state_) { |
| 796 case STATE_DO_READ: | 802 case STATE_DO_READ: |
| 797 DCHECK_EQ(result, OK); | 803 DCHECK_EQ(result, OK); |
| 798 result = DoRead(); | 804 result = DoRead(); |
| 799 break; | 805 break; |
| 800 case STATE_DO_READ_COMPLETE: | 806 case STATE_DO_READ_COMPLETE: |
| 801 result = DoReadComplete(result); | 807 result = DoReadComplete(result); |
| 802 break; | 808 break; |
| 803 case STATE_CLOSED: | 809 case STATE_CLOSED: |
| 804 result = ERR_CONNECTION_CLOSED; | 810 result = ERR_CONNECTION_CLOSED; |
| 805 break; | 811 break; |
| 806 default: | 812 default: |
| 807 NOTREACHED() << "state_: " << state_; | 813 NOTREACHED() << "state_: " << state_; |
| 808 break; | 814 break; |
| 809 } | 815 } |
| 810 } while (result != ERR_IO_PENDING && result != ERR_CONNECTION_CLOSED); | 816 } while (result != ERR_IO_PENDING && result != ERR_CONNECTION_CLOSED); |
| 811 | 817 |
| 812 return result; | 818 return result; |
| 813 } | 819 } |
| 814 | 820 |
| 815 int SpdySession::DoRead() { | 821 int SpdySession::DoRead() { |
| 822 DCHECK(!read_pending_); |
| 816 if (bytes_read_ > kMaxReadBytes) { | 823 if (bytes_read_ > kMaxReadBytes) { |
| 817 state_ = STATE_DO_READ; | 824 state_ = STATE_DO_READ; |
| 818 MessageLoop::current()->PostTask( | 825 MessageLoop::current()->PostTask( |
| 819 FROM_HERE, | 826 FROM_HERE, |
| 820 base::Bind(&SpdySession::StartRead, | 827 base::Bind(&SpdySession::StartRead, |
| 821 weak_factory_.GetWeakPtr())); | 828 weak_factory_.GetWeakPtr())); |
| 822 return ERR_IO_PENDING; | 829 return ERR_IO_PENDING; |
| 823 } | 830 } |
| 824 | 831 |
| 825 CHECK(connection_.get()); | 832 CHECK(connection_.get()); |
| 826 CHECK(connection_->socket()); | 833 CHECK(connection_->socket()); |
| 827 state_ = STATE_DO_READ_COMPLETE; | 834 state_ = STATE_DO_READ_COMPLETE; |
| 828 return connection_->socket()->Read( | 835 int result = connection_->socket()->Read( |
| 829 read_buffer_.get(), | 836 read_buffer_.get(), |
| 830 kReadBufferSize, | 837 kReadBufferSize, |
| 831 base::Bind(&SpdySession::OnReadComplete, base::Unretained(this))); | 838 base::Bind(&SpdySession::OnReadComplete, base::Unretained(this))); |
| 839 if (result == net::ERR_IO_PENDING) |
| 840 read_pending_ = true; |
| 841 return result; |
| 832 } | 842 } |
| 833 | 843 |
| 834 int SpdySession::DoReadComplete(int result) { | 844 int SpdySession::DoReadComplete(int result) { |
| 835 // Parse a frame. For now this code requires that the frame fit into our | 845 // Parse a frame. For now this code requires that the frame fit into our |
| 836 // buffer (32KB). | 846 // buffer (32KB). |
| 837 // TODO(mbelshe): support arbitrarily large frames! | 847 // TODO(mbelshe): support arbitrarily large frames! |
| 838 | 848 |
| 849 DCHECK(!read_pending_); |
| 850 |
| 839 if (result <= 0) { | 851 if (result <= 0) { |
| 840 // Session is tearing down. | 852 // Session is tearing down. |
| 841 net::Error error = static_cast<net::Error>(result); | 853 net::Error error = static_cast<net::Error>(result); |
| 842 if (result == 0) | 854 if (result == 0) |
| 843 error = ERR_CONNECTION_CLOSED; | 855 error = ERR_CONNECTION_CLOSED; |
| 844 CloseSessionOnError(error, true, "result is <= 0."); | 856 CloseSessionOnError(error, true, "result is <= 0."); |
| 845 return ERR_CONNECTION_CLOSED; | 857 return ERR_CONNECTION_CLOSED; |
| 846 } | 858 } |
| 847 | 859 |
| 848 total_bytes_received_ += result; | 860 total_bytes_received_ += result; |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1984 SSLClientSocket* SpdySession::GetSSLClientSocket() const { | 1996 SSLClientSocket* SpdySession::GetSSLClientSocket() const { |
| 1985 if (!is_secure_) | 1997 if (!is_secure_) |
| 1986 return NULL; | 1998 return NULL; |
| 1987 SSLClientSocket* ssl_socket = | 1999 SSLClientSocket* ssl_socket = |
| 1988 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 2000 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
| 1989 DCHECK(ssl_socket); | 2001 DCHECK(ssl_socket); |
| 1990 return ssl_socket; | 2002 return ssl_socket; |
| 1991 } | 2003 } |
| 1992 | 2004 |
| 1993 } // namespace net | 2005 } // namespace net |
| OLD | NEW |