| 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 25 matching lines...) Expand all Loading... |
| 36 // This is somewhat arbitrary and not really fixed, but it will always work | 36 // This is somewhat arbitrary and not really fixed, but it will always work |
| 37 // reasonably with ethernet. Chop the world into 2-packet chunks. This is | 37 // reasonably with ethernet. Chop the world into 2-packet chunks. This is |
| 38 // somewhat arbitrary, but is reasonably small and ensures that we elicit | 38 // somewhat arbitrary, but is reasonably small and ensures that we elicit |
| 39 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). | 39 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). |
| 40 const int kMss = 1430; | 40 const int kMss = 1430; |
| 41 const int kMaxSpdyFrameChunkSize = (2 * kMss) - SpdyFrame::kHeaderSize; | 41 const int kMaxSpdyFrameChunkSize = (2 * kMss) - SpdyFrame::kHeaderSize; |
| 42 | 42 |
| 43 // Specifies the maxiumum concurrent streams server could send (via push). | 43 // Specifies the maxiumum concurrent streams server could send (via push). |
| 44 const int kMaxConcurrentPushedStreams = 1000; | 44 const int kMaxConcurrentPushedStreams = 1000; |
| 45 | 45 |
| 46 // Specifies the number of bytes read synchronously (without yielding) if the |
| 47 // data is available. |
| 48 const int kMaxReadBytes = 32 * 1024; |
| 49 |
| 46 class BoundNetLog; | 50 class BoundNetLog; |
| 47 struct LoadTimingInfo; | 51 struct LoadTimingInfo; |
| 48 class SpdyStream; | 52 class SpdyStream; |
| 49 class SSLInfo; | 53 class SSLInfo; |
| 50 | 54 |
| 51 enum SpdyProtocolErrorDetails { | 55 enum SpdyProtocolErrorDetails { |
| 52 // SpdyFramer::SpdyErrors | 56 // SpdyFramer::SpdyErrors |
| 53 SPDY_ERROR_NO_ERROR, | 57 SPDY_ERROR_NO_ERROR, |
| 54 SPDY_ERROR_INVALID_CONTROL_FRAME, | 58 SPDY_ERROR_INVALID_CONTROL_FRAME, |
| 55 SPDY_ERROR_CONTROL_PAYLOAD_TOO_LARGE, | 59 SPDY_ERROR_CONTROL_PAYLOAD_TOO_LARGE, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 262 |
| 259 // Returns the ServerBoundCertService used by this Socket, or NULL | 263 // Returns the ServerBoundCertService used by this Socket, or NULL |
| 260 // if server bound certs are not supported in this session. | 264 // if server bound certs are not supported in this session. |
| 261 ServerBoundCertService* GetServerBoundCertService() const; | 265 ServerBoundCertService* GetServerBoundCertService() const; |
| 262 | 266 |
| 263 // Send WINDOW_UPDATE frame, called by a stream whenever receive window | 267 // Send WINDOW_UPDATE frame, called by a stream whenever receive window |
| 264 // size is increased. | 268 // size is increased. |
| 265 void SendWindowUpdate(SpdyStreamId stream_id, int32 delta_window_size); | 269 void SendWindowUpdate(SpdyStreamId stream_id, int32 delta_window_size); |
| 266 | 270 |
| 267 // If session is closed, no new streams/transactions should be created. | 271 // If session is closed, no new streams/transactions should be created. |
| 268 bool IsClosed() const { return state_ == CLOSED; } | 272 bool IsClosed() const { return state_ == STATE_CLOSED; } |
| 269 | 273 |
| 270 // Closes this session. This will close all active streams and mark | 274 // Closes this session. This will close all active streams and mark |
| 271 // the session as permanently closed. | 275 // the session as permanently closed. |
| 272 // |err| should not be OK; this function is intended to be called on | 276 // |err| should not be OK; this function is intended to be called on |
| 273 // error. | 277 // error. |
| 274 // |remove_from_pool| indicates whether to also remove the session from the | 278 // |remove_from_pool| indicates whether to also remove the session from the |
| 275 // session pool. | 279 // session pool. |
| 276 // |description| indicates the reason for the error. | 280 // |description| indicates the reason for the error. |
| 277 void CloseSessionOnError(net::Error err, | 281 void CloseSessionOnError(net::Error err, |
| 278 bool remove_from_pool, | 282 bool remove_from_pool, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 ~CallbackResultPair(); | 414 ~CallbackResultPair(); |
| 411 | 415 |
| 412 CompletionCallback callback; | 416 CompletionCallback callback; |
| 413 int result; | 417 int result; |
| 414 }; | 418 }; |
| 415 | 419 |
| 416 typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair> | 420 typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair> |
| 417 PendingCallbackMap; | 421 PendingCallbackMap; |
| 418 | 422 |
| 419 enum State { | 423 enum State { |
| 420 IDLE, | 424 STATE_IDLE, |
| 421 CONNECTING, | 425 STATE_CONNECTING, |
| 422 CONNECTED, | 426 STATE_DO_READ, |
| 423 CLOSED | 427 STATE_DO_READ_COMPLETE, |
| 428 STATE_CLOSED |
| 424 }; | 429 }; |
| 425 | 430 |
| 426 virtual ~SpdySession(); | 431 virtual ~SpdySession(); |
| 427 | 432 |
| 428 void ProcessPendingCreateStreams(); | 433 void ProcessPendingCreateStreams(); |
| 429 int CreateStreamImpl( | 434 int CreateStreamImpl( |
| 430 const GURL& url, | 435 const GURL& url, |
| 431 RequestPriority priority, | 436 RequestPriority priority, |
| 432 scoped_refptr<SpdyStream>* spdy_stream, | 437 scoped_refptr<SpdyStream>* spdy_stream, |
| 433 const BoundNetLog& stream_net_log); | 438 const BoundNetLog& stream_net_log); |
| 434 | 439 |
| 440 // Start the DoLoop to read data from socket. |
| 441 void StartRead(); |
| 442 |
| 443 // Try to make progress by reading and processing data. |
| 444 int DoLoop(int result); |
| 445 // The implementations of STATE_DO_READ/STATE_DO_READ_COMPLETE state changes |
| 446 // of the state machine. |
| 447 int DoRead(); |
| 448 int DoReadComplete(int bytes_read); |
| 449 |
| 450 // Check if session is connected or not. |
| 451 bool IsConnected() const { |
| 452 return state_ == STATE_DO_READ || state_ == STATE_DO_READ_COMPLETE; |
| 453 } |
| 454 |
| 435 // IO Callbacks | 455 // IO Callbacks |
| 436 void OnReadComplete(int result); | 456 void OnReadComplete(int result); |
| 437 void OnWriteComplete(int result); | 457 void OnWriteComplete(int result); |
| 438 | 458 |
| 439 // Send relevant SETTINGS. This is generally called on connection setup. | 459 // Send relevant SETTINGS. This is generally called on connection setup. |
| 440 void SendInitialSettings(); | 460 void SendInitialSettings(); |
| 441 | 461 |
| 442 // Helper method to send SETTINGS a frame. | 462 // Helper method to send SETTINGS a frame. |
| 443 void SendSettings(const SettingsMap& settings); | 463 void SendSettings(const SettingsMap& settings); |
| 444 | 464 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 459 void WritePingFrame(uint32 unique_id); | 479 void WritePingFrame(uint32 unique_id); |
| 460 | 480 |
| 461 // Post a CheckPingStatus call after delay. Don't post if there is already | 481 // Post a CheckPingStatus call after delay. Don't post if there is already |
| 462 // CheckPingStatus running. | 482 // CheckPingStatus running. |
| 463 void PlanToCheckPingStatus(); | 483 void PlanToCheckPingStatus(); |
| 464 | 484 |
| 465 // Check the status of the connection. It calls |CloseSessionOnError| if we | 485 // Check the status of the connection. It calls |CloseSessionOnError| if we |
| 466 // haven't received any data in |kHungInterval| time period. | 486 // haven't received any data in |kHungInterval| time period. |
| 467 void CheckPingStatus(base::TimeTicks last_check_time); | 487 void CheckPingStatus(base::TimeTicks last_check_time); |
| 468 | 488 |
| 469 // Start reading from the socket. | |
| 470 // Returns OK on success, or an error on failure. | |
| 471 net::Error ReadSocket(); | |
| 472 | |
| 473 // Write current data to the socket. | 489 // Write current data to the socket. |
| 474 void WriteSocketLater(); | 490 void WriteSocketLater(); |
| 475 void WriteSocket(); | 491 void WriteSocket(); |
| 476 | 492 |
| 477 // Get a new stream id. | 493 // Get a new stream id. |
| 478 int GetNewStreamId(); | 494 int GetNewStreamId(); |
| 479 | 495 |
| 480 // Queue a frame for sending. | 496 // Queue a frame for sending. |
| 481 // |frame| is the frame to send. | 497 // |frame| is the frame to send. |
| 482 // |priority| is the priority for insertion into the queue. | 498 // |priority| is the priority for insertion into the queue. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 676 |
| 661 // Limits | 677 // Limits |
| 662 size_t max_concurrent_streams_; // 0 if no limit | 678 size_t max_concurrent_streams_; // 0 if no limit |
| 663 size_t max_concurrent_streams_limit_; | 679 size_t max_concurrent_streams_limit_; |
| 664 | 680 |
| 665 // Some statistics counters for the session. | 681 // Some statistics counters for the session. |
| 666 int streams_initiated_count_; | 682 int streams_initiated_count_; |
| 667 int streams_pushed_count_; | 683 int streams_pushed_count_; |
| 668 int streams_pushed_and_claimed_count_; | 684 int streams_pushed_and_claimed_count_; |
| 669 int streams_abandoned_count_; | 685 int streams_abandoned_count_; |
| 670 int bytes_received_; | 686 |
| 687 // |total_bytes_received_| keeps track of all the bytes read by the |
| 688 // SpdySession. It is used by the |Net.SpdySettingsCwnd...| histograms. |
| 689 int total_bytes_received_; |
| 690 |
| 691 // |bytes_read_| keeps track of number of bytes read continously in the |
| 692 // DoLoop() without yielding. |
| 693 int bytes_read_; |
| 694 |
| 671 bool sent_settings_; // Did this session send settings when it started. | 695 bool sent_settings_; // Did this session send settings when it started. |
| 672 bool received_settings_; // Did this session receive at least one settings | 696 bool received_settings_; // Did this session receive at least one settings |
| 673 // frame. | 697 // frame. |
| 674 int stalled_streams_; // Count of streams that were ever stalled. | 698 int stalled_streams_; // Count of streams that were ever stalled. |
| 675 | 699 |
| 676 // Count of all pings on the wire, for which we have not gotten a response. | 700 // Count of all pings on the wire, for which we have not gotten a response. |
| 677 int64 pings_in_flight_; | 701 int64 pings_in_flight_; |
| 678 | 702 |
| 679 // This is the next ping_id (unique_id) to be sent in PING frame. | 703 // This is the next ping_id (unique_id) to be sent in PING frame. |
| 680 uint32 next_ping_id_; | 704 uint32 next_ping_id_; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 // This SPDY proxy is allowed to push resources from origins that are | 768 // This SPDY proxy is allowed to push resources from origins that are |
| 745 // different from those of their associated streams. | 769 // different from those of their associated streams. |
| 746 HostPortPair trusted_spdy_proxy_; | 770 HostPortPair trusted_spdy_proxy_; |
| 747 | 771 |
| 748 TimeFunc time_func_; | 772 TimeFunc time_func_; |
| 749 }; | 773 }; |
| 750 | 774 |
| 751 } // namespace net | 775 } // namespace net |
| 752 | 776 |
| 753 #endif // NET_SPDY_SPDY_SESSION_H_ | 777 #endif // NET_SPDY_SPDY_SESSION_H_ |
| OLD | NEW |