Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: net/spdy/spdy_framer.h

Issue 2753043002: Create new versions of SerializeXXX() functions that uses pre-allocated buffer in SpdyFrameBuilder. (Closed)
Patch Set: git cl format Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_frame_builder.cc ('k') | net/spdy/spdy_framer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_FRAMER_H_ 5 #ifndef NET_SPDY_SPDY_FRAMER_H_
6 #define NET_SPDY_SPDY_FRAMER_H_ 6 #define NET_SPDY_SPDY_FRAMER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <cstdint> 11 #include <cstdint>
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <string> 14 #include <string>
15 #include <utility> 15 #include <utility>
16 16
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "base/sys_byteorder.h" 18 #include "base/sys_byteorder.h"
19 #include "net/base/net_export.h" 19 #include "net/base/net_export.h"
20 #include "net/spdy/hpack/hpack_decoder_interface.h" 20 #include "net/spdy/hpack/hpack_decoder_interface.h"
21 #include "net/spdy/hpack/hpack_encoder.h" 21 #include "net/spdy/hpack/hpack_encoder.h"
22 #include "net/spdy/spdy_alt_svc_wire_format.h" 22 #include "net/spdy/spdy_alt_svc_wire_format.h"
23 #include "net/spdy/spdy_flags.h" 23 #include "net/spdy/spdy_flags.h"
24 #include "net/spdy/spdy_header_block.h" 24 #include "net/spdy/spdy_header_block.h"
25 #include "net/spdy/spdy_headers_handler_interface.h" 25 #include "net/spdy/spdy_headers_handler_interface.h"
26 #include "net/spdy/spdy_protocol.h" 26 #include "net/spdy/spdy_protocol.h"
27 #include "net/spdy/zero_copy_output_buffer.h"
27 28
28 namespace net { 29 namespace net {
29 30
30 class HttpProxyClientSocketPoolTest; 31 class HttpProxyClientSocketPoolTest;
31 class HttpNetworkLayer; 32 class HttpNetworkLayer;
32 class HttpNetworkTransactionTest; 33 class HttpNetworkTransactionTest;
33 class SpdyHttpStreamTest; 34 class SpdyHttpStreamTest;
34 class SpdyNetworkTransactionTest; 35 class SpdyNetworkTransactionTest;
35 class SpdyProxyClientSocketTest; 36 class SpdyProxyClientSocketTest;
36 class SpdySessionTest; 37 class SpdySessionTest;
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // availability of an alternative service to the client. 464 // availability of an alternative service to the client.
464 SpdySerializedFrame SerializeAltSvc(const SpdyAltSvcIR& altsvc); 465 SpdySerializedFrame SerializeAltSvc(const SpdyAltSvcIR& altsvc);
465 466
466 // Serializes a PRIORITY frame. The PRIORITY frame advises a change in 467 // Serializes a PRIORITY frame. The PRIORITY frame advises a change in
467 // the relative priority of the given stream. 468 // the relative priority of the given stream.
468 SpdySerializedFrame SerializePriority(const SpdyPriorityIR& priority) const; 469 SpdySerializedFrame SerializePriority(const SpdyPriorityIR& priority) const;
469 470
470 // Serialize a frame of unknown type. 471 // Serialize a frame of unknown type.
471 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame); 472 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame);
472 473
474 // Serialize a data frame.
475 bool SerializeData(const SpdyDataIR& data,
476 ZeroCopyOutputBuffer* output) const;
477
478 // Serializes the data frame header and optionally padding length fields,
479 // excluding actual data payload and padding.
480 bool SerializeDataFrameHeaderWithPaddingLengthField(
481 const SpdyDataIR& data,
482 ZeroCopyOutputBuffer* output) const;
483
484 bool SerializeRstStream(const SpdyRstStreamIR& rst_stream,
485 ZeroCopyOutputBuffer* output) const;
486
487 // Serializes a SETTINGS frame. The SETTINGS frame is
488 // used to communicate name/value pairs relevant to the communication channel.
489 bool SerializeSettings(const SpdySettingsIR& settings,
490 ZeroCopyOutputBuffer* output) const;
491
492 // Serializes a PING frame. The unique_id is used to
493 // identify the ping request/response.
494 bool SerializePing(const SpdyPingIR& ping,
495 ZeroCopyOutputBuffer* output) const;
496
497 // Serializes a GOAWAY frame. The GOAWAY frame is used
498 // prior to the shutting down of the TCP connection, and includes the
499 // stream_id of the last stream the sender of the frame is willing to process
500 // to completion.
501 bool SerializeGoAway(const SpdyGoAwayIR& goaway,
502 ZeroCopyOutputBuffer* output) const;
503
504 // Serializes a HEADERS frame. The HEADERS frame is used
505 // for sending headers.
506 bool SerializeHeaders(const SpdyHeadersIR& headers,
507 ZeroCopyOutputBuffer* output);
508
509 // Serializes a WINDOW_UPDATE frame. The WINDOW_UPDATE
510 // frame is used to implement per stream flow control.
511 bool SerializeWindowUpdate(const SpdyWindowUpdateIR& window_update,
512 ZeroCopyOutputBuffer* output) const;
513
514 // Serializes a BLOCKED frame. The BLOCKED frame is used to
515 // indicate to the remote endpoint that this endpoint believes itself to be
516 // flow-control blocked but otherwise ready to send data. The BLOCKED frame
517 // is purely advisory and optional.
518 bool SerializeBlocked(const SpdyBlockedIR& blocked,
519 ZeroCopyOutputBuffer* output) const;
520
521 // Serializes a PUSH_PROMISE frame. The PUSH_PROMISE frame is used
522 // to inform the client that it will be receiving an additional stream
523 // in response to the original request. The frame includes synthesized
524 // headers to explain the upcoming data.
525 bool SerializePushPromise(const SpdyPushPromiseIR& push_promise,
526 ZeroCopyOutputBuffer* output);
527
528 // Serializes a CONTINUATION frame. The CONTINUATION frame is used
529 // to continue a sequence of header block fragments.
530 bool SerializeContinuation(const SpdyContinuationIR& continuation,
531 ZeroCopyOutputBuffer* output) const;
532
533 // Serializes an ALTSVC frame. The ALTSVC frame advertises the
534 // availability of an alternative service to the client.
535 bool SerializeAltSvc(const SpdyAltSvcIR& altsvc,
536 ZeroCopyOutputBuffer* output);
537
538 // Serializes a PRIORITY frame. The PRIORITY frame advises a change in
539 // the relative priority of the given stream.
540 bool SerializePriority(const SpdyPriorityIR& priority,
541 ZeroCopyOutputBuffer* output) const;
542
543 // Serialize a frame of unknown type.
544 bool SerializeFrame(const SpdyFrameIR& frame, ZeroCopyOutputBuffer* output);
545
473 // Returns whether this SpdyFramer will compress header blocks using HPACK. 546 // Returns whether this SpdyFramer will compress header blocks using HPACK.
474 bool compression_enabled() const { 547 bool compression_enabled() const {
475 return compression_option_ == ENABLE_COMPRESSION; 548 return compression_option_ == ENABLE_COMPRESSION;
476 } 549 }
477 550
478 void SetHpackIndexingPolicy(HpackEncoder::IndexingPolicy policy) { 551 void SetHpackIndexingPolicy(HpackEncoder::IndexingPolicy policy) {
479 GetHpackEncoder()->SetIndexingPolicy(std::move(policy)); 552 GetHpackEncoder()->SetIndexingPolicy(std::move(policy));
480 } 553 }
481 554
482 // Returns the (minimum) size of frames (sans variable-length portions). 555 // Returns the (minimum) size of frames (sans variable-length portions).
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 void ProcessControlFrameHeader(); 712 void ProcessControlFrameHeader();
640 // Always passed exactly 1 setting's worth of data. 713 // Always passed exactly 1 setting's worth of data.
641 bool ProcessSetting(const char* data); 714 bool ProcessSetting(const char* data);
642 715
643 // Get (and lazily initialize) the HPACK state. 716 // Get (and lazily initialize) the HPACK state.
644 HpackEncoder* GetHpackEncoder(); 717 HpackEncoder* GetHpackEncoder();
645 HpackDecoderInterface* GetHpackDecoder(); 718 HpackDecoderInterface* GetHpackDecoder();
646 719
647 size_t GetNumberRequiredContinuationFrames(size_t size); 720 size_t GetNumberRequiredContinuationFrames(size_t size);
648 721
649 void WritePayloadWithContinuation(SpdyFrameBuilder* builder, 722 bool WritePayloadWithContinuation(SpdyFrameBuilder* builder,
650 const std::string& hpack_encoding, 723 const std::string& hpack_encoding,
651 SpdyStreamId stream_id, 724 SpdyStreamId stream_id,
652 SpdyFrameType type, 725 SpdyFrameType type,
653 int padding_payload_len); 726 int padding_payload_len);
654 727
655 // Utility to copy the given data block to the current frame buffer, up 728 // Utility to copy the given data block to the current frame buffer, up
656 // to the given maximum number of bytes, and update the buffer 729 // to the given maximum number of bytes, and update the buffer
657 // data (pointer and length). Returns the number of bytes 730 // data (pointer and length). Returns the number of bytes
658 // read, and: 731 // read, and:
659 // *data is advanced the number of bytes read. 732 // *data is advanced the number of bytes read.
(...skipping 10 matching lines...) Expand all
670 // Calculates the number of bytes required to serialize a SpdyHeadersIR, not 743 // Calculates the number of bytes required to serialize a SpdyHeadersIR, not
671 // including the bytes to be used for the encoded header set. 744 // including the bytes to be used for the encoded header set.
672 size_t GetHeaderFrameSizeSansBlock(const SpdyHeadersIR& header_ir) const; 745 size_t GetHeaderFrameSizeSansBlock(const SpdyHeadersIR& header_ir) const;
673 746
674 // Serializes the flags octet for a given SpdyHeadersIR. 747 // Serializes the flags octet for a given SpdyHeadersIR.
675 uint8_t SerializeHeaderFrameFlags(const SpdyHeadersIR& header_ir) const; 748 uint8_t SerializeHeaderFrameFlags(const SpdyHeadersIR& header_ir) const;
676 749
677 // Set the error code and moves the framer into the error state. 750 // Set the error code and moves the framer into the error state.
678 void set_error(SpdyFramerError error); 751 void set_error(SpdyFramerError error);
679 752
753 // Helper functions to prepare the input for SpdyFrameBuilder.
754 void SerializeDataBuilderHelper(const SpdyDataIR& data_ir,
755 uint8_t* flags,
756 int* num_padding_fields,
757 size_t* size_with_padding) const;
758 void SerializeDataFrameHeaderWithPaddingLengthFieldBuilderHelper(
759 const SpdyDataIR& data_ir,
760 uint8_t* flags,
761 size_t* frame_size,
762 size_t* num_padding_fields) const;
763 void SerializeSettingsBuilderHelper(const SpdySettingsIR& settings,
764 uint8_t* flags,
765 const SettingsMap* values,
766 size_t* size) const;
767 void SerializeAltSvcBuilderHelper(const SpdyAltSvcIR& altsvc_ir,
768 std::string* value,
769 size_t* size) const;
770 void SerializeHeadersBuilderHelper(const SpdyHeadersIR& headers,
771 uint8_t* flags,
772 size_t* size,
773 std::string* hpack_encoding,
774 int* weight,
775 size_t* length_field);
776 void SerializePushPromiseBuilderHelper(const SpdyPushPromiseIR& push_promise,
777 uint8_t* flags,
778 std::string* hpack_encoding,
779 size_t* size);
780
680 // The size of the control frame buffer. 781 // The size of the control frame buffer.
681 // Since this is only used for control frame headers, the maximum control 782 // Since this is only used for control frame headers, the maximum control
682 // frame header size is sufficient; all remaining control 783 // frame header size is sufficient; all remaining control
683 // frame data is streamed to the visitor. 784 // frame data is streamed to the visitor.
684 static const size_t kControlFrameBufferSize; 785 static const size_t kControlFrameBufferSize;
685 786
686 // The maximum size of the control frames that we send, including the size of 787 // The maximum size of the control frames that we send, including the size of
687 // the header. This limit is arbitrary. We can enforce it here or at the 788 // the header. This limit is arbitrary. We can enforce it here or at the
688 // application layer. We chose the framing layer, but this can be changed (or 789 // application layer. We chose the framing layer, but this can be changed (or
689 // removed) if necessary later down the line. 790 // removed) if necessary later down the line.
690 // TODO(diannahu): Rename to make it clear that this limit is for sending. 791 // TODO(diannahu): Rename to make it clear that this limit is for sending.
691 static const size_t kMaxControlFrameSize; 792 static const size_t kMaxControlFrameSize;
692 // The maximum size for the payload of DATA frames to send. 793 // The maximum size for the payload of DATA frames to send.
693 static const size_t kMaxDataPayloadSendSize; 794 static const size_t kMaxDataPayloadSendSize;
795 // The size of one parameter in SETTINGS frame.
796 static const size_t kOneSettingParameterSize;
694 797
695 SpdyState state_; 798 SpdyState state_;
696 SpdyState previous_state_; 799 SpdyState previous_state_;
697 SpdyFramerError spdy_framer_error_; 800 SpdyFramerError spdy_framer_error_;
698 801
699 // Note that for DATA frame, remaining_data_length_ is sum of lengths of 802 // Note that for DATA frame, remaining_data_length_ is sum of lengths of
700 // frame header, padding length field (optional), data payload (optional) and 803 // frame header, padding length field (optional), data payload (optional) and
701 // padding payload (optional). 804 // padding payload (optional).
702 size_t remaining_data_length_; 805 size_t remaining_data_length_;
703 806
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 // rather than reading all available input. 878 // rather than reading all available input.
776 bool process_single_input_frame_ = false; 879 bool process_single_input_frame_ = false;
777 880
778 // Latched value of FLAGS_chromium_http2_flag_remove_rewritelength. 881 // Latched value of FLAGS_chromium_http2_flag_remove_rewritelength.
779 bool skip_rewritelength_ = false; 882 bool skip_rewritelength_ = false;
780 }; 883 };
781 884
782 } // namespace net 885 } // namespace net
783 886
784 #endif // NET_SPDY_SPDY_FRAMER_H_ 887 #endif // NET_SPDY_SPDY_FRAMER_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_frame_builder.cc ('k') | net/spdy/spdy_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698