OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 DCHECK_EQ(0u, (length & ~kLengthMask)); | 376 DCHECK_EQ(0u, (length & ~kLengthMask)); |
377 length = htonl(length & kLengthMask); | 377 length = htonl(length & kLengthMask); |
378 frame_->flags_length_.length_ = flags() | length; | 378 frame_->flags_length_.length_ = flags() | length; |
379 } | 379 } |
380 | 380 |
381 bool is_control_frame() const { | 381 bool is_control_frame() const { |
382 return (ntohs(frame_->control_.version_) & kControlFlagMask) == | 382 return (ntohs(frame_->control_.version_) & kControlFlagMask) == |
383 kControlFlagMask; | 383 kControlFlagMask; |
384 } | 384 } |
385 | 385 |
386 // Returns the size of the SpdyFrameBlock structure. | 386 // The size of the SpdyFrameBlock structure. |
387 // Every SpdyFrame* class has a static size() method for accessing | 387 // Every SpdyFrame* class has a static size() method for accessing |
388 // the size of the data structure which will be sent over the wire. | 388 // the size of the data structure which will be sent over the wire. |
389 // Note: this is not the same as sizeof(SpdyFrame). | 389 // Note: this is not the same as sizeof(SpdyFrame). |
390 static size_t size() { return sizeof(struct SpdyFrameBlock); } | 390 enum { kHeaderSize = sizeof(struct SpdyFrameBlock) }; |
391 | 391 |
392 protected: | 392 protected: |
393 SpdyFrameBlock* frame_; | 393 SpdyFrameBlock* frame_; |
394 | 394 |
395 private: | 395 private: |
396 bool owns_buffer_; | 396 bool owns_buffer_; |
397 DISALLOW_COPY_AND_ASSIGN(SpdyFrame); | 397 DISALLOW_COPY_AND_ASSIGN(SpdyFrame); |
398 }; | 398 }; |
399 | 399 |
400 // A Data Frame. | 400 // A Data Frame. |
(...skipping 10 matching lines...) Expand all Loading... |
411 // Note that setting the stream id sets the control bit to false. | 411 // Note that setting the stream id sets the control bit to false. |
412 // As stream id should always be set, this means the control bit | 412 // As stream id should always be set, this means the control bit |
413 // should always be set correctly. | 413 // should always be set correctly. |
414 void set_stream_id(SpdyStreamId id) { | 414 void set_stream_id(SpdyStreamId id) { |
415 DCHECK_EQ(0u, (id & ~kStreamIdMask)); | 415 DCHECK_EQ(0u, (id & ~kStreamIdMask)); |
416 frame_->data_.stream_id_ = htonl(id & kStreamIdMask); | 416 frame_->data_.stream_id_ = htonl(id & kStreamIdMask); |
417 } | 417 } |
418 | 418 |
419 // Returns the size of the SpdyFrameBlock structure. | 419 // Returns the size of the SpdyFrameBlock structure. |
420 // Note: this is not the size of the SpdyDataFrame class. | 420 // Note: this is not the size of the SpdyDataFrame class. |
421 static size_t size() { return SpdyFrame::size(); } | 421 static size_t size() { return SpdyFrame::kHeaderSize; } |
422 | 422 |
423 const char* payload() const { | 423 const char* payload() const { |
424 return reinterpret_cast<const char*>(frame_) + size(); | 424 return reinterpret_cast<const char*>(frame_) + size(); |
425 } | 425 } |
426 | 426 |
427 private: | 427 private: |
428 DISALLOW_COPY_AND_ASSIGN(SpdyDataFrame); | 428 DISALLOW_COPY_AND_ASSIGN(SpdyDataFrame); |
429 }; | 429 }; |
430 | 430 |
431 // A Control Frame. | 431 // A Control Frame. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 void set_associated_stream_id(SpdyStreamId id) { | 515 void set_associated_stream_id(SpdyStreamId id) { |
516 mutable_block()->associated_stream_id_ = htonl(id & kStreamIdMask); | 516 mutable_block()->associated_stream_id_ = htonl(id & kStreamIdMask); |
517 } | 517 } |
518 | 518 |
519 SpdyPriority priority() const { | 519 SpdyPriority priority() const { |
520 return (block()->priority_ & kPriorityMask) >> 6; | 520 return (block()->priority_ & kPriorityMask) >> 6; |
521 } | 521 } |
522 | 522 |
523 // The number of bytes in the header block beyond the frame header length. | 523 // The number of bytes in the header block beyond the frame header length. |
524 int header_block_len() const { | 524 int header_block_len() const { |
525 return length() - (size() - SpdyFrame::size()); | 525 return length() - (size() - SpdyFrame::kHeaderSize); |
526 } | 526 } |
527 | 527 |
528 const char* header_block() const { | 528 const char* header_block() const { |
529 return reinterpret_cast<const char*>(block()) + size(); | 529 return reinterpret_cast<const char*>(block()) + size(); |
530 } | 530 } |
531 | 531 |
532 // Returns the size of the SpdySynStreamControlFrameBlock structure. | 532 // Returns the size of the SpdySynStreamControlFrameBlock structure. |
533 // Note: this is not the size of the SpdySynStreamControlFrame class. | 533 // Note: this is not the size of the SpdySynStreamControlFrame class. |
534 static size_t size() { return sizeof(SpdySynStreamControlFrameBlock); } | 534 static size_t size() { return sizeof(SpdySynStreamControlFrameBlock); } |
535 | 535 |
(...skipping 16 matching lines...) Expand all Loading... |
552 | 552 |
553 SpdyStreamId stream_id() const { | 553 SpdyStreamId stream_id() const { |
554 return ntohl(block()->stream_id_) & kStreamIdMask; | 554 return ntohl(block()->stream_id_) & kStreamIdMask; |
555 } | 555 } |
556 | 556 |
557 void set_stream_id(SpdyStreamId id) { | 557 void set_stream_id(SpdyStreamId id) { |
558 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 558 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); |
559 } | 559 } |
560 | 560 |
561 int header_block_len() const { | 561 int header_block_len() const { |
562 return length() - (size() - SpdyFrame::size()); | 562 return length() - (size() - SpdyFrame::kHeaderSize); |
563 } | 563 } |
564 | 564 |
565 const char* header_block() const { | 565 const char* header_block() const { |
566 return reinterpret_cast<const char*>(block()) + size(); | 566 return reinterpret_cast<const char*>(block()) + size(); |
567 } | 567 } |
568 | 568 |
569 // Returns the size of the SpdySynReplyControlFrameBlock structure. | 569 // Returns the size of the SpdySynReplyControlFrameBlock structure. |
570 // Note: this is not the size of the SpdySynReplyControlFrame class. | 570 // Note: this is not the size of the SpdySynReplyControlFrame class. |
571 static size_t size() { return sizeof(SpdySynReplyControlFrameBlock); } | 571 static size_t size() { return sizeof(SpdySynReplyControlFrameBlock); } |
572 | 572 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 | 629 |
630 uint32 num_entries() const { | 630 uint32 num_entries() const { |
631 return ntohl(block()->num_entries_); | 631 return ntohl(block()->num_entries_); |
632 } | 632 } |
633 | 633 |
634 void set_num_entries(int val) { | 634 void set_num_entries(int val) { |
635 mutable_block()->num_entries_ = htonl(val); | 635 mutable_block()->num_entries_ = htonl(val); |
636 } | 636 } |
637 | 637 |
638 int header_block_len() const { | 638 int header_block_len() const { |
639 return length() - (size() - SpdyFrame::size()); | 639 return length() - (size() - SpdyFrame::kHeaderSize); |
640 } | 640 } |
641 | 641 |
642 const char* header_block() const { | 642 const char* header_block() const { |
643 return reinterpret_cast<const char*>(block()) + size(); | 643 return reinterpret_cast<const char*>(block()) + size(); |
644 } | 644 } |
645 | 645 |
646 // Returns the size of the SpdySettingsControlFrameBlock structure. | 646 // Returns the size of the SpdySettingsControlFrameBlock structure. |
647 // Note: this is not the size of the SpdySettingsControlFrameBlock class. | 647 // Note: this is not the size of the SpdySettingsControlFrameBlock class. |
648 static size_t size() { return sizeof(SpdySettingsControlFrameBlock); } | 648 static size_t size() { return sizeof(SpdySettingsControlFrameBlock); } |
649 | 649 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 SpdyStreamId stream_id() const { | 727 SpdyStreamId stream_id() const { |
728 return ntohl(block()->stream_id_) & kStreamIdMask; | 728 return ntohl(block()->stream_id_) & kStreamIdMask; |
729 } | 729 } |
730 | 730 |
731 void set_stream_id(SpdyStreamId id) { | 731 void set_stream_id(SpdyStreamId id) { |
732 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 732 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); |
733 } | 733 } |
734 | 734 |
735 // The number of bytes in the header block beyond the frame header length. | 735 // The number of bytes in the header block beyond the frame header length. |
736 int header_block_len() const { | 736 int header_block_len() const { |
737 return length() - (size() - SpdyFrame::size()); | 737 return length() - (size() - SpdyFrame::kHeaderSize); |
738 } | 738 } |
739 | 739 |
740 const char* header_block() const { | 740 const char* header_block() const { |
741 return reinterpret_cast<const char*>(block()) + size(); | 741 return reinterpret_cast<const char*>(block()) + size(); |
742 } | 742 } |
743 | 743 |
744 // Returns the size of the SpdyHeadersControlFrameBlock structure. | 744 // Returns the size of the SpdyHeadersControlFrameBlock structure. |
745 // Note: this is not the size of the SpdyHeadersControlFrame class. | 745 // Note: this is not the size of the SpdyHeadersControlFrame class. |
746 static size_t size() { return sizeof(SpdyHeadersControlFrameBlock); } | 746 static size_t size() { return sizeof(SpdyHeadersControlFrameBlock); } |
747 | 747 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 struct SpdyWindowUpdateControlFrameBlock* mutable_block() { | 789 struct SpdyWindowUpdateControlFrameBlock* mutable_block() { |
790 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); | 790 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); |
791 } | 791 } |
792 | 792 |
793 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateControlFrame); | 793 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateControlFrame); |
794 }; | 794 }; |
795 | 795 |
796 } // namespace spdy | 796 } // namespace spdy |
797 | 797 |
798 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 798 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
OLD | NEW |