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

Side by Side Diff: net/quic/quic_session.cc

Issue 11661002: Move VisitorShim from QuicServerSession to QuicSession. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 12 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_session.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/quic/quic_session.h" 5 #include "net/quic/quic_session.h"
6 6
7 #include "base/stl_util.h"
7 #include "net/quic/quic_connection.h" 8 #include "net/quic/quic_connection.h"
8 9
9 using base::StringPiece; 10 using base::StringPiece;
10 using base::hash_map; 11 using base::hash_map;
11 using base::hash_set; 12 using base::hash_set;
12 using std::vector; 13 using std::vector;
13 14
14 namespace net { 15 namespace net {
15 16
17 // We want to make sure we delete any closed streams in a safe manner.
18 // To avoid deleting a stream in mid-operation, we have a simple shim between
19 // us and the stream, so we can delete any streams when we return from
20 // processing.
21 //
22 // We could just override the base methods, but this makes it easier to make
23 // sure we don't miss any.
24 class VisitorShim : public QuicConnectionVisitorInterface {
25 public:
26 explicit VisitorShim(QuicSession* session) : session_(session) {}
27
28 virtual bool OnPacket(const IPEndPoint& self_address,
29 const IPEndPoint& peer_address,
30 const QuicPacketHeader& header,
31 const vector<QuicStreamFrame>& frame) {
32 bool accepted = session_->OnPacket(self_address, peer_address, header,
33 frame);
34 session_->PostProcessAfterData();
35 return accepted;
36 }
37 virtual void OnRstStream(const QuicRstStreamFrame& frame) {
38 session_->OnRstStream(frame);
39 session_->PostProcessAfterData();
40 }
41
42 virtual void OnAck(AckedPackets acked_packets) {
43 session_->OnAck(acked_packets);
44 session_->PostProcessAfterData();
45 }
46
47 virtual bool OnCanWrite() {
48 bool rc = session_->OnCanWrite();
49 session_->PostProcessAfterData();
50 return rc;
51 }
52
53 virtual void ConnectionClose(QuicErrorCode error, bool from_peer) {
54 session_->ConnectionClose(error, from_peer);
55 // The session will go away, so don't bother with cleanup.
56 }
57
58 private:
59 QuicSession* session_;
60 };
61
16 QuicSession::QuicSession(QuicConnection* connection, bool is_server) 62 QuicSession::QuicSession(QuicConnection* connection, bool is_server)
17 : connection_(connection), 63 : connection_(connection),
64 visitor_shim_(new VisitorShim(this)),
18 max_open_streams_(kDefaultMaxStreamsPerConnection), 65 max_open_streams_(kDefaultMaxStreamsPerConnection),
19 next_stream_id_(is_server ? 2 : 3), 66 next_stream_id_(is_server ? 2 : 3),
20 is_server_(is_server), 67 is_server_(is_server),
21 largest_peer_created_stream_id_(0) { 68 largest_peer_created_stream_id_(0) {
22 connection_->set_visitor(this); 69 connection->set_visitor(visitor_shim_.get());
23 } 70 }
24 71
25 QuicSession::~QuicSession() { 72 QuicSession::~QuicSession() {
26 } 73 }
27 74
28 bool QuicSession::OnPacket(const IPEndPoint& self_address, 75 bool QuicSession::OnPacket(const IPEndPoint& self_address,
29 const IPEndPoint& peer_address, 76 const IPEndPoint& peer_address,
30 const QuicPacketHeader& header, 77 const QuicPacketHeader& header,
31 const vector<QuicStreamFrame>& frames) { 78 const vector<QuicStreamFrame>& frames) {
32 if (header.guid != connection()->guid()) { 79 if (header.guid != connection()->guid()) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 264 }
218 265
219 size_t QuicSession::GetNumOpenStreams() { 266 size_t QuicSession::GetNumOpenStreams() {
220 return stream_map_.size() + implicitly_created_streams_.size(); 267 return stream_map_.size() + implicitly_created_streams_.size();
221 } 268 }
222 269
223 void QuicSession::MarkWriteBlocked(QuicStreamId id) { 270 void QuicSession::MarkWriteBlocked(QuicStreamId id) {
224 write_blocked_streams_.push_back(id); 271 write_blocked_streams_.push_back(id);
225 } 272 }
226 273
274 void QuicSession::PostProcessAfterData() {
275 STLDeleteElements(&closed_streams_);
276 closed_streams_.clear();
277 }
278
227 } // namespace net 279 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698