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