| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 if (availability_state_ == STATE_GOING_AWAY) | 877 if (availability_state_ == STATE_GOING_AWAY) |
| 878 return ERR_FAILED; | 878 return ERR_FAILED; |
| 879 | 879 |
| 880 if (availability_state_ == STATE_DRAINING) | 880 if (availability_state_ == STATE_DRAINING) |
| 881 return ERR_CONNECTION_CLOSED; | 881 return ERR_CONNECTION_CLOSED; |
| 882 | 882 |
| 883 Error err = TryAccessStream(request->url()); | 883 Error err = TryAccessStream(request->url()); |
| 884 if (err != OK) | 884 if (err != OK) |
| 885 return err; | 885 return err; |
| 886 | 886 |
| 887 if (!max_concurrent_streams_ || | 887 if ((active_streams_.size() + created_streams_.size() - num_pushed_streams_ < |
| 888 (active_streams_.size() + created_streams_.size() - num_pushed_streams_ < | |
| 889 max_concurrent_streams_)) { | 888 max_concurrent_streams_)) { |
| 890 return CreateStream(*request, stream); | 889 return CreateStream(*request, stream); |
| 891 } | 890 } |
| 892 | 891 |
| 893 stalled_streams_++; | 892 stalled_streams_++; |
| 894 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_STALLED_MAX_STREAMS); | 893 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_STALLED_MAX_STREAMS); |
| 895 RequestPriority priority = request->priority(); | 894 RequestPriority priority = request->priority(); |
| 896 CHECK_GE(priority, MINIMUM_PRIORITY); | 895 CHECK_GE(priority, MINIMUM_PRIORITY); |
| 897 CHECK_LE(priority, MAXIMUM_PRIORITY); | 896 CHECK_LE(priority, MAXIMUM_PRIORITY); |
| 898 pending_create_stream_queues_[priority].push_back(request); | 897 pending_create_stream_queues_[priority].push_back(request); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 base::WeakPtr<SpdyStreamRequest> pending_request = | 984 base::WeakPtr<SpdyStreamRequest> pending_request = |
| 986 pending_create_stream_queues_[j].front(); | 985 pending_create_stream_queues_[j].front(); |
| 987 DCHECK(pending_request); | 986 DCHECK(pending_request); |
| 988 pending_create_stream_queues_[j].pop_front(); | 987 pending_create_stream_queues_[j].pop_front(); |
| 989 return pending_request; | 988 return pending_request; |
| 990 } | 989 } |
| 991 return base::WeakPtr<SpdyStreamRequest>(); | 990 return base::WeakPtr<SpdyStreamRequest>(); |
| 992 } | 991 } |
| 993 | 992 |
| 994 void SpdySession::ProcessPendingStreamRequests() { | 993 void SpdySession::ProcessPendingStreamRequests() { |
| 995 // Like |max_concurrent_streams_|, 0 means infinite for | 994 size_t max_requests_to_process = |
| 996 // |max_requests_to_process|. | 995 max_concurrent_streams_ - |
| 997 size_t max_requests_to_process = 0; | 996 (active_streams_.size() + created_streams_.size()); |
| 998 if (max_concurrent_streams_ != 0) { | 997 for (size_t i = 0; i < max_requests_to_process; ++i) { |
| 999 max_requests_to_process = | |
| 1000 max_concurrent_streams_ - | |
| 1001 (active_streams_.size() + created_streams_.size()); | |
| 1002 } | |
| 1003 for (size_t i = 0; | |
| 1004 max_requests_to_process == 0 || i < max_requests_to_process; ++i) { | |
| 1005 base::WeakPtr<SpdyStreamRequest> pending_request = | 998 base::WeakPtr<SpdyStreamRequest> pending_request = |
| 1006 GetNextPendingStreamRequest(); | 999 GetNextPendingStreamRequest(); |
| 1007 if (!pending_request) | 1000 if (!pending_request) |
| 1008 break; | 1001 break; |
| 1009 | 1002 |
| 1010 // Note that this post can race with other stream creations, and it's | 1003 // Note that this post can race with other stream creations, and it's |
| 1011 // possible that the un-stalled stream will be stalled again if it loses. | 1004 // possible that the un-stalled stream will be stalled again if it loses. |
| 1012 // TODO(jgraettinger): Provide stronger ordering guarantees. | 1005 // TODO(jgraettinger): Provide stronger ordering guarantees. |
| 1013 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1006 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1014 FROM_HERE, base::Bind(&SpdySession::CompleteStreamRequest, | 1007 FROM_HERE, base::Bind(&SpdySession::CompleteStreamRequest, |
| (...skipping 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3280 if (!queue->empty()) { | 3273 if (!queue->empty()) { |
| 3281 SpdyStreamId stream_id = queue->front(); | 3274 SpdyStreamId stream_id = queue->front(); |
| 3282 queue->pop_front(); | 3275 queue->pop_front(); |
| 3283 return stream_id; | 3276 return stream_id; |
| 3284 } | 3277 } |
| 3285 } | 3278 } |
| 3286 return 0; | 3279 return 0; |
| 3287 } | 3280 } |
| 3288 | 3281 |
| 3289 } // namespace net | 3282 } // namespace net |
| OLD | NEW |