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 #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 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 // Returns the ServerBoundCertService used by this Socket, or NULL | 258 // Returns the ServerBoundCertService used by this Socket, or NULL |
259 // if server bound certs are not supported in this session. | 259 // if server bound certs are not supported in this session. |
260 ServerBoundCertService* GetServerBoundCertService() const; | 260 ServerBoundCertService* GetServerBoundCertService() const; |
261 | 261 |
262 // Send WINDOW_UPDATE frame, called by a stream whenever receive window | 262 // Send WINDOW_UPDATE frame, called by a stream whenever receive window |
263 // size is increased. | 263 // size is increased. |
264 void SendWindowUpdate(SpdyStreamId stream_id, int32 delta_window_size); | 264 void SendWindowUpdate(SpdyStreamId stream_id, int32 delta_window_size); |
265 | 265 |
266 // If session is closed, no new streams/transactions should be created. | 266 // If session is closed, no new streams/transactions should be created. |
267 bool IsClosed() const { return state_ == CLOSED; } | 267 bool IsClosed() const { return state_ == STATE_CLOSED; } |
268 | 268 |
269 // Closes this session. This will close all active streams and mark | 269 // Closes this session. This will close all active streams and mark |
270 // the session as permanently closed. | 270 // the session as permanently closed. |
271 // |err| should not be OK; this function is intended to be called on | 271 // |err| should not be OK; this function is intended to be called on |
272 // error. | 272 // error. |
273 // |remove_from_pool| indicates whether to also remove the session from the | 273 // |remove_from_pool| indicates whether to also remove the session from the |
274 // session pool. | 274 // session pool. |
275 // |description| indicates the reason for the error. | 275 // |description| indicates the reason for the error. |
276 void CloseSessionOnError(net::Error err, | 276 void CloseSessionOnError(net::Error err, |
277 bool remove_from_pool, | 277 bool remove_from_pool, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 ~CallbackResultPair(); | 398 ~CallbackResultPair(); |
399 | 399 |
400 CompletionCallback callback; | 400 CompletionCallback callback; |
401 int result; | 401 int result; |
402 }; | 402 }; |
403 | 403 |
404 typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair> | 404 typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair> |
405 PendingCallbackMap; | 405 PendingCallbackMap; |
406 | 406 |
407 enum State { | 407 enum State { |
408 IDLE, | 408 STATE_IDLE, |
409 CONNECTING, | 409 STATE_CONNECTING, |
410 CONNECTED, | 410 STATE_DO_READ, |
411 CLOSED | 411 STATE_DO_READ_COMPLETE, |
| 412 STATE_CLOSED |
412 }; | 413 }; |
413 | 414 |
414 virtual ~SpdySession(); | 415 virtual ~SpdySession(); |
415 | 416 |
416 void ProcessPendingCreateStreams(); | 417 void ProcessPendingCreateStreams(); |
417 int CreateStreamImpl( | 418 int CreateStreamImpl( |
418 const GURL& url, | 419 const GURL& url, |
419 RequestPriority priority, | 420 RequestPriority priority, |
420 scoped_refptr<SpdyStream>* spdy_stream, | 421 scoped_refptr<SpdyStream>* spdy_stream, |
421 const BoundNetLog& stream_net_log); | 422 const BoundNetLog& stream_net_log); |
422 | 423 |
| 424 // Start the DoLoop to read data from socket. |
| 425 void StartRead(); |
| 426 |
| 427 // Try to make progress by reading and processing data. |
| 428 int DoLoop(int result); |
| 429 // The implementations of STATE_DO_READ/STATE_DO_READ_COMPLETE state changes |
| 430 // of the state machine. |
| 431 int DoRead(); |
| 432 int DoReadComplete(int bytes_read); |
| 433 |
| 434 // Check if session is connected or not. |
| 435 bool IsConnected() const { |
| 436 return state_ == STATE_DO_READ || state_ == STATE_DO_READ_COMPLETE; |
| 437 } |
| 438 |
423 // IO Callbacks | 439 // IO Callbacks |
424 void OnReadComplete(int result); | 440 void OnReadComplete(int result); |
425 void OnWriteComplete(int result); | 441 void OnWriteComplete(int result); |
426 | 442 |
427 // Send relevant SETTINGS. This is generally called on connection setup. | 443 // Send relevant SETTINGS. This is generally called on connection setup. |
428 void SendInitialSettings(); | 444 void SendInitialSettings(); |
429 | 445 |
430 // Helper method to send SETTINGS a frame. | 446 // Helper method to send SETTINGS a frame. |
431 void SendSettings(const SettingsMap& settings); | 447 void SendSettings(const SettingsMap& settings); |
432 | 448 |
(...skipping 14 matching lines...) Expand all Loading... |
447 void WritePingFrame(uint32 unique_id); | 463 void WritePingFrame(uint32 unique_id); |
448 | 464 |
449 // Post a CheckPingStatus call after delay. Don't post if there is already | 465 // Post a CheckPingStatus call after delay. Don't post if there is already |
450 // CheckPingStatus running. | 466 // CheckPingStatus running. |
451 void PlanToCheckPingStatus(); | 467 void PlanToCheckPingStatus(); |
452 | 468 |
453 // Check the status of the connection. It calls |CloseSessionOnError| if we | 469 // Check the status of the connection. It calls |CloseSessionOnError| if we |
454 // haven't received any data in |kHungInterval| time period. | 470 // haven't received any data in |kHungInterval| time period. |
455 void CheckPingStatus(base::TimeTicks last_check_time); | 471 void CheckPingStatus(base::TimeTicks last_check_time); |
456 | 472 |
457 // Start reading from the socket. | |
458 // Returns OK on success, or an error on failure. | |
459 net::Error ReadSocket(); | |
460 | |
461 // Write current data to the socket. | 473 // Write current data to the socket. |
462 void WriteSocketLater(); | 474 void WriteSocketLater(); |
463 void WriteSocket(); | 475 void WriteSocket(); |
464 | 476 |
465 // Get a new stream id. | 477 // Get a new stream id. |
466 int GetNewStreamId(); | 478 int GetNewStreamId(); |
467 | 479 |
468 // Queue a frame for sending. | 480 // Queue a frame for sending. |
469 // |frame| is the frame to send. | 481 // |frame| is the frame to send. |
470 // |priority| is the priority for insertion into the queue. | 482 // |priority| is the priority for insertion into the queue. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 | 660 |
649 // Limits | 661 // Limits |
650 size_t max_concurrent_streams_; // 0 if no limit | 662 size_t max_concurrent_streams_; // 0 if no limit |
651 size_t max_concurrent_streams_limit_; | 663 size_t max_concurrent_streams_limit_; |
652 | 664 |
653 // Some statistics counters for the session. | 665 // Some statistics counters for the session. |
654 int streams_initiated_count_; | 666 int streams_initiated_count_; |
655 int streams_pushed_count_; | 667 int streams_pushed_count_; |
656 int streams_pushed_and_claimed_count_; | 668 int streams_pushed_and_claimed_count_; |
657 int streams_abandoned_count_; | 669 int streams_abandoned_count_; |
658 int bytes_received_; | 670 int total_bytes_received_; |
| 671 int bytes_read_; |
659 bool sent_settings_; // Did this session send settings when it started. | 672 bool sent_settings_; // Did this session send settings when it started. |
660 bool received_settings_; // Did this session receive at least one settings | 673 bool received_settings_; // Did this session receive at least one settings |
661 // frame. | 674 // frame. |
662 int stalled_streams_; // Count of streams that were ever stalled. | 675 int stalled_streams_; // Count of streams that were ever stalled. |
663 | 676 |
664 // Count of all pings on the wire, for which we have not gotten a response. | 677 // Count of all pings on the wire, for which we have not gotten a response. |
665 int64 pings_in_flight_; | 678 int64 pings_in_flight_; |
666 | 679 |
667 // This is the next ping_id (unique_id) to be sent in PING frame. | 680 // This is the next ping_id (unique_id) to be sent in PING frame. |
668 uint32 next_ping_id_; | 681 uint32 next_ping_id_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 // This SPDY proxy is allowed to push resources from origins that are | 745 // This SPDY proxy is allowed to push resources from origins that are |
733 // different from those of their associated streams. | 746 // different from those of their associated streams. |
734 HostPortPair trusted_spdy_proxy_; | 747 HostPortPair trusted_spdy_proxy_; |
735 | 748 |
736 TimeFunc time_func_; | 749 TimeFunc time_func_; |
737 }; | 750 }; |
738 | 751 |
739 } // namespace net | 752 } // namespace net |
740 | 753 |
741 #endif // NET_SPDY_SPDY_SESSION_H_ | 754 #endif // NET_SPDY_SPDY_SESSION_H_ |
OLD | NEW |