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