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

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

Issue 10448083: Fix out of order SYN_STEAM frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make SpdyFrameProducer a nested class in SpdySession. Created 8 years, 6 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/spdy/spdy_network_transaction_spdy3_unittest.cc ('k') | net/spdy/spdy_session.cc » ('j') | 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 #ifndef NET_SPDY_SPDY_SESSION_H_ 5 #ifndef NET_SPDY_SPDY_SESSION_H_
6 #define NET_SPDY_SPDY_SESSION_H_ 6 #define NET_SPDY_SPDY_SESSION_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 SpdyProtocolErrorDetails_SpdyErrors_mismatch); 89 SpdyProtocolErrorDetails_SpdyErrors_mismatch);
90 90
91 COMPILE_ASSERT(PROTOCOL_ERROR_UNEXPECTED_PING == 91 COMPILE_ASSERT(PROTOCOL_ERROR_UNEXPECTED_PING ==
92 static_cast<SpdyProtocolErrorDetails>(NUM_STATUS_CODES + 92 static_cast<SpdyProtocolErrorDetails>(NUM_STATUS_CODES +
93 STATUS_CODE_INVALID), 93 STATUS_CODE_INVALID),
94 SpdyProtocolErrorDetails_SpdyErrors_mismatch); 94 SpdyProtocolErrorDetails_SpdyErrors_mismatch);
95 95
96 class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, 96 class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
97 public BufferedSpdyFramerVisitorInterface { 97 public BufferedSpdyFramerVisitorInterface {
98 public: 98 public:
99 // Defines an interface for producing SPDY frames.
100 class NET_EXPORT_PRIVATE SpdyFrameProducer {
willchan no longer on Chromium 2012/06/21 23:51:03 Indentation
Ryan Hamilton 2012/06/22 16:17:32 Done.
101 public:
102 SpdyFrameProducer() {}
103
104 // Returns a newly created SpdyFrame, owned by the called.
105 virtual SpdyFrame* ProduceNextFrame(SpdySession* session) = 0;
106
107 // Returns the priority of frames produced by this producer.
108 virtual RequestPriority GetPriority() const = 0;
109
110 // Returns a pointer to the underlying SpdyStream, or NULL if none exits.
111 virtual SpdyStream* GetSpdyStream() = 0;
willchan no longer on Chromium 2012/06/21 23:51:03 Do you still need this one?
Ryan Hamilton 2012/06/22 16:17:32 It is still used because when we decide that we ne
willchan no longer on Chromium 2012/06/22 21:10:44 I see. I think I'd rather keep it out of this inte
112
113 virtual ~SpdyFrameProducer() {}
114
115 // Activates |spdy_stream| in |spdy_session|.
116 void ActivateStream(SpdySession* spdy_session, SpdyStream* spdy_stream);
willchan no longer on Chromium 2012/06/21 23:51:03 Can this be static?
Ryan Hamilton 2012/06/22 16:17:32 Done.
117
118 private:
119 DISALLOW_COPY_AND_ASSIGN(SpdyFrameProducer);
120 };
121
99 // Create a new SpdySession. 122 // Create a new SpdySession.
100 // |host_port_proxy_pair| is the host/port that this session connects to, and 123 // |host_port_proxy_pair| is the host/port that this session connects to, and
101 // the proxy configuration settings that it's using. 124 // the proxy configuration settings that it's using.
102 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must 125 // |spdy_session_pool| is the SpdySessionPool that owns us. Its lifetime must
103 // strictly be greater than |this|. 126 // strictly be greater than |this|.
104 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log 127 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log
105 // network events to. 128 // network events to.
106 SpdySession(const HostPortProxyPair& host_port_proxy_pair, 129 SpdySession(const HostPortProxyPair& host_port_proxy_pair,
107 SpdySessionPool* spdy_session_pool, 130 SpdySessionPool* spdy_session_pool,
108 HttpServerProperties* http_server_properties, 131 HttpServerProperties* http_server_properties,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // If the session is un-authenticated, then this call always returns true. 174 // If the session is un-authenticated, then this call always returns true.
152 // For SSL-based sessions, verifies that the server certificate in use by 175 // For SSL-based sessions, verifies that the server certificate in use by
153 // this session provides authentication for the domain and no client 176 // this session provides authentication for the domain and no client
154 // certificate was sent to the original server during the SSL handshake. 177 // certificate was sent to the original server during the SSL handshake.
155 // NOTE: This function can have false negatives on some platforms. 178 // NOTE: This function can have false negatives on some platforms.
156 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch 179 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch
157 // histogram because this function does more than verifying domain 180 // histogram because this function does more than verifying domain
158 // authentication now. 181 // authentication now.
159 bool VerifyDomainAuthentication(const std::string& domain); 182 bool VerifyDomainAuthentication(const std::string& domain);
160 183
184 // Records that |stream| has a write available.
185 void SetStreamHasWriteAvailable(SpdyStream* stream);
186
161 // Send the SYN frame for |stream_id|. This also sends PING message to check 187 // Send the SYN frame for |stream_id|. This also sends PING message to check
162 // the status of the connection. 188 // the status of the connection.
163 int WriteSynStream( 189 SpdySynStreamControlFrame* CreateSynStream(
164 SpdyStreamId stream_id, 190 SpdyStreamId stream_id,
165 RequestPriority priority, 191 RequestPriority priority,
166 uint8 credential_slot, 192 uint8 credential_slot,
167 SpdyControlFlags flags, 193 SpdyControlFlags flags,
168 const linked_ptr<SpdyHeaderBlock>& headers); 194 const linked_ptr<SpdyHeaderBlock>& headers);
169 195
170 // Write a CREDENTIAL frame to the session. 196 // Write a CREDENTIAL frame to the session.
171 int WriteCredentialFrame(const std::string& origin, 197 SpdyCredentialControlFrame* CreateCredentialFrame(const std::string& origin,
172 SSLClientCertType type, 198 SSLClientCertType type,
173 const std::string& key, 199 const std::string& key,
174 const std::string& cert, 200 const std::string& cert,
175 RequestPriority priority); 201 RequestPriority priority);
176 202
177 // Write a data frame to the stream. 203 // Write a data frame to the stream.
178 // Used to create and queue a data frame for the given stream. 204 // Used to create and queue a data frame for the given stream.
179 int WriteStreamData(SpdyStreamId stream_id, net::IOBuffer* data, 205 SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id,
180 int len, 206 net::IOBuffer* data, int len,
181 SpdyDataFlags flags); 207 SpdyDataFlags flags);
182 208
183 // Close a stream. 209 // Close a stream.
184 void CloseStream(SpdyStreamId stream_id, int status); 210 void CloseStream(SpdyStreamId stream_id, int status);
185 211
212 // Close a stream that has been created but is not yet active.
213 void CloseCreatedStream(SpdyStream* stream, int status);
214
186 // Reset a stream by sending a RST_STREAM frame with given status code. 215 // Reset a stream by sending a RST_STREAM frame with given status code.
187 // Also closes the stream. Was not piggybacked to CloseStream since not 216 // Also closes the stream. Was not piggybacked to CloseStream since not
188 // all of the calls to CloseStream necessitate sending a RST_STREAM. 217 // all of the calls to CloseStream necessitate sending a RST_STREAM.
189 void ResetStream(SpdyStreamId stream_id, 218 void ResetStream(SpdyStreamId stream_id,
190 SpdyStatusCodes status, 219 SpdyStatusCodes status,
191 const std::string& description); 220 const std::string& description);
192 221
193 // Check if a stream is active. 222 // Check if a stream is active.
194 bool IsStreamActive(SpdyStreamId stream_id) const; 223 bool IsStreamActive(SpdyStreamId stream_id) const;
195 224
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 bool WasEverUsed() const { 292 bool WasEverUsed() const {
264 return connection_->socket()->WasEverUsed(); 293 return connection_->socket()->WasEverUsed();
265 } 294 }
266 295
267 void set_spdy_session_pool(SpdySessionPool* pool) { 296 void set_spdy_session_pool(SpdySessionPool* pool) {
268 spdy_session_pool_ = NULL; 297 spdy_session_pool_ = NULL;
269 } 298 }
270 299
271 // Returns true if session is not currently active 300 // Returns true if session is not currently active
272 bool is_active() const { 301 bool is_active() const {
273 return !active_streams_.empty(); 302 return !active_streams_.empty() || !created_streams_.empty();
274 } 303 }
275 304
276 // Access to the number of active and pending streams. These are primarily 305 // Access to the number of active and pending streams. These are primarily
277 // available for testing and diagnostics. 306 // available for testing and diagnostics.
278 size_t num_active_streams() const { return active_streams_.size(); } 307 size_t num_active_streams() const { return active_streams_.size(); }
279 size_t num_unclaimed_pushed_streams() const { 308 size_t num_unclaimed_pushed_streams() const {
280 return unclaimed_pushed_streams_.size(); 309 return unclaimed_pushed_streams_.size();
281 } 310 }
311 size_t num_created_streams() const { return created_streams_.size(); }
282 312
283 // Returns true if flow control is enabled for the session. 313 // Returns true if flow control is enabled for the session.
284 bool is_flow_control_enabled() const { 314 bool is_flow_control_enabled() const {
285 return flow_control_; 315 return flow_control_;
286 } 316 }
287 317
288 // Returns the current |initial_send_window_size_|. 318 // Returns the current |initial_send_window_size_|.
289 int32 initial_send_window_size() const { 319 int32 initial_send_window_size() const {
290 return initial_send_window_size_; 320 return initial_send_window_size_;
291 } 321 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 RequestPriority priority; 377 RequestPriority priority;
348 scoped_refptr<SpdyStream>* spdy_stream; 378 scoped_refptr<SpdyStream>* spdy_stream;
349 const BoundNetLog* stream_net_log; 379 const BoundNetLog* stream_net_log;
350 CompletionCallback callback; 380 CompletionCallback callback;
351 }; 381 };
352 typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> > 382 typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> >
353 PendingCreateStreamQueue; 383 PendingCreateStreamQueue;
354 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; 384 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap;
355 // Only HTTP push a stream. 385 // Only HTTP push a stream.
356 typedef std::map<std::string, scoped_refptr<SpdyStream> > PushedStreamMap; 386 typedef std::map<std::string, scoped_refptr<SpdyStream> > PushedStreamMap;
357 typedef std::priority_queue<SpdyIOBuffer> OutputQueue; 387 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet;
388 class SpdyFrameProducerCompare {
389 public:
390 bool operator() (const SpdyFrameProducer* lhs,
391 const SpdyFrameProducer* rhs) const {
392 return lhs->GetPriority() < rhs->GetPriority();
393 }
394 };
395 typedef std::priority_queue<SpdyFrameProducer*,
396 std::vector<SpdyFrameProducer*>,
397 SpdyFrameProducerCompare> WriteQueue;
358 398
359 struct CallbackResultPair { 399 struct CallbackResultPair {
360 CallbackResultPair(const CompletionCallback& callback_in, int result_in) 400 CallbackResultPair(const CompletionCallback& callback_in, int result_in)
361 : callback(callback_in), result(result_in) {} 401 : callback(callback_in), result(result_in) {}
362 ~CallbackResultPair(); 402 ~CallbackResultPair();
363 403
364 CompletionCallback callback; 404 CompletionCallback callback;
365 int result; 405 int result;
366 }; 406 };
367 407
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 // Write current data to the socket. 462 // Write current data to the socket.
423 void WriteSocketLater(); 463 void WriteSocketLater();
424 void WriteSocket(); 464 void WriteSocket();
425 465
426 // Get a new stream id. 466 // Get a new stream id.
427 int GetNewStreamId(); 467 int GetNewStreamId();
428 468
429 // Queue a frame for sending. 469 // Queue a frame for sending.
430 // |frame| is the frame to send. 470 // |frame| is the frame to send.
431 // |priority| is the priority for insertion into the queue. 471 // |priority| is the priority for insertion into the queue.
432 // |stream| is the stream which this IO is associated with (or NULL). 472 void QueueFrame(SpdyFrame* frame, RequestPriority priority);
433 void QueueFrame(SpdyFrame* frame, RequestPriority priority,
434 SpdyStream* stream);
435 473
436 // Track active streams in the active stream list. 474 // Track active streams in the active stream list.
437 void ActivateStream(SpdyStream* stream); 475 void ActivateStream(SpdyStream* stream);
438 void DeleteStream(SpdyStreamId id, int status); 476 void DeleteStream(SpdyStreamId id, int status);
439 477
440 // Removes this session from the session pool. 478 // Removes this session from the session pool.
441 void RemoveFromPool(); 479 void RemoveFromPool();
442 480
443 // Check if we have a pending pushed-stream for this url 481 // Check if we have a pending pushed-stream for this url
444 // Returns the stream if found (and returns it from the pending 482 // Returns the stream if found (and returns it from the pending
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // the server to start pushing the stream]) or there are still network events 589 // the server to start pushing the stream]) or there are still network events
552 // incoming even though the consumer has already gone away (cancellation). 590 // incoming even though the consumer has already gone away (cancellation).
553 // TODO(willchan): Perhaps we should separate out cancelled streams and move 591 // TODO(willchan): Perhaps we should separate out cancelled streams and move
554 // them into a separate ActiveStreamMap, and not deliver network events to 592 // them into a separate ActiveStreamMap, and not deliver network events to
555 // them? 593 // them?
556 ActiveStreamMap active_streams_; 594 ActiveStreamMap active_streams_;
557 // Map of all the streams that have already started to be pushed by the 595 // Map of all the streams that have already started to be pushed by the
558 // server, but do not have consumers yet. 596 // server, but do not have consumers yet.
559 PushedStreamMap unclaimed_pushed_streams_; 597 PushedStreamMap unclaimed_pushed_streams_;
560 598
561 // As we gather data to be sent, we put it into the output queue. 599 // Set of all created streams but that have not yet sent any frames.
562 OutputQueue queue_; 600 CreatedStreamSet created_streams_;
601
602 // As streams have data to be sent, we put them into the write queue.
603 WriteQueue write_queue_;
563 604
564 // The packet we are currently sending. 605 // The packet we are currently sending.
565 bool write_pending_; // Will be true when a write is in progress. 606 bool write_pending_; // Will be true when a write is in progress.
566 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress. 607 SpdyIOBuffer in_flight_write_; // This is the write buffer in progress.
567 608
568 // Flag if we have a pending message scheduled for WriteSocket. 609 // Flag if we have a pending message scheduled for WriteSocket.
569 bool delayed_write_pending_; 610 bool delayed_write_pending_;
570 611
571 // Flag if we're using an SSL connection for this SpdySession. 612 // Flag if we're using an SSL connection for this SpdySession.
572 bool is_secure_; 613 bool is_secure_;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 private: 757 private:
717 const int status_; 758 const int status_;
718 const std::string description_; 759 const std::string description_;
719 760
720 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySessionCloseParameter); 761 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySessionCloseParameter);
721 }; 762 };
722 763
723 } // namespace net 764 } // namespace net
724 765
725 #endif // NET_SPDY_SPDY_SESSION_H_ 766 #endif // NET_SPDY_SPDY_SESSION_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_spdy3_unittest.cc ('k') | net/spdy/spdy_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698