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

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

Issue 367963003: Separate client and server pushed streams limits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 size_t max_concurrent_streams_limit, 542 size_t max_concurrent_streams_limit,
543 TimeFunc time_func, 543 TimeFunc time_func,
544 const HostPortPair& trusted_spdy_proxy, 544 const HostPortPair& trusted_spdy_proxy,
545 NetLog* net_log) 545 NetLog* net_log)
546 : in_io_loop_(false), 546 : in_io_loop_(false),
547 spdy_session_key_(spdy_session_key), 547 spdy_session_key_(spdy_session_key),
548 pool_(NULL), 548 pool_(NULL),
549 http_server_properties_(http_server_properties), 549 http_server_properties_(http_server_properties),
550 read_buffer_(new IOBuffer(kReadBufferSize)), 550 read_buffer_(new IOBuffer(kReadBufferSize)),
551 stream_hi_water_mark_(kFirstStreamId), 551 stream_hi_water_mark_(kFirstStreamId),
552 num_pushed_streams_(0u),
553 num_active_pushed_streams_(0u),
552 in_flight_write_frame_type_(DATA), 554 in_flight_write_frame_type_(DATA),
553 in_flight_write_frame_size_(0), 555 in_flight_write_frame_size_(0),
554 is_secure_(false), 556 is_secure_(false),
555 certificate_error_code_(OK), 557 certificate_error_code_(OK),
556 availability_state_(STATE_AVAILABLE), 558 availability_state_(STATE_AVAILABLE),
557 read_state_(READ_STATE_DO_READ), 559 read_state_(READ_STATE_DO_READ),
558 write_state_(WRITE_STATE_IDLE), 560 write_state_(WRITE_STATE_IDLE),
559 error_on_close_(OK), 561 error_on_close_(OK),
560 max_concurrent_streams_(initial_max_concurrent_streams == 0 562 max_concurrent_streams_(initial_max_concurrent_streams == 0
561 ? kInitialMaxConcurrentStreams 563 ? kInitialMaxConcurrentStreams
562 : initial_max_concurrent_streams), 564 : initial_max_concurrent_streams),
563 max_concurrent_streams_limit_(max_concurrent_streams_limit == 0 565 max_concurrent_streams_limit_(max_concurrent_streams_limit == 0
564 ? kMaxConcurrentStreamLimit 566 ? kMaxConcurrentStreamLimit
565 : max_concurrent_streams_limit), 567 : max_concurrent_streams_limit),
568 max_concurrent_pushed_streams_(kMaxConcurrentPushedStreams),
566 streams_initiated_count_(0), 569 streams_initiated_count_(0),
567 streams_pushed_count_(0), 570 streams_pushed_count_(0),
568 streams_pushed_and_claimed_count_(0), 571 streams_pushed_and_claimed_count_(0),
569 streams_abandoned_count_(0), 572 streams_abandoned_count_(0),
570 total_bytes_received_(0), 573 total_bytes_received_(0),
571 sent_settings_(false), 574 sent_settings_(false),
572 received_settings_(false), 575 received_settings_(false),
573 stalled_streams_(0), 576 stalled_streams_(0),
574 pings_in_flight_(0), 577 pings_in_flight_(0),
575 next_ping_id_(1), 578 next_ping_id_(1),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 return ERR_FAILED; 773 return ERR_FAILED;
771 774
772 if (availability_state_ == STATE_DRAINING) 775 if (availability_state_ == STATE_DRAINING)
773 return ERR_CONNECTION_CLOSED; 776 return ERR_CONNECTION_CLOSED;
774 777
775 Error err = TryAccessStream(request->url()); 778 Error err = TryAccessStream(request->url());
776 if (err != OK) 779 if (err != OK)
777 return err; 780 return err;
778 781
779 if (!max_concurrent_streams_ || 782 if (!max_concurrent_streams_ ||
780 (active_streams_.size() + created_streams_.size() < 783 (active_streams_.size() + created_streams_.size() - num_pushed_streams_ <
781 max_concurrent_streams_)) { 784 max_concurrent_streams_)) {
782 return CreateStream(*request, stream); 785 return CreateStream(*request, stream);
783 } 786 }
784 787
785 stalled_streams_++; 788 stalled_streams_++;
786 net_log().AddEvent(NetLog::TYPE_SPDY_SESSION_STALLED_MAX_STREAMS); 789 net_log().AddEvent(NetLog::TYPE_SPDY_SESSION_STALLED_MAX_STREAMS);
787 RequestPriority priority = request->priority(); 790 RequestPriority priority = request->priority();
788 CHECK_GE(priority, MINIMUM_PRIORITY); 791 CHECK_GE(priority, MINIMUM_PRIORITY);
789 CHECK_LE(priority, MAXIMUM_PRIORITY); 792 CHECK_LE(priority, MAXIMUM_PRIORITY);
790 pending_create_stream_queues_[priority].push_back(request); 793 pending_create_stream_queues_[priority].push_back(request);
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 scoped_ptr<SpdyStream> owned_stream(it->second.stream); 1214 scoped_ptr<SpdyStream> owned_stream(it->second.stream);
1212 active_streams_.erase(it); 1215 active_streams_.erase(it);
1213 1216
1214 // TODO(akalin): When SpdyStream was ref-counted (and 1217 // TODO(akalin): When SpdyStream was ref-counted (and
1215 // |unclaimed_pushed_streams_| held scoped_refptr<SpdyStream>), this 1218 // |unclaimed_pushed_streams_| held scoped_refptr<SpdyStream>), this
1216 // was only done when status was not OK. This meant that pushed 1219 // was only done when status was not OK. This meant that pushed
1217 // streams can still be claimed after they're closed. This is 1220 // streams can still be claimed after they're closed. This is
1218 // probably something that we still want to support, although server 1221 // probably something that we still want to support, although server
1219 // push is hardly used. Write tests for this and fix this. (See 1222 // push is hardly used. Write tests for this and fix this. (See
1220 // http://crbug.com/261712 .) 1223 // http://crbug.com/261712 .)
1221 if (owned_stream->type() == SPDY_PUSH_STREAM) 1224 if (owned_stream->type() == SPDY_PUSH_STREAM) {
1222 unclaimed_pushed_streams_.erase(owned_stream->url()); 1225 unclaimed_pushed_streams_.erase(owned_stream->url());
1226 num_pushed_streams_--;
1227 if (!owned_stream->IsReservedRemote())
1228 num_active_pushed_streams_--;
1229 }
1223 1230
1224 DeleteStream(owned_stream.Pass(), status); 1231 DeleteStream(owned_stream.Pass(), status);
1225 MaybeFinishGoingAway(); 1232 MaybeFinishGoingAway();
1226 1233
1227 // If there are no active streams and the socket pool is stalled, close the 1234 // If there are no active streams and the socket pool is stalled, close the
1228 // session to free up a socket slot. 1235 // session to free up a socket slot.
1229 if (active_streams_.empty() && connection_->IsPoolStalled()) { 1236 if (active_streams_.empty() && connection_->IsPoolStalled()) {
1230 DoDrainSession(ERR_CONNECTION_CLOSED, "Closing idle connection."); 1237 DoDrainSession(ERR_CONNECTION_CLOSED, "Closing idle connection.");
1231 } 1238 }
1232 } 1239 }
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 last_compressed_frame_len_ = frame_len; 2095 last_compressed_frame_len_ = frame_len;
2089 } 2096 }
2090 2097
2091 int SpdySession::OnInitialResponseHeadersReceived( 2098 int SpdySession::OnInitialResponseHeadersReceived(
2092 const SpdyHeaderBlock& response_headers, 2099 const SpdyHeaderBlock& response_headers,
2093 base::Time response_time, 2100 base::Time response_time,
2094 base::TimeTicks recv_first_byte_time, 2101 base::TimeTicks recv_first_byte_time,
2095 SpdyStream* stream) { 2102 SpdyStream* stream) {
2096 CHECK(in_io_loop_); 2103 CHECK(in_io_loop_);
2097 SpdyStreamId stream_id = stream->stream_id(); 2104 SpdyStreamId stream_id = stream->stream_id();
2105
2106 if (stream->type() == SPDY_PUSH_STREAM) {
2107 DCHECK(stream->IsReservedRemote());
2108 if (max_concurrent_pushed_streams_ &&
2109 num_active_pushed_streams_ >= max_concurrent_pushed_streams_) {
2110 ResetStream(stream_id,
2111 RST_STREAM_REFUSED_STREAM,
2112 "Stream concurrency limit reached.");
2113 return STATUS_CODE_REFUSED_STREAM;
2114 }
2115 }
2116
2098 // May invalidate |stream|. 2117 // May invalidate |stream|.
2099 int rv = stream->OnInitialResponseHeadersReceived( 2118 int rv = stream->OnInitialResponseHeadersReceived(
2100 response_headers, response_time, recv_first_byte_time); 2119 response_headers, response_time, recv_first_byte_time);
2101 if (rv < 0) { 2120 if (rv < 0) {
2102 DCHECK_NE(rv, ERR_IO_PENDING); 2121 DCHECK_NE(rv, ERR_IO_PENDING);
2103 DCHECK(active_streams_.find(stream_id) == active_streams_.end()); 2122 DCHECK(active_streams_.find(stream_id) == active_streams_.end());
2104 } 2123 }
2124
2125 if (stream->type() == SPDY_PUSH_STREAM) {
2126 DCHECK(stream->IsLocallyClosed());
2127 num_active_pushed_streams_++;
2128 }
2129
2105 return rv; 2130 return rv;
2106 } 2131 }
2107 2132
2108 void SpdySession::OnSynStream(SpdyStreamId stream_id, 2133 void SpdySession::OnSynStream(SpdyStreamId stream_id,
2109 SpdyStreamId associated_stream_id, 2134 SpdyStreamId associated_stream_id,
2110 SpdyPriority priority, 2135 SpdyPriority priority,
2111 bool fin, 2136 bool fin,
2112 bool unidirectional, 2137 bool unidirectional,
2113 const SpdyHeaderBlock& headers) { 2138 const SpdyHeaderBlock& headers) {
2114 CHECK(in_io_loop_); 2139 CHECK(in_io_loop_);
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 InsertActivatedStream(stream.Pass()); 2602 InsertActivatedStream(stream.Pass());
2578 2603
2579 ActiveStreamMap::iterator active_it = active_streams_.find(stream_id); 2604 ActiveStreamMap::iterator active_it = active_streams_.find(stream_id);
2580 if (active_it == active_streams_.end()) { 2605 if (active_it == active_streams_.end()) {
2581 NOTREACHED(); 2606 NOTREACHED();
2582 return false; 2607 return false;
2583 } 2608 }
2584 2609
2585 active_it->second.stream->OnPushPromiseHeadersReceived(headers); 2610 active_it->second.stream->OnPushPromiseHeadersReceived(headers);
2586 DCHECK(active_it->second.stream->IsReservedRemote()); 2611 DCHECK(active_it->second.stream->IsReservedRemote());
2612 num_pushed_streams_++;
2587 return true; 2613 return true;
2588 } 2614 }
2589 2615
2590 void SpdySession::OnPushPromise(SpdyStreamId stream_id, 2616 void SpdySession::OnPushPromise(SpdyStreamId stream_id,
2591 SpdyStreamId promised_stream_id, 2617 SpdyStreamId promised_stream_id,
2592 const SpdyHeaderBlock& headers) { 2618 const SpdyHeaderBlock& headers) {
2593 CHECK(in_io_loop_); 2619 CHECK(in_io_loop_);
2594 2620
2595 if (net_log_.IsLogging()) { 2621 if (net_log_.IsLogging()) {
2596 net_log_.AddEvent(NetLog::TYPE_SPDY_SESSION_RECV_PUSH_PROMISE, 2622 net_log_.AddEvent(NetLog::TYPE_SPDY_SESSION_RECV_PUSH_PROMISE,
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
3133 if (!queue->empty()) { 3159 if (!queue->empty()) {
3134 SpdyStreamId stream_id = queue->front(); 3160 SpdyStreamId stream_id = queue->front();
3135 queue->pop_front(); 3161 queue->pop_front();
3136 return stream_id; 3162 return stream_id;
3137 } 3163 }
3138 } 3164 }
3139 return 0; 3165 return 0;
3140 } 3166 }
3141 3167
3142 } // namespace net 3168 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698