OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <deque> | 9 #include <deque> |
10 #include <list> | 10 #include <list> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 bool is_secure, | 97 bool is_secure, |
98 int certificate_error_code); | 98 int certificate_error_code); |
99 | 99 |
100 // Check to see if this SPDY session can support an additional domain. | 100 // Check to see if this SPDY session can support an additional domain. |
101 // If the session is un-authenticated, then this call always returns true. | 101 // If the session is un-authenticated, then this call always returns true. |
102 // For SSL-based sessions, verifies that the certificate in use by this | 102 // For SSL-based sessions, verifies that the certificate in use by this |
103 // session provides authentication for the domain. | 103 // session provides authentication for the domain. |
104 // NOTE: This function can have false negatives on some platforms. | 104 // NOTE: This function can have false negatives on some platforms. |
105 bool VerifyDomainAuthentication(const std::string& domain); | 105 bool VerifyDomainAuthentication(const std::string& domain); |
106 | 106 |
107 // Send the SYN frame for |stream_id|. | 107 // Send the PING (pre-PING and post-PING) frames. |
108 void SendPing(); | |
jar (doing other things)
2011/10/14 19:59:07
In cases where you ONLY use methods for tests, ple
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
109 | |
110 // Send the SYN frame for |stream_id|. This also sends PING message to check | |
111 // the status of the connection. | |
108 int WriteSynStream( | 112 int WriteSynStream( |
109 spdy::SpdyStreamId stream_id, | 113 spdy::SpdyStreamId stream_id, |
110 RequestPriority priority, | 114 RequestPriority priority, |
111 spdy::SpdyControlFlags flags, | 115 spdy::SpdyControlFlags flags, |
112 const linked_ptr<spdy::SpdyHeaderBlock>& headers); | 116 const linked_ptr<spdy::SpdyHeaderBlock>& headers); |
113 | 117 |
114 // Write a data frame to the stream. | 118 // Write a data frame to the stream. |
115 // Used to create and queue a data frame for the given stream. | 119 // Used to create and queue a data frame for the given stream. |
116 int WriteStreamData(spdy::SpdyStreamId stream_id, net::IOBuffer* data, | 120 int WriteStreamData(spdy::SpdyStreamId stream_id, net::IOBuffer* data, |
117 int len, | 121 int len, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 | 153 |
150 // Sets the max concurrent streams per session, as a ceiling on any server | 154 // Sets the max concurrent streams per session, as a ceiling on any server |
151 // specific SETTINGS value. | 155 // specific SETTINGS value. |
152 static void set_max_concurrent_streams(size_t value) { | 156 static void set_max_concurrent_streams(size_t value) { |
153 max_concurrent_stream_limit_ = value; | 157 max_concurrent_stream_limit_ = value; |
154 } | 158 } |
155 static size_t max_concurrent_streams() { | 159 static size_t max_concurrent_streams() { |
156 return max_concurrent_stream_limit_; | 160 return max_concurrent_stream_limit_; |
157 } | 161 } |
158 | 162 |
163 // Enable sending of PING frame with each request. | |
164 static void set_send_ping_for_every_request(bool enable) { | |
165 send_ping_for_every_request_ = enable; | |
166 } | |
167 static bool send_ping_for_every_request() { | |
168 return send_ping_for_every_request_; | |
169 } | |
170 | |
159 // The initial max concurrent streams per session, can be overridden by the | 171 // The initial max concurrent streams per session, can be overridden by the |
160 // server via SETTINGS. | 172 // server via SETTINGS. |
161 static void set_init_max_concurrent_streams(size_t value) { | 173 static void set_init_max_concurrent_streams(size_t value) { |
162 init_max_concurrent_streams_ = | 174 init_max_concurrent_streams_ = |
163 std::min(value, max_concurrent_stream_limit_); | 175 std::min(value, max_concurrent_stream_limit_); |
164 } | 176 } |
165 | 177 |
166 // Send WINDOW_UPDATE frame, called by a stream whenever receive window | 178 // Send WINDOW_UPDATE frame, called by a stream whenever receive window |
167 // size is increased. | 179 // size is increased. |
168 void SendWindowUpdate(spdy::SpdyStreamId stream_id, int delta_window_size); | 180 void SendWindowUpdate(spdy::SpdyStreamId stream_id, int delta_window_size); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 size_t num_active_streams() const { return active_streams_.size(); } | 220 size_t num_active_streams() const { return active_streams_.size(); } |
209 size_t num_unclaimed_pushed_streams() const { | 221 size_t num_unclaimed_pushed_streams() const { |
210 return unclaimed_pushed_streams_.size(); | 222 return unclaimed_pushed_streams_.size(); |
211 } | 223 } |
212 | 224 |
213 const BoundNetLog& net_log() const { return net_log_; } | 225 const BoundNetLog& net_log() const { return net_log_; } |
214 | 226 |
215 int GetPeerAddress(AddressList* address) const; | 227 int GetPeerAddress(AddressList* address) const; |
216 int GetLocalAddress(IPEndPoint* address) const; | 228 int GetLocalAddress(IPEndPoint* address) const; |
217 | 229 |
230 // -------------------------- | |
231 // Helper methods for testing | |
232 // -------------------------- | |
233 static void set_post_ping_delay_time_ms(int duration) { | |
234 post_ping_delay_time_ms_ = duration; | |
235 } | |
236 static int post_ping_delay_time_ms() { | |
237 return post_ping_delay_time_ms_; | |
238 } | |
239 | |
240 static void set_check_status_delay_time_ms(int duration) { | |
241 check_status_delay_time_ms_ = duration; | |
242 } | |
243 static int check_status_delay_time_ms() { | |
244 return check_status_delay_time_ms_; | |
245 } | |
246 | |
247 static void set_hung_interval_ms(int duration) { | |
248 hung_interval_ms_ = duration; | |
249 } | |
250 static int hung_interval_ms() { | |
251 return hung_interval_ms_; | |
252 } | |
253 | |
254 int64 pings_in_flight() const { return pings_in_flight_; } | |
255 | |
256 uint32 unique_id_counter() const { return unique_id_counter_; } | |
257 | |
258 base::TimeTicks received_data_time() const { return received_data_time_; } | |
259 | |
260 bool post_ping_pending() const { return post_ping_pending_; } | |
261 | |
262 bool check_status_pending() const { return check_status_pending_; } | |
263 | |
218 private: | 264 private: |
219 friend class base::RefCounted<SpdySession>; | 265 friend class base::RefCounted<SpdySession>; |
220 FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, GetActivePushStream); | 266 FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, GetActivePushStream); |
221 | 267 |
222 struct PendingCreateStream { | 268 struct PendingCreateStream { |
223 PendingCreateStream(const GURL& url, RequestPriority priority, | 269 PendingCreateStream(const GURL& url, RequestPriority priority, |
224 scoped_refptr<SpdyStream>* spdy_stream, | 270 scoped_refptr<SpdyStream>* spdy_stream, |
225 const BoundNetLog& stream_net_log, | 271 const BoundNetLog& stream_net_log, |
226 OldCompletionCallback* callback) | 272 OldCompletionCallback* callback) |
227 : url(&url), priority(priority), spdy_stream(spdy_stream), | 273 : url(&url), priority(priority), spdy_stream(spdy_stream), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 | 316 |
271 // Control frame handlers. | 317 // Control frame handlers. |
272 void OnSyn(const spdy::SpdySynStreamControlFrame& frame, | 318 void OnSyn(const spdy::SpdySynStreamControlFrame& frame, |
273 const linked_ptr<spdy::SpdyHeaderBlock>& headers); | 319 const linked_ptr<spdy::SpdyHeaderBlock>& headers); |
274 void OnSynReply(const spdy::SpdySynReplyControlFrame& frame, | 320 void OnSynReply(const spdy::SpdySynReplyControlFrame& frame, |
275 const linked_ptr<spdy::SpdyHeaderBlock>& headers); | 321 const linked_ptr<spdy::SpdyHeaderBlock>& headers); |
276 void OnHeaders(const spdy::SpdyHeadersControlFrame& frame, | 322 void OnHeaders(const spdy::SpdyHeadersControlFrame& frame, |
277 const linked_ptr<spdy::SpdyHeaderBlock>& headers); | 323 const linked_ptr<spdy::SpdyHeaderBlock>& headers); |
278 void OnRst(const spdy::SpdyRstStreamControlFrame& frame); | 324 void OnRst(const spdy::SpdyRstStreamControlFrame& frame); |
279 void OnGoAway(const spdy::SpdyGoAwayControlFrame& frame); | 325 void OnGoAway(const spdy::SpdyGoAwayControlFrame& frame); |
326 void OnPing(const spdy::SpdyPingControlFrame& frame); | |
280 void OnSettings(const spdy::SpdySettingsControlFrame& frame); | 327 void OnSettings(const spdy::SpdySettingsControlFrame& frame); |
281 void OnWindowUpdate(const spdy::SpdyWindowUpdateControlFrame& frame); | 328 void OnWindowUpdate(const spdy::SpdyWindowUpdateControlFrame& frame); |
282 | 329 |
283 // IO Callbacks | 330 // IO Callbacks |
284 void OnReadComplete(int result); | 331 void OnReadComplete(int result); |
285 void OnWriteComplete(int result); | 332 void OnWriteComplete(int result); |
286 | 333 |
287 // Send relevant SETTINGS. This is generally called on connection setup. | 334 // Send relevant SETTINGS. This is generally called on connection setup. |
288 void SendSettings(); | 335 void SendSettings(); |
289 | 336 |
290 // Handle SETTINGS. Either when we send settings, or when we receive a | 337 // Handle SETTINGS. Either when we send settings, or when we receive a |
291 // SETTINGS ontrol frame, update our SpdySession accordingly. | 338 // SETTINGS ontrol frame, update our SpdySession accordingly. |
292 void HandleSettings(const spdy::SpdySettings& settings); | 339 void HandleSettings(const spdy::SpdySettings& settings); |
293 | 340 |
341 // Send PING if there are no PINGs in flight and we haven't heard from server. | |
342 void SendPrePing(); | |
343 | |
344 // Send a delayed PING if there is no |post_ping_pending_|. This PING | |
345 // verfies that the requests are being received by the server. | |
346 void SendPostPing(); | |
jar (doing other things)
2011/10/14 19:59:07
You talked about replacing the word "Post" This co
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
347 | |
348 // Send a PING after delay. Don't post a PING if there is already | |
349 // a PING post pending. | |
350 void PlanToSendPostPing(); | |
351 | |
352 // Post a CheckStatus call after delay. Don't post if there is already | |
353 // CheckStatus running. | |
354 void PlanToCheckStatus(); | |
jar (doing other things)
2011/10/14 19:59:07
When talking, you suggested adding the word "Ping"
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
355 | |
356 // Send the PING frame. | |
357 void WritePingFrame(); | |
358 | |
359 // Check the status of the connection. It calls |CloseSessionOnError| if we | |
360 // haven't received any data in |kHungInterval| time period. | |
361 void CheckStatus(base::TimeTicks last_check_time); | |
362 | |
294 // Start reading from the socket. | 363 // Start reading from the socket. |
295 // Returns OK on success, or an error on failure. | 364 // Returns OK on success, or an error on failure. |
296 net::Error ReadSocket(); | 365 net::Error ReadSocket(); |
297 | 366 |
298 // Write current data to the socket. | 367 // Write current data to the socket. |
299 void WriteSocketLater(); | 368 void WriteSocketLater(); |
300 void WriteSocket(); | 369 void WriteSocket(); |
301 | 370 |
302 // Get a new stream id. | 371 // Get a new stream id. |
303 int GetNewStreamId(); | 372 int GetNewStreamId(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 int streams_pushed_count_; | 499 int streams_pushed_count_; |
431 int streams_pushed_and_claimed_count_; | 500 int streams_pushed_and_claimed_count_; |
432 int streams_abandoned_count_; | 501 int streams_abandoned_count_; |
433 int frames_received_; | 502 int frames_received_; |
434 int bytes_received_; | 503 int bytes_received_; |
435 bool sent_settings_; // Did this session send settings when it started. | 504 bool sent_settings_; // Did this session send settings when it started. |
436 bool received_settings_; // Did this session receive at least one settings | 505 bool received_settings_; // Did this session receive at least one settings |
437 // frame. | 506 // frame. |
438 int stalled_streams_; // Count of streams that were ever stalled. | 507 int stalled_streams_; // Count of streams that were ever stalled. |
439 | 508 |
509 // This list keeps track of all pings that are in flight. | |
jar (doing other things)
2011/10/14 19:59:07
nit: Suggest changing comment to:
Count of all pi
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
510 int64 pings_in_flight_; | |
511 | |
512 // This is the next unique_id to be sent in PING frame. unique_ids are odd | |
513 // numbers. | |
514 uint32 unique_id_counter_; | |
jar (doing other things)
2011/10/14 19:59:07
suggest: next_ping_id_;
(and adjust comment)
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
515 | |
516 // This is the last time we have received data. | |
517 base::TimeTicks received_data_time_; | |
518 | |
519 // Flag if we have a pending post-PING. | |
jar (doing other things)
2011/10/14 19:59:07
Indicate if we have already scheduled a delayed ta
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
520 bool post_ping_pending_; | |
521 | |
522 // Flag if we have a check status pending. | |
jar (doing other things)
2011/10/14 19:59:07
Indicate if we have already scheduled a delayed ta
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
523 bool check_status_pending_; | |
524 | |
525 // Flag to indicate what was the last data sent (if it was PING or if we had | |
526 // sent any other data). | |
jar (doing other things)
2011/10/14 19:59:07
Indicate if the last data we sent was a ping (gene
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
527 bool last_sent_was_ping_; | |
528 | |
440 // Initial send window size for the session; can be changed by an | 529 // Initial send window size for the session; can be changed by an |
441 // arriving SETTINGS frame; newly created streams use this value for the | 530 // arriving SETTINGS frame; newly created streams use this value for the |
442 // initial send window size. | 531 // initial send window size. |
443 int initial_send_window_size_; | 532 int initial_send_window_size_; |
444 | 533 |
445 // Initial receive window size for the session; there are plans to add a | 534 // Initial receive window size for the session; there are plans to add a |
446 // command line switch that would cause a SETTINGS frame with window size | 535 // command line switch that would cause a SETTINGS frame with window size |
447 // announcement to be sent on startup; newly created streams will use | 536 // announcement to be sent on startup; newly created streams will use |
448 // this value for the initial receive window size. | 537 // this value for the initial receive window size. |
449 int initial_recv_window_size_; | 538 int initial_recv_window_size_; |
450 | 539 |
451 BoundNetLog net_log_; | 540 BoundNetLog net_log_; |
452 | 541 |
453 // Outside of tests, this should always be true. | 542 // Outside of tests, this should always be true. |
454 bool verify_domain_authentication_; | 543 bool verify_domain_authentication_; |
455 | 544 |
456 static bool use_ssl_; | 545 static bool use_ssl_; |
457 static bool use_flow_control_; | 546 static bool use_flow_control_; |
458 static size_t init_max_concurrent_streams_; | 547 static size_t init_max_concurrent_streams_; |
459 static size_t max_concurrent_stream_limit_; | 548 static size_t max_concurrent_stream_limit_; |
549 static bool send_ping_for_every_request_; | |
jar (doing other things)
2011/10/14 19:59:07
That name is no longer valid (since we don't send
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
550 static int post_ping_delay_time_ms_; | |
551 static int check_status_delay_time_ms_; | |
552 static int hung_interval_ms_; | |
jar (doing other things)
2011/10/14 19:59:07
Use only one var for line 551 and 552.
Suggest us
ramant (doing other things)
2011/10/14 23:42:45
Done.
| |
553 | |
460 }; | 554 }; |
461 | 555 |
462 class NetLogSpdySynParameter : public NetLog::EventParameters { | 556 class NetLogSpdySynParameter : public NetLog::EventParameters { |
463 public: | 557 public: |
464 NetLogSpdySynParameter(const linked_ptr<spdy::SpdyHeaderBlock>& headers, | 558 NetLogSpdySynParameter(const linked_ptr<spdy::SpdyHeaderBlock>& headers, |
465 spdy::SpdyControlFlags flags, | 559 spdy::SpdyControlFlags flags, |
466 spdy::SpdyStreamId id, | 560 spdy::SpdyStreamId id, |
467 spdy::SpdyStreamId associated_stream); | 561 spdy::SpdyStreamId associated_stream); |
468 | 562 |
469 const linked_ptr<spdy::SpdyHeaderBlock>& GetHeaders() const { | 563 const linked_ptr<spdy::SpdyHeaderBlock>& GetHeaders() const { |
470 return headers_; | 564 return headers_; |
471 } | 565 } |
472 | 566 |
473 virtual base::Value* ToValue() const; | 567 virtual base::Value* ToValue() const; |
474 | 568 |
475 private: | 569 private: |
476 virtual ~NetLogSpdySynParameter(); | 570 virtual ~NetLogSpdySynParameter(); |
477 | 571 |
478 const linked_ptr<spdy::SpdyHeaderBlock> headers_; | 572 const linked_ptr<spdy::SpdyHeaderBlock> headers_; |
479 const spdy::SpdyControlFlags flags_; | 573 const spdy::SpdyControlFlags flags_; |
480 const spdy::SpdyStreamId id_; | 574 const spdy::SpdyStreamId id_; |
481 const spdy::SpdyStreamId associated_stream_; | 575 const spdy::SpdyStreamId associated_stream_; |
482 | 576 |
483 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySynParameter); | 577 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySynParameter); |
484 }; | 578 }; |
485 | 579 |
486 } // namespace net | 580 } // namespace net |
487 | 581 |
488 #endif // NET_SPDY_SPDY_SESSION_H_ | 582 #endif // NET_SPDY_SPDY_SESSION_H_ |
OLD | NEW |