| 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 // This file contains some protocol structures for use with Spdy. | 5 // This file contains some protocol structures for use with Spdy. |
| 6 | 6 |
| 7 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ | 7 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ |
| 8 #define NET_SPDY_SPDY_PROTOCOL_H_ | 8 #define NET_SPDY_SPDY_PROTOCOL_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 568 } |
| 569 | 569 |
| 570 // Provides access to the frame bytes, which is a buffer containing | 570 // Provides access to the frame bytes, which is a buffer containing |
| 571 // the frame packed as expected for sending over the wire. | 571 // the frame packed as expected for sending over the wire. |
| 572 char* data() const { return reinterpret_cast<char*>(frame_); } | 572 char* data() const { return reinterpret_cast<char*>(frame_); } |
| 573 | 573 |
| 574 uint8 flags() const { return frame_->flags_length_.flags_[0]; } | 574 uint8 flags() const { return frame_->flags_length_.flags_[0]; } |
| 575 void set_flags(uint8 flags) { frame_->flags_length_.flags_[0] = flags; } | 575 void set_flags(uint8 flags) { frame_->flags_length_.flags_[0] = flags; } |
| 576 | 576 |
| 577 uint32 length() const { | 577 uint32 length() const { |
| 578 return ntohl(frame_->flags_length_.length_) & kLengthMask; | 578 return base::NetToHost32(frame_->flags_length_.length_) & kLengthMask; |
| 579 } | 579 } |
| 580 | 580 |
| 581 void set_length(uint32 length) { | 581 void set_length(uint32 length) { |
| 582 DCHECK_EQ(0u, (length & ~kLengthMask)); | 582 DCHECK_EQ(0u, (length & ~kLengthMask)); |
| 583 length = htonl(length & kLengthMask); | 583 length = base::HostToNet32(length & kLengthMask); |
| 584 frame_->flags_length_.length_ = flags() | length; | 584 frame_->flags_length_.length_ = flags() | length; |
| 585 } | 585 } |
| 586 | 586 |
| 587 bool is_control_frame() const { | 587 bool is_control_frame() const { |
| 588 return (ntohs(frame_->control_.version_) & kControlFlagMask) == | 588 return (base::NetToHost16(frame_->control_.version_) & kControlFlagMask) == |
| 589 kControlFlagMask; | 589 kControlFlagMask; |
| 590 } | 590 } |
| 591 | 591 |
| 592 // The size of the SpdyFrameBlock structure. | 592 // The size of the SpdyFrameBlock structure. |
| 593 // Every SpdyFrame* class has a static size() method for accessing | 593 // Every SpdyFrame* class has a static size() method for accessing |
| 594 // the size of the data structure which will be sent over the wire. | 594 // the size of the data structure which will be sent over the wire. |
| 595 // Note: this is not the same as sizeof(SpdyFrame). | 595 // Note: this is not the same as sizeof(SpdyFrame). |
| 596 enum { kHeaderSize = sizeof(struct SpdyFrameBlock) }; | 596 enum { kHeaderSize = sizeof(struct SpdyFrameBlock) }; |
| 597 | 597 |
| 598 protected: | 598 protected: |
| 599 SpdyFrameBlock* frame_; | 599 SpdyFrameBlock* frame_; |
| 600 | 600 |
| 601 private: | 601 private: |
| 602 bool owns_buffer_; | 602 bool owns_buffer_; |
| 603 DISALLOW_COPY_AND_ASSIGN(SpdyFrame); | 603 DISALLOW_COPY_AND_ASSIGN(SpdyFrame); |
| 604 }; | 604 }; |
| 605 | 605 |
| 606 // A Data Frame. | 606 // A Data Frame. |
| 607 class SpdyDataFrame : public SpdyFrame { | 607 class SpdyDataFrame : public SpdyFrame { |
| 608 public: | 608 public: |
| 609 SpdyDataFrame() : SpdyFrame(size()) {} | 609 SpdyDataFrame() : SpdyFrame(size()) {} |
| 610 SpdyDataFrame(char* data, bool owns_buffer) | 610 SpdyDataFrame(char* data, bool owns_buffer) |
| 611 : SpdyFrame(data, owns_buffer) {} | 611 : SpdyFrame(data, owns_buffer) {} |
| 612 | 612 |
| 613 SpdyStreamId stream_id() const { | 613 SpdyStreamId stream_id() const { |
| 614 return ntohl(frame_->data_.stream_id_) & kStreamIdMask; | 614 return base::NetToHost32(frame_->data_.stream_id_) & kStreamIdMask; |
| 615 } | 615 } |
| 616 | 616 |
| 617 // Note that setting the stream id sets the control bit to false. | 617 // Note that setting the stream id sets the control bit to false. |
| 618 // As stream id should always be set, this means the control bit | 618 // As stream id should always be set, this means the control bit |
| 619 // should always be set correctly. | 619 // should always be set correctly. |
| 620 void set_stream_id(SpdyStreamId id) { | 620 void set_stream_id(SpdyStreamId id) { |
| 621 DCHECK_EQ(0u, (id & ~kStreamIdMask)); | 621 DCHECK_EQ(0u, (id & ~kStreamIdMask)); |
| 622 frame_->data_.stream_id_ = htonl(id & kStreamIdMask); | 622 frame_->data_.stream_id_ = base::HostToNet32(id & kStreamIdMask); |
| 623 } | 623 } |
| 624 | 624 |
| 625 // Returns the size of the SpdyFrameBlock structure. | 625 // Returns the size of the SpdyFrameBlock structure. |
| 626 // Note: this is not the size of the SpdyDataFrame class. | 626 // Note: this is not the size of the SpdyDataFrame class. |
| 627 static size_t size() { return SpdyFrame::kHeaderSize; } | 627 static size_t size() { return SpdyFrame::kHeaderSize; } |
| 628 | 628 |
| 629 const char* payload() const { | 629 const char* payload() const { |
| 630 return reinterpret_cast<const char*>(frame_) + size(); | 630 return reinterpret_cast<const char*>(frame_) + size(); |
| 631 } | 631 } |
| 632 | 632 |
| 633 private: | 633 private: |
| 634 DISALLOW_COPY_AND_ASSIGN(SpdyDataFrame); | 634 DISALLOW_COPY_AND_ASSIGN(SpdyDataFrame); |
| 635 }; | 635 }; |
| 636 | 636 |
| 637 // A Control Frame. | 637 // A Control Frame. |
| 638 class SpdyControlFrame : public SpdyFrame { | 638 class SpdyControlFrame : public SpdyFrame { |
| 639 public: | 639 public: |
| 640 explicit SpdyControlFrame(size_t size) : SpdyFrame(size) {} | 640 explicit SpdyControlFrame(size_t size) : SpdyFrame(size) {} |
| 641 SpdyControlFrame(char* data, bool owns_buffer) | 641 SpdyControlFrame(char* data, bool owns_buffer) |
| 642 : SpdyFrame(data, owns_buffer) {} | 642 : SpdyFrame(data, owns_buffer) {} |
| 643 | 643 |
| 644 // Callers can use this method to check if the frame appears to be a valid | 644 // Callers can use this method to check if the frame appears to be a valid |
| 645 // frame. Does not guarantee that there are no errors. | 645 // frame. Does not guarantee that there are no errors. |
| 646 bool AppearsToBeAValidControlFrame() const { | 646 bool AppearsToBeAValidControlFrame() const { |
| 647 // Right now we only check if the frame has an out-of-bounds type. | 647 // Right now we only check if the frame has an out-of-bounds type. |
| 648 uint16 type = ntohs(block()->control_.type_); | 648 uint16 type = base::NetToHost16(block()->control_.type_); |
| 649 // NOOP is not a 'valid' control frame in SPDY/3 and beyond. | 649 // NOOP is not a 'valid' control frame in SPDY/3 and beyond. |
| 650 return type >= SYN_STREAM && | 650 return type >= SYN_STREAM && |
| 651 type < NUM_CONTROL_FRAME_TYPES && | 651 type < NUM_CONTROL_FRAME_TYPES && |
| 652 (version() == 2 || type != NOOP); | 652 (version() == 2 || type != NOOP); |
| 653 } | 653 } |
| 654 | 654 |
| 655 uint16 version() const { | 655 uint16 version() const { |
| 656 const int kVersionMask = 0x7fff; | 656 const int kVersionMask = 0x7fff; |
| 657 return ntohs(block()->control_.version_) & kVersionMask; | 657 return base::NetToHost16(block()->control_.version_) & kVersionMask; |
| 658 } | 658 } |
| 659 | 659 |
| 660 void set_version(uint16 version) { | 660 void set_version(uint16 version) { |
| 661 const uint16 kControlBit = 0x80; | 661 const uint16 kControlBit = 0x80; |
| 662 DCHECK_EQ(0, version & kControlBit); | 662 DCHECK_EQ(0, version & kControlBit); |
| 663 mutable_block()->control_.version_ = kControlBit | htons(version); | 663 mutable_block()->control_.version_ = |
| 664 kControlBit | base::HostToNet16(version); |
| 664 } | 665 } |
| 665 | 666 |
| 666 SpdyControlType type() const { | 667 SpdyControlType type() const { |
| 667 uint16 type = ntohs(block()->control_.type_); | 668 uint16 type = base::NetToHost16(block()->control_.type_); |
| 668 LOG_IF(DFATAL, type < SYN_STREAM || type >= NUM_CONTROL_FRAME_TYPES) | 669 LOG_IF(DFATAL, type < SYN_STREAM || type >= NUM_CONTROL_FRAME_TYPES) |
| 669 << "Invalid control frame type " << type; | 670 << "Invalid control frame type " << type; |
| 670 return static_cast<SpdyControlType>(type); | 671 return static_cast<SpdyControlType>(type); |
| 671 } | 672 } |
| 672 | 673 |
| 673 void set_type(SpdyControlType type) { | 674 void set_type(SpdyControlType type) { |
| 674 DCHECK(type >= SYN_STREAM && type < NUM_CONTROL_FRAME_TYPES); | 675 DCHECK(type >= SYN_STREAM && type < NUM_CONTROL_FRAME_TYPES); |
| 675 mutable_block()->control_.type_ = htons(type); | 676 mutable_block()->control_.type_ = base::HostToNet16(type); |
| 676 } | 677 } |
| 677 | 678 |
| 678 // Returns true if this control frame is of a type that has a header block, | 679 // Returns true if this control frame is of a type that has a header block, |
| 679 // otherwise it returns false. | 680 // otherwise it returns false. |
| 680 bool has_header_block() const { | 681 bool has_header_block() const { |
| 681 return type() == SYN_STREAM || type() == SYN_REPLY || type() == HEADERS; | 682 return type() == SYN_STREAM || type() == SYN_REPLY || type() == HEADERS; |
| 682 } | 683 } |
| 683 | 684 |
| 684 private: | 685 private: |
| 685 const struct SpdyFrameBlock* block() const { | 686 const struct SpdyFrameBlock* block() const { |
| 686 return frame_; | 687 return frame_; |
| 687 } | 688 } |
| 688 struct SpdyFrameBlock* mutable_block() { | 689 struct SpdyFrameBlock* mutable_block() { |
| 689 return frame_; | 690 return frame_; |
| 690 } | 691 } |
| 691 DISALLOW_COPY_AND_ASSIGN(SpdyControlFrame); | 692 DISALLOW_COPY_AND_ASSIGN(SpdyControlFrame); |
| 692 }; | 693 }; |
| 693 | 694 |
| 694 // A SYN_STREAM frame. | 695 // A SYN_STREAM frame. |
| 695 class SpdySynStreamControlFrame : public SpdyControlFrame { | 696 class SpdySynStreamControlFrame : public SpdyControlFrame { |
| 696 public: | 697 public: |
| 697 SpdySynStreamControlFrame() : SpdyControlFrame(size()) {} | 698 SpdySynStreamControlFrame() : SpdyControlFrame(size()) {} |
| 698 SpdySynStreamControlFrame(char* data, bool owns_buffer) | 699 SpdySynStreamControlFrame(char* data, bool owns_buffer) |
| 699 : SpdyControlFrame(data, owns_buffer) {} | 700 : SpdyControlFrame(data, owns_buffer) {} |
| 700 | 701 |
| 701 SpdyStreamId stream_id() const { | 702 SpdyStreamId stream_id() const { |
| 702 return ntohl(block()->stream_id_) & kStreamIdMask; | 703 return base::NetToHost32(block()->stream_id_) & kStreamIdMask; |
| 703 } | 704 } |
| 704 | 705 |
| 705 void set_stream_id(SpdyStreamId id) { | 706 void set_stream_id(SpdyStreamId id) { |
| 706 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 707 mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask); |
| 707 } | 708 } |
| 708 | 709 |
| 709 SpdyStreamId associated_stream_id() const { | 710 SpdyStreamId associated_stream_id() const { |
| 710 return ntohl(block()->associated_stream_id_) & kStreamIdMask; | 711 return base::NetToHost32(block()->associated_stream_id_) & kStreamIdMask; |
| 711 } | 712 } |
| 712 | 713 |
| 713 void set_associated_stream_id(SpdyStreamId id) { | 714 void set_associated_stream_id(SpdyStreamId id) { |
| 714 mutable_block()->associated_stream_id_ = htonl(id & kStreamIdMask); | 715 mutable_block()->associated_stream_id_ = |
| 716 base::HostToNet32(id & kStreamIdMask); |
| 715 } | 717 } |
| 716 | 718 |
| 717 SpdyPriority priority() const { | 719 SpdyPriority priority() const { |
| 718 if (version() < 3) { | 720 if (version() < 3) { |
| 719 return (block()->priority_ & kSpdy2PriorityMask) >> 6; | 721 return (block()->priority_ & kSpdy2PriorityMask) >> 6; |
| 720 } else { | 722 } else { |
| 721 return (block()->priority_ & kSpdy3PriorityMask) >> 5; | 723 return (block()->priority_ & kSpdy3PriorityMask) >> 5; |
| 722 } | 724 } |
| 723 } | 725 } |
| 724 | 726 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 746 }; | 748 }; |
| 747 | 749 |
| 748 // A SYN_REPLY frame. | 750 // A SYN_REPLY frame. |
| 749 class SpdySynReplyControlFrame : public SpdyControlFrame { | 751 class SpdySynReplyControlFrame : public SpdyControlFrame { |
| 750 public: | 752 public: |
| 751 SpdySynReplyControlFrame() : SpdyControlFrame(size()) {} | 753 SpdySynReplyControlFrame() : SpdyControlFrame(size()) {} |
| 752 SpdySynReplyControlFrame(char* data, bool owns_buffer) | 754 SpdySynReplyControlFrame(char* data, bool owns_buffer) |
| 753 : SpdyControlFrame(data, owns_buffer) {} | 755 : SpdyControlFrame(data, owns_buffer) {} |
| 754 | 756 |
| 755 SpdyStreamId stream_id() const { | 757 SpdyStreamId stream_id() const { |
| 756 return ntohl(block()->stream_id_) & kStreamIdMask; | 758 return base::NetToHost32(block()->stream_id_) & kStreamIdMask; |
| 757 } | 759 } |
| 758 | 760 |
| 759 void set_stream_id(SpdyStreamId id) { | 761 void set_stream_id(SpdyStreamId id) { |
| 760 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 762 mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask); |
| 761 } | 763 } |
| 762 | 764 |
| 763 int header_block_len() const { | 765 int header_block_len() const { |
| 764 size_t header_block_len = length() - (size() - SpdyFrame::kHeaderSize); | 766 size_t header_block_len = length() - (size() - SpdyFrame::kHeaderSize); |
| 765 // SPDY 2 had 2 bytes of unused space preceeding the header block. | 767 // SPDY 2 had 2 bytes of unused space preceeding the header block. |
| 766 if (version() < 3) { | 768 if (version() < 3) { |
| 767 header_block_len -= 2; | 769 header_block_len -= 2; |
| 768 } | 770 } |
| 769 return header_block_len; | 771 return header_block_len; |
| 770 } | 772 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 793 }; | 795 }; |
| 794 | 796 |
| 795 // A RST_STREAM frame. | 797 // A RST_STREAM frame. |
| 796 class SpdyRstStreamControlFrame : public SpdyControlFrame { | 798 class SpdyRstStreamControlFrame : public SpdyControlFrame { |
| 797 public: | 799 public: |
| 798 SpdyRstStreamControlFrame() : SpdyControlFrame(size()) {} | 800 SpdyRstStreamControlFrame() : SpdyControlFrame(size()) {} |
| 799 SpdyRstStreamControlFrame(char* data, bool owns_buffer) | 801 SpdyRstStreamControlFrame(char* data, bool owns_buffer) |
| 800 : SpdyControlFrame(data, owns_buffer) {} | 802 : SpdyControlFrame(data, owns_buffer) {} |
| 801 | 803 |
| 802 SpdyStreamId stream_id() const { | 804 SpdyStreamId stream_id() const { |
| 803 return ntohl(block()->stream_id_) & kStreamIdMask; | 805 return base::NetToHost32(block()->stream_id_) & kStreamIdMask; |
| 804 } | 806 } |
| 805 | 807 |
| 806 void set_stream_id(SpdyStreamId id) { | 808 void set_stream_id(SpdyStreamId id) { |
| 807 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 809 mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask); |
| 808 } | 810 } |
| 809 | 811 |
| 810 SpdyStatusCodes status() const { | 812 SpdyStatusCodes status() const { |
| 811 SpdyStatusCodes status = | 813 SpdyStatusCodes status = |
| 812 static_cast<SpdyStatusCodes>(ntohl(block()->status_)); | 814 static_cast<SpdyStatusCodes>(base::NetToHost32(block()->status_)); |
| 813 if (status < INVALID || status >= NUM_STATUS_CODES) { | 815 if (status < INVALID || status >= NUM_STATUS_CODES) { |
| 814 status = INVALID; | 816 status = INVALID; |
| 815 } | 817 } |
| 816 return status; | 818 return status; |
| 817 } | 819 } |
| 818 void set_status(SpdyStatusCodes status) { | 820 void set_status(SpdyStatusCodes status) { |
| 819 mutable_block()->status_ = htonl(static_cast<uint32>(status)); | 821 mutable_block()->status_ = base::HostToNet32(static_cast<uint32>(status)); |
| 820 } | 822 } |
| 821 | 823 |
| 822 // Returns the size of the SpdyRstStreamControlFrameBlock structure. | 824 // Returns the size of the SpdyRstStreamControlFrameBlock structure. |
| 823 // Note: this is not the size of the SpdyRstStreamControlFrame class. | 825 // Note: this is not the size of the SpdyRstStreamControlFrame class. |
| 824 static size_t size() { return sizeof(SpdyRstStreamControlFrameBlock); } | 826 static size_t size() { return sizeof(SpdyRstStreamControlFrameBlock); } |
| 825 | 827 |
| 826 private: | 828 private: |
| 827 const struct SpdyRstStreamControlFrameBlock* block() const { | 829 const struct SpdyRstStreamControlFrameBlock* block() const { |
| 828 return static_cast<SpdyRstStreamControlFrameBlock*>(frame_); | 830 return static_cast<SpdyRstStreamControlFrameBlock*>(frame_); |
| 829 } | 831 } |
| 830 struct SpdyRstStreamControlFrameBlock* mutable_block() { | 832 struct SpdyRstStreamControlFrameBlock* mutable_block() { |
| 831 return static_cast<SpdyRstStreamControlFrameBlock*>(frame_); | 833 return static_cast<SpdyRstStreamControlFrameBlock*>(frame_); |
| 832 } | 834 } |
| 833 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamControlFrame); | 835 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamControlFrame); |
| 834 }; | 836 }; |
| 835 | 837 |
| 836 class SpdySettingsControlFrame : public SpdyControlFrame { | 838 class SpdySettingsControlFrame : public SpdyControlFrame { |
| 837 public: | 839 public: |
| 838 SpdySettingsControlFrame() : SpdyControlFrame(size()) {} | 840 SpdySettingsControlFrame() : SpdyControlFrame(size()) {} |
| 839 SpdySettingsControlFrame(char* data, bool owns_buffer) | 841 SpdySettingsControlFrame(char* data, bool owns_buffer) |
| 840 : SpdyControlFrame(data, owns_buffer) {} | 842 : SpdyControlFrame(data, owns_buffer) {} |
| 841 | 843 |
| 842 uint32 num_entries() const { | 844 uint32 num_entries() const { |
| 843 return ntohl(block()->num_entries_); | 845 return base::NetToHost32(block()->num_entries_); |
| 844 } | 846 } |
| 845 | 847 |
| 846 void set_num_entries(int val) { | 848 void set_num_entries(int val) { |
| 847 mutable_block()->num_entries_ = htonl(val); | 849 mutable_block()->num_entries_ = base::HostToNet32(val); |
| 848 } | 850 } |
| 849 | 851 |
| 850 int header_block_len() const { | 852 int header_block_len() const { |
| 851 return length() - (size() - SpdyFrame::kHeaderSize); | 853 return length() - (size() - SpdyFrame::kHeaderSize); |
| 852 } | 854 } |
| 853 | 855 |
| 854 const char* header_block() const { | 856 const char* header_block() const { |
| 855 return reinterpret_cast<const char*>(block()) + size(); | 857 return reinterpret_cast<const char*>(block()) + size(); |
| 856 } | 858 } |
| 857 | 859 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 869 DISALLOW_COPY_AND_ASSIGN(SpdySettingsControlFrame); | 871 DISALLOW_COPY_AND_ASSIGN(SpdySettingsControlFrame); |
| 870 }; | 872 }; |
| 871 | 873 |
| 872 class SpdyPingControlFrame : public SpdyControlFrame { | 874 class SpdyPingControlFrame : public SpdyControlFrame { |
| 873 public: | 875 public: |
| 874 SpdyPingControlFrame() : SpdyControlFrame(size()) {} | 876 SpdyPingControlFrame() : SpdyControlFrame(size()) {} |
| 875 SpdyPingControlFrame(char* data, bool owns_buffer) | 877 SpdyPingControlFrame(char* data, bool owns_buffer) |
| 876 : SpdyControlFrame(data, owns_buffer) {} | 878 : SpdyControlFrame(data, owns_buffer) {} |
| 877 | 879 |
| 878 uint32 unique_id() const { | 880 uint32 unique_id() const { |
| 879 return ntohl(block()->unique_id_); | 881 return base::NetToHost32(block()->unique_id_); |
| 880 } | 882 } |
| 881 | 883 |
| 882 void set_unique_id(uint32 unique_id) { | 884 void set_unique_id(uint32 unique_id) { |
| 883 mutable_block()->unique_id_ = htonl(unique_id); | 885 mutable_block()->unique_id_ = base::HostToNet32(unique_id); |
| 884 } | 886 } |
| 885 | 887 |
| 886 static size_t size() { return sizeof(SpdyPingControlFrameBlock); } | 888 static size_t size() { return sizeof(SpdyPingControlFrameBlock); } |
| 887 | 889 |
| 888 private: | 890 private: |
| 889 const struct SpdyPingControlFrameBlock* block() const { | 891 const struct SpdyPingControlFrameBlock* block() const { |
| 890 return static_cast<SpdyPingControlFrameBlock*>(frame_); | 892 return static_cast<SpdyPingControlFrameBlock*>(frame_); |
| 891 } | 893 } |
| 892 struct SpdyPingControlFrameBlock* mutable_block() { | 894 struct SpdyPingControlFrameBlock* mutable_block() { |
| 893 return static_cast<SpdyPingControlFrameBlock*>(frame_); | 895 return static_cast<SpdyPingControlFrameBlock*>(frame_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 913 DISALLOW_COPY_AND_ASSIGN(SpdyCredentialControlFrame); | 915 DISALLOW_COPY_AND_ASSIGN(SpdyCredentialControlFrame); |
| 914 }; | 916 }; |
| 915 | 917 |
| 916 class SpdyGoAwayControlFrame : public SpdyControlFrame { | 918 class SpdyGoAwayControlFrame : public SpdyControlFrame { |
| 917 public: | 919 public: |
| 918 SpdyGoAwayControlFrame() : SpdyControlFrame(size()) {} | 920 SpdyGoAwayControlFrame() : SpdyControlFrame(size()) {} |
| 919 SpdyGoAwayControlFrame(char* data, bool owns_buffer) | 921 SpdyGoAwayControlFrame(char* data, bool owns_buffer) |
| 920 : SpdyControlFrame(data, owns_buffer) {} | 922 : SpdyControlFrame(data, owns_buffer) {} |
| 921 | 923 |
| 922 SpdyStreamId last_accepted_stream_id() const { | 924 SpdyStreamId last_accepted_stream_id() const { |
| 923 return ntohl(block()->last_accepted_stream_id_) & kStreamIdMask; | 925 return base::NetToHost32(block()->last_accepted_stream_id_) & kStreamIdMask; |
| 924 } | 926 } |
| 925 | 927 |
| 926 void set_last_accepted_stream_id(SpdyStreamId id) { | 928 void set_last_accepted_stream_id(SpdyStreamId id) { |
| 927 mutable_block()->last_accepted_stream_id_ = htonl(id & kStreamIdMask); | 929 mutable_block()->last_accepted_stream_id_ = |
| 930 base::HostToNet32(id & kStreamIdMask); |
| 928 } | 931 } |
| 929 | 932 |
| 930 static size_t size() { return sizeof(SpdyGoAwayControlFrameBlock); } | 933 static size_t size() { return sizeof(SpdyGoAwayControlFrameBlock); } |
| 931 | 934 |
| 932 private: | 935 private: |
| 933 const struct SpdyGoAwayControlFrameBlock* block() const { | 936 const struct SpdyGoAwayControlFrameBlock* block() const { |
| 934 return static_cast<SpdyGoAwayControlFrameBlock*>(frame_); | 937 return static_cast<SpdyGoAwayControlFrameBlock*>(frame_); |
| 935 } | 938 } |
| 936 struct SpdyGoAwayControlFrameBlock* mutable_block() { | 939 struct SpdyGoAwayControlFrameBlock* mutable_block() { |
| 937 return static_cast<SpdyGoAwayControlFrameBlock*>(frame_); | 940 return static_cast<SpdyGoAwayControlFrameBlock*>(frame_); |
| 938 } | 941 } |
| 939 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayControlFrame); | 942 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayControlFrame); |
| 940 }; | 943 }; |
| 941 | 944 |
| 942 // A HEADERS frame. | 945 // A HEADERS frame. |
| 943 class SpdyHeadersControlFrame : public SpdyControlFrame { | 946 class SpdyHeadersControlFrame : public SpdyControlFrame { |
| 944 public: | 947 public: |
| 945 SpdyHeadersControlFrame() : SpdyControlFrame(size()) {} | 948 SpdyHeadersControlFrame() : SpdyControlFrame(size()) {} |
| 946 SpdyHeadersControlFrame(char* data, bool owns_buffer) | 949 SpdyHeadersControlFrame(char* data, bool owns_buffer) |
| 947 : SpdyControlFrame(data, owns_buffer) {} | 950 : SpdyControlFrame(data, owns_buffer) {} |
| 948 | 951 |
| 949 SpdyStreamId stream_id() const { | 952 SpdyStreamId stream_id() const { |
| 950 return ntohl(block()->stream_id_) & kStreamIdMask; | 953 return base::NetToHost32(block()->stream_id_) & kStreamIdMask; |
| 951 } | 954 } |
| 952 | 955 |
| 953 void set_stream_id(SpdyStreamId id) { | 956 void set_stream_id(SpdyStreamId id) { |
| 954 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 957 mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask); |
| 955 } | 958 } |
| 956 | 959 |
| 957 // The number of bytes in the header block beyond the frame header length. | 960 // The number of bytes in the header block beyond the frame header length. |
| 958 int header_block_len() const { | 961 int header_block_len() const { |
| 959 size_t header_block_len = length() - (size() - SpdyFrame::kHeaderSize); | 962 size_t header_block_len = length() - (size() - SpdyFrame::kHeaderSize); |
| 960 // SPDY 2 had 2 bytes of unused space preceeding the header block. | 963 // SPDY 2 had 2 bytes of unused space preceeding the header block. |
| 961 if (version() < 3) { | 964 if (version() < 3) { |
| 962 header_block_len -= 2; | 965 header_block_len -= 2; |
| 963 } | 966 } |
| 964 return header_block_len; | 967 return header_block_len; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 988 }; | 991 }; |
| 989 | 992 |
| 990 // A WINDOW_UPDATE frame. | 993 // A WINDOW_UPDATE frame. |
| 991 class SpdyWindowUpdateControlFrame : public SpdyControlFrame { | 994 class SpdyWindowUpdateControlFrame : public SpdyControlFrame { |
| 992 public: | 995 public: |
| 993 SpdyWindowUpdateControlFrame() : SpdyControlFrame(size()) {} | 996 SpdyWindowUpdateControlFrame() : SpdyControlFrame(size()) {} |
| 994 SpdyWindowUpdateControlFrame(char* data, bool owns_buffer) | 997 SpdyWindowUpdateControlFrame(char* data, bool owns_buffer) |
| 995 : SpdyControlFrame(data, owns_buffer) {} | 998 : SpdyControlFrame(data, owns_buffer) {} |
| 996 | 999 |
| 997 SpdyStreamId stream_id() const { | 1000 SpdyStreamId stream_id() const { |
| 998 return ntohl(block()->stream_id_) & kStreamIdMask; | 1001 return base::NetToHost32(block()->stream_id_) & kStreamIdMask; |
| 999 } | 1002 } |
| 1000 | 1003 |
| 1001 void set_stream_id(SpdyStreamId id) { | 1004 void set_stream_id(SpdyStreamId id) { |
| 1002 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 1005 mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask); |
| 1003 } | 1006 } |
| 1004 | 1007 |
| 1005 uint32 delta_window_size() const { | 1008 uint32 delta_window_size() const { |
| 1006 return ntohl(block()->delta_window_size_); | 1009 return base::NetToHost32(block()->delta_window_size_); |
| 1007 } | 1010 } |
| 1008 | 1011 |
| 1009 void set_delta_window_size(uint32 delta_window_size) { | 1012 void set_delta_window_size(uint32 delta_window_size) { |
| 1010 mutable_block()->delta_window_size_ = htonl(delta_window_size); | 1013 mutable_block()->delta_window_size_ = base::HostToNet32(delta_window_size); |
| 1011 } | 1014 } |
| 1012 | 1015 |
| 1013 // Returns the size of the SpdyWindowUpdateControlFrameBlock structure. | 1016 // Returns the size of the SpdyWindowUpdateControlFrameBlock structure. |
| 1014 // Note: this is not the size of the SpdyWindowUpdateControlFrame class. | 1017 // Note: this is not the size of the SpdyWindowUpdateControlFrame class. |
| 1015 static size_t size() { return sizeof(SpdyWindowUpdateControlFrameBlock); } | 1018 static size_t size() { return sizeof(SpdyWindowUpdateControlFrameBlock); } |
| 1016 | 1019 |
| 1017 private: | 1020 private: |
| 1018 const struct SpdyWindowUpdateControlFrameBlock* block() const { | 1021 const struct SpdyWindowUpdateControlFrameBlock* block() const { |
| 1019 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); | 1022 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); |
| 1020 } | 1023 } |
| 1021 struct SpdyWindowUpdateControlFrameBlock* mutable_block() { | 1024 struct SpdyWindowUpdateControlFrameBlock* mutable_block() { |
| 1022 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); | 1025 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); |
| 1023 } | 1026 } |
| 1024 | 1027 |
| 1025 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateControlFrame); | 1028 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateControlFrame); |
| 1026 }; | 1029 }; |
| 1027 | 1030 |
| 1028 } // namespace spdy | 1031 } // namespace spdy |
| 1029 | 1032 |
| 1030 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 1033 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
| OLD | NEW |