| 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 <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // reasonably with ethernet. Chop the world into 2-packet chunks. This is | 41 // reasonably with ethernet. Chop the world into 2-packet chunks. This is |
| 42 // somewhat arbitrary, but is reasonably small and ensures that we elicit | 42 // somewhat arbitrary, but is reasonably small and ensures that we elicit |
| 43 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). | 43 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). |
| 44 const int kMss = 1430; | 44 const int kMss = 1430; |
| 45 // The 8 is the size of the SPDY frame header. | 45 // The 8 is the size of the SPDY frame header. |
| 46 const int kMaxSpdyFrameChunkSize = (2 * kMss) - 8; | 46 const int kMaxSpdyFrameChunkSize = (2 * kMss) - 8; |
| 47 | 47 |
| 48 // Specifies the maxiumum concurrent streams server could send (via push). | 48 // Specifies the maxiumum concurrent streams server could send (via push). |
| 49 const int kMaxConcurrentPushedStreams = 1000; | 49 const int kMaxConcurrentPushedStreams = 1000; |
| 50 | 50 |
| 51 // Specifies the number of bytes read synchronously (without yielding) if the |
| 52 // data is available. |
| 53 const int kMaxReadBytes = 32 * 1024; |
| 54 |
| 51 // The initial receive window size for both streams and sessions. | 55 // The initial receive window size for both streams and sessions. |
| 52 const int32 kDefaultInitialRecvWindowSize = 10 * 1024 * 1024; // 10MB | 56 const int32 kDefaultInitialRecvWindowSize = 10 * 1024 * 1024; // 10MB |
| 53 | 57 |
| 54 class BoundNetLog; | 58 class BoundNetLog; |
| 55 struct LoadTimingInfo; | 59 struct LoadTimingInfo; |
| 56 class SpdyStream; | 60 class SpdyStream; |
| 57 class SSLInfo; | 61 class SSLInfo; |
| 58 | 62 |
| 59 enum SpdyProtocolErrorDetails { | 63 enum SpdyProtocolErrorDetails { |
| 60 // SpdyFramer::SpdyErrors | 64 // SpdyFramer::SpdyErrors |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 uint32 delta_window_size); | 317 uint32 delta_window_size); |
| 314 | 318 |
| 315 // Called by a stream to increase this session's receive window size | 319 // Called by a stream to increase this session's receive window size |
| 316 // by |delta_window_size|, which must be at least 1 and must not | 320 // by |delta_window_size|, which must be at least 1 and must not |
| 317 // cause this session's receive window size to overflow, possibly | 321 // cause this session's receive window size to overflow, possibly |
| 318 // also sending a WINDOW_UPDATE frame. Does nothing if session flow | 322 // also sending a WINDOW_UPDATE frame. Does nothing if session flow |
| 319 // control is turned off. | 323 // control is turned off. |
| 320 void IncreaseRecvWindowSize(int32 delta_window_size); | 324 void IncreaseRecvWindowSize(int32 delta_window_size); |
| 321 | 325 |
| 322 // If session is closed, no new streams/transactions should be created. | 326 // If session is closed, no new streams/transactions should be created. |
| 323 bool IsClosed() const { return state_ == CLOSED; } | 327 bool IsClosed() const { return state_ == STATE_CLOSED; } |
| 324 | 328 |
| 325 // Closes this session. This will close all active streams and mark | 329 // Closes this session. This will close all active streams and mark |
| 326 // the session as permanently closed. | 330 // the session as permanently closed. |
| 327 // |err| should not be OK; this function is intended to be called on | 331 // |err| should not be OK; this function is intended to be called on |
| 328 // error. | 332 // error. |
| 329 // |remove_from_pool| indicates whether to also remove the session from the | 333 // |remove_from_pool| indicates whether to also remove the session from the |
| 330 // session pool. | 334 // session pool. |
| 331 // |description| indicates the reason for the error. | 335 // |description| indicates the reason for the error. |
| 332 void CloseSessionOnError(net::Error err, | 336 void CloseSessionOnError(net::Error err, |
| 333 bool remove_from_pool, | 337 bool remove_from_pool, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 typedef std::deque<SpdyStreamRequest*> PendingStreamRequestQueue; | 475 typedef std::deque<SpdyStreamRequest*> PendingStreamRequestQueue; |
| 472 typedef std::set<SpdyStreamRequest*> PendingStreamRequestCompletionSet; | 476 typedef std::set<SpdyStreamRequest*> PendingStreamRequestCompletionSet; |
| 473 | 477 |
| 474 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; | 478 typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap; |
| 475 typedef std::map<std::string, | 479 typedef std::map<std::string, |
| 476 std::pair<scoped_refptr<SpdyStream>, base::TimeTicks> > PushedStreamMap; | 480 std::pair<scoped_refptr<SpdyStream>, base::TimeTicks> > PushedStreamMap; |
| 477 | 481 |
| 478 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet; | 482 typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet; |
| 479 | 483 |
| 480 enum State { | 484 enum State { |
| 481 IDLE, | 485 STATE_IDLE, |
| 482 CONNECTING, | 486 STATE_CONNECTING, |
| 483 CONNECTED, | 487 STATE_DO_READ, |
| 484 CLOSED | 488 STATE_DO_READ_COMPLETE, |
| 489 STATE_CLOSED |
| 485 }; | 490 }; |
| 486 | 491 |
| 487 virtual ~SpdySession(); | 492 virtual ~SpdySession(); |
| 488 | 493 |
| 489 // Called by SpdyStreamRequest to start a request to create a | 494 // Called by SpdyStreamRequest to start a request to create a |
| 490 // stream. If OK is returned, then |stream| will be filled in with a | 495 // stream. If OK is returned, then |stream| will be filled in with a |
| 491 // valid stream. If ERR_IO_PENDING is returned, then | 496 // valid stream. If ERR_IO_PENDING is returned, then |
| 492 // |request->OnRequestComplete()| will be called when the stream is | 497 // |request->OnRequestComplete()| will be called when the stream is |
| 493 // created (unless it is cancelled). Otherwise, no stream is created | 498 // created (unless it is cancelled). Otherwise, no stream is created |
| 494 // and the error is returned. | 499 // and the error is returned. |
| 495 int TryCreateStream(SpdyStreamRequest* request, | 500 int TryCreateStream(SpdyStreamRequest* request, |
| 496 scoped_refptr<SpdyStream>* stream); | 501 scoped_refptr<SpdyStream>* stream); |
| 497 | 502 |
| 498 // Actually create a stream into |stream|. Returns OK if successful; | 503 // Actually create a stream into |stream|. Returns OK if successful; |
| 499 // otherwise, returns an error and |stream| is not filled. | 504 // otherwise, returns an error and |stream| is not filled. |
| 500 int CreateStream(const SpdyStreamRequest& request, | 505 int CreateStream(const SpdyStreamRequest& request, |
| 501 scoped_refptr<SpdyStream>* stream); | 506 scoped_refptr<SpdyStream>* stream); |
| 502 | 507 |
| 503 // Called by SpdyStreamRequest to remove |request| from the stream | 508 // Called by SpdyStreamRequest to remove |request| from the stream |
| 504 // creation queue. | 509 // creation queue. |
| 505 void CancelStreamRequest(SpdyStreamRequest* request); | 510 void CancelStreamRequest(SpdyStreamRequest* request); |
| 506 | 511 |
| 507 // Called when there is room to create more streams (e.g., a stream | 512 // Called when there is room to create more streams (e.g., a stream |
| 508 // was closed). Processes as many pending stream requests as | 513 // was closed). Processes as many pending stream requests as |
| 509 // possible. | 514 // possible. |
| 510 void ProcessPendingStreamRequests(); | 515 void ProcessPendingStreamRequests(); |
| 511 | 516 |
| 517 // Start the DoLoop to read data from socket. |
| 518 void StartRead(); |
| 519 |
| 520 // Try to make progress by reading and processing data. |
| 521 int DoLoop(int result); |
| 522 // The implementations of STATE_DO_READ/STATE_DO_READ_COMPLETE state changes |
| 523 // of the state machine. |
| 524 int DoRead(); |
| 525 int DoReadComplete(int bytes_read); |
| 526 |
| 527 // Check if session is connected or not. |
| 528 bool IsConnected() const { |
| 529 return state_ == STATE_DO_READ || state_ == STATE_DO_READ_COMPLETE; |
| 530 } |
| 531 |
| 512 // IO Callbacks | 532 // IO Callbacks |
| 513 void OnReadComplete(int result); | 533 void OnReadComplete(int result); |
| 514 void OnWriteComplete(int result); | 534 void OnWriteComplete(int result); |
| 515 | 535 |
| 516 // Send relevant SETTINGS. This is generally called on connection setup. | 536 // Send relevant SETTINGS. This is generally called on connection setup. |
| 517 void SendInitialSettings(); | 537 void SendInitialSettings(); |
| 518 | 538 |
| 519 // Helper method to send SETTINGS a frame. | 539 // Helper method to send SETTINGS a frame. |
| 520 void SendSettings(const SettingsMap& settings); | 540 void SendSettings(const SettingsMap& settings); |
| 521 | 541 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 540 void WritePingFrame(uint32 unique_id); | 560 void WritePingFrame(uint32 unique_id); |
| 541 | 561 |
| 542 // Post a CheckPingStatus call after delay. Don't post if there is already | 562 // Post a CheckPingStatus call after delay. Don't post if there is already |
| 543 // CheckPingStatus running. | 563 // CheckPingStatus running. |
| 544 void PlanToCheckPingStatus(); | 564 void PlanToCheckPingStatus(); |
| 545 | 565 |
| 546 // Check the status of the connection. It calls |CloseSessionOnError| if we | 566 // Check the status of the connection. It calls |CloseSessionOnError| if we |
| 547 // haven't received any data in |kHungInterval| time period. | 567 // haven't received any data in |kHungInterval| time period. |
| 548 void CheckPingStatus(base::TimeTicks last_check_time); | 568 void CheckPingStatus(base::TimeTicks last_check_time); |
| 549 | 569 |
| 550 // Start reading from the socket. | |
| 551 // Returns OK on success, or an error on failure. | |
| 552 net::Error ReadSocket(); | |
| 553 | |
| 554 // Write current data to the socket. | 570 // Write current data to the socket. |
| 555 void WriteSocketLater(); | 571 void WriteSocketLater(); |
| 556 void WriteSocket(); | 572 void WriteSocket(); |
| 557 | 573 |
| 558 // Get a new stream id. | 574 // Get a new stream id. |
| 559 int GetNewStreamId(); | 575 int GetNewStreamId(); |
| 560 | 576 |
| 561 // Pushes the given frame with the given priority into the write | 577 // Pushes the given frame with the given priority into the write |
| 562 // queue for the session. | 578 // queue for the session. |
| 563 void EnqueueSessionWrite(RequestPriority priority, | 579 void EnqueueSessionWrite(RequestPriority priority, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // |spdy_session_pool_| owns us, therefore its lifetime must exceed ours. We | 731 // |spdy_session_pool_| owns us, therefore its lifetime must exceed ours. We |
| 716 // set this to NULL after we are removed from the pool. | 732 // set this to NULL after we are removed from the pool. |
| 717 SpdySessionPool* spdy_session_pool_; | 733 SpdySessionPool* spdy_session_pool_; |
| 718 HttpServerProperties* const http_server_properties_; | 734 HttpServerProperties* const http_server_properties_; |
| 719 | 735 |
| 720 // The socket handle for this session. | 736 // The socket handle for this session. |
| 721 scoped_ptr<ClientSocketHandle> connection_; | 737 scoped_ptr<ClientSocketHandle> connection_; |
| 722 | 738 |
| 723 // The read buffer used to read data from the socket. | 739 // The read buffer used to read data from the socket. |
| 724 scoped_refptr<IOBuffer> read_buffer_; | 740 scoped_refptr<IOBuffer> read_buffer_; |
| 725 bool read_pending_; | |
| 726 | 741 |
| 727 int stream_hi_water_mark_; // The next stream id to use. | 742 int stream_hi_water_mark_; // The next stream id to use. |
| 728 | 743 |
| 729 // Queue, for each priority, of pending stream requests that have | 744 // Queue, for each priority, of pending stream requests that have |
| 730 // not yet been satisfied. | 745 // not yet been satisfied. |
| 731 PendingStreamRequestQueue pending_create_stream_queues_[NUM_PRIORITIES]; | 746 PendingStreamRequestQueue pending_create_stream_queues_[NUM_PRIORITIES]; |
| 732 | 747 |
| 733 // A set of requests that are waiting to be completed (i.e., for the | 748 // A set of requests that are waiting to be completed (i.e., for the |
| 734 // stream to actually be created). This is necessary since we kick | 749 // stream to actually be created). This is necessary since we kick |
| 735 // off the stream creation asynchronously, and so the request may be | 750 // off the stream creation asynchronously, and so the request may be |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 796 |
| 782 // Limits | 797 // Limits |
| 783 size_t max_concurrent_streams_; // 0 if no limit | 798 size_t max_concurrent_streams_; // 0 if no limit |
| 784 size_t max_concurrent_streams_limit_; | 799 size_t max_concurrent_streams_limit_; |
| 785 | 800 |
| 786 // Some statistics counters for the session. | 801 // Some statistics counters for the session. |
| 787 int streams_initiated_count_; | 802 int streams_initiated_count_; |
| 788 int streams_pushed_count_; | 803 int streams_pushed_count_; |
| 789 int streams_pushed_and_claimed_count_; | 804 int streams_pushed_and_claimed_count_; |
| 790 int streams_abandoned_count_; | 805 int streams_abandoned_count_; |
| 791 int bytes_received_; | 806 |
| 807 // |total_bytes_received_| keeps track of all the bytes read by the |
| 808 // SpdySession. It is used by the |Net.SpdySettingsCwnd...| histograms. |
| 809 int total_bytes_received_; |
| 810 |
| 811 // |bytes_read_| keeps track of number of bytes read continously in the |
| 812 // DoLoop() without yielding. |
| 813 int bytes_read_; |
| 814 |
| 792 bool sent_settings_; // Did this session send settings when it started. | 815 bool sent_settings_; // Did this session send settings when it started. |
| 793 bool received_settings_; // Did this session receive at least one settings | 816 bool received_settings_; // Did this session receive at least one settings |
| 794 // frame. | 817 // frame. |
| 795 int stalled_streams_; // Count of streams that were ever stalled. | 818 int stalled_streams_; // Count of streams that were ever stalled. |
| 796 | 819 |
| 797 // Count of all pings on the wire, for which we have not gotten a response. | 820 // Count of all pings on the wire, for which we have not gotten a response. |
| 798 int64 pings_in_flight_; | 821 int64 pings_in_flight_; |
| 799 | 822 |
| 800 // This is the next ping_id (unique_id) to be sent in PING frame. | 823 // This is the next ping_id (unique_id) to be sent in PING frame. |
| 801 uint32 next_ping_id_; | 824 uint32 next_ping_id_; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 // This SPDY proxy is allowed to push resources from origins that are | 899 // This SPDY proxy is allowed to push resources from origins that are |
| 877 // different from those of their associated streams. | 900 // different from those of their associated streams. |
| 878 HostPortPair trusted_spdy_proxy_; | 901 HostPortPair trusted_spdy_proxy_; |
| 879 | 902 |
| 880 TimeFunc time_func_; | 903 TimeFunc time_func_; |
| 881 }; | 904 }; |
| 882 | 905 |
| 883 } // namespace net | 906 } // namespace net |
| 884 | 907 |
| 885 #endif // NET_SPDY_SPDY_SESSION_H_ | 908 #endif // NET_SPDY_SPDY_SESSION_H_ |
| OLD | NEW |