diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 04:05:40 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 04:05:40 +0000 |
commit | f1525409f0a8b7e1fe50abad138d18062c27fbcf (patch) | |
tree | 3ced864709a672cdb96460dfa3633c671cfa7552 /net/spdy/spdy_framer.h | |
parent | 9e380509a8bece2177f27ed5b214732b50be39db (diff) | |
download | chromium_src-f1525409f0a8b7e1fe50abad138d18062c27fbcf.zip chromium_src-f1525409f0a8b7e1fe50abad138d18062c27fbcf.tar.gz chromium_src-f1525409f0a8b7e1fe50abad138d18062c27fbcf.tar.bz2 |
Separate SPDY data-frame compression from the header compressors.
BUG=none
TEST=SpdyFramerTest.UnclosedStreamDataCompressors, SpdyFramerTest.DataCompression
Review URL: http://codereview.chromium.org/2071009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47886 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy/spdy_framer.h')
-rw-r--r-- | net/spdy/spdy_framer.h | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/net/spdy/spdy_framer.h b/net/spdy/spdy_framer.h index 2c95ae5..540da6d 100644 --- a/net/spdy/spdy_framer.h +++ b/net/spdy/spdy_framer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -192,7 +192,7 @@ class SpdyFramer { // To create a compressed frame, enable DATA_FLAG_COMPRESSED. // To mark this frame as the last data frame, enable DATA_FLAG_FIN. SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id, const char* data, - uint32 len, SpdyDataFlags flags); + uint32 len, uint32 flags); static SpdyControlFrame* CreateNopFrame(); @@ -212,21 +212,21 @@ class SpdyFramer { // Compression state is maintained as part of the SpdyFramer. // Returned frame must be freed with "delete". // On failure, returns NULL. - SpdyFrame* CompressFrame(const SpdyFrame* frame); + SpdyFrame* CompressFrame(const SpdyFrame& frame); // Decompresses a SpdyFrame. // On success, returns a new SpdyFrame with the payload decompressed. // Compression state is maintained as part of the SpdyFramer. // Returned frame must be freed with "delete". // On failure, returns NULL. - SpdyFrame* DecompressFrame(const SpdyFrame* frame); + SpdyFrame* DecompressFrame(const SpdyFrame& frame); // Create a copy of a frame. // Returned frame must be freed with "delete". - SpdyFrame* DuplicateFrame(const SpdyFrame* frame); + SpdyFrame* DuplicateFrame(const SpdyFrame& frame); // Returns true if a frame could be compressed. - bool IsCompressible(const SpdyFrame* frame) const; + bool IsCompressible(const SpdyFrame& frame) const; // For debugging. static const char* StateToString(int state); @@ -237,7 +237,8 @@ class SpdyFramer { static const int kDictionarySize; protected: - FRIEND_TEST(SpdyFramerTest, HeaderBlockBarfsOnOutOfOrderHeaders); + FRIEND_TEST(SpdyFramerTest, DataCompression); + FRIEND_TEST(SpdyFramerTest, UnclosedStreamDataCompressors); friend class net::SpdyNetworkTransactionTest; friend class net::HttpNetworkTransactionTest; friend class net::HttpNetworkLayer; // This is temporary for the server. @@ -251,6 +252,8 @@ class SpdyFramer { static void set_enable_compression_default(bool value); private: + typedef std::map<SpdyStreamId, z_stream*> CompressorMap; + // Internal breakout from ProcessInput. Returns the number of bytes // consumed from the data. size_t ProcessCommonHeader(const char* data, size_t len); @@ -258,9 +261,24 @@ class SpdyFramer { size_t ProcessControlFramePayload(const char* data, size_t len); size_t ProcessDataFramePayload(const char* data, size_t len); - // Initialize the ZLib state. - bool InitializeCompressor(); - bool InitializeDecompressor(); + // Get (and lazily initialize) the ZLib state. + z_stream* GetHeaderCompressor(); + z_stream* GetHeaderDecompressor(); + z_stream* GetStreamCompressor(SpdyStreamId id); + z_stream* GetStreamDecompressor(SpdyStreamId id); + + // Compression helpers + SpdyControlFrame* CompressControlFrame(const SpdyControlFrame& frame); + SpdyDataFrame* CompressDataFrame(const SpdyDataFrame& frame); + SpdyControlFrame* DecompressControlFrame(const SpdyControlFrame& frame); + SpdyDataFrame* DecompressDataFrame(const SpdyDataFrame& frame); + SpdyFrame* CompressFrameWithZStream(const SpdyFrame& frame, + z_stream* compressor); + SpdyFrame* DecompressFrameWithZStream(const SpdyFrame& frame, + z_stream* decompressor); + void CleanupCompressorForStream(SpdyStreamId id); + void CleanupDecompressorForStream(SpdyStreamId id); + void CleanupStreamCompressorsAndDecompressors(); // Not used (yet) size_t BytesSafeToRead() const; @@ -273,9 +291,12 @@ class SpdyFramer { // Given a frame, breakdown the variable payload length, the static header // header length, and variable payload pointer. - bool GetFrameBoundaries(const SpdyFrame* frame, int* payload_length, + bool GetFrameBoundaries(const SpdyFrame& frame, int* payload_length, int* header_length, const char** payload) const; + int num_stream_compressors() const { return stream_compressors_.size(); } + int num_stream_decompressors() const { return stream_decompressors_.size(); } + SpdyState state_; SpdyError error_code_; size_t remaining_payload_; @@ -285,9 +306,15 @@ class SpdyFramer { size_t current_frame_len_; // Number of bytes read into the current_frame_. size_t current_frame_capacity_; - bool enable_compression_; - scoped_ptr<z_stream> compressor_; - scoped_ptr<z_stream> decompressor_; + bool enable_compression_; // Controls all compression + // SPDY header compressors. + scoped_ptr<z_stream> header_compressor_; + scoped_ptr<z_stream> header_decompressor_; + + // Per-stream data compressors. + CompressorMap stream_compressors_; + CompressorMap stream_decompressors_; + SpdyFramerVisitorInterface* visitor_; static bool compression_default_; |