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

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

Issue 1328563002: clang_tidy net/spdy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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_test.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 #include "net/spdy/spdy_framer.h" 5 #include "net/spdy/spdy_framer.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 2968 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 // so disable compression in that case. 2979 // so disable compression in that case.
2980 // TODO(phajdan.jr): Remove the special case when it's no longer necessary. 2980 // TODO(phajdan.jr): Remove the special case when it's no longer necessary.
2981 static const int kCompressorLevel = 0; 2981 static const int kCompressorLevel = 0;
2982 #else // !defined(USE_SYSTEM_ZLIB) 2982 #else // !defined(USE_SYSTEM_ZLIB)
2983 static const int kCompressorLevel = 9; 2983 static const int kCompressorLevel = 9;
2984 #endif // !defined(USE_SYSTEM_ZLIB) 2984 #endif // !defined(USE_SYSTEM_ZLIB)
2985 static const int kCompressorWindowSizeInBits = 11; 2985 static const int kCompressorWindowSizeInBits = 11;
2986 static const int kCompressorMemLevel = 1; 2986 static const int kCompressorMemLevel = 1;
2987 2987
2988 z_stream* SpdyFramer::GetHeaderCompressor() { 2988 z_stream* SpdyFramer::GetHeaderCompressor() {
2989 if (header_compressor_.get()) 2989 if (header_compressor_.get()) {
2990 return header_compressor_.get(); // Already initialized. 2990 return header_compressor_.get(); // Already initialized.
2991 }
2991 2992
2992 header_compressor_.reset(new z_stream); 2993 header_compressor_.reset(new z_stream);
2993 memset(header_compressor_.get(), 0, sizeof(z_stream)); 2994 memset(header_compressor_.get(), 0, sizeof(z_stream));
2994 2995
2995 int success = deflateInit2(header_compressor_.get(), 2996 int success = deflateInit2(header_compressor_.get(),
2996 kCompressorLevel, 2997 kCompressorLevel,
2997 Z_DEFLATED, 2998 Z_DEFLATED,
2998 kCompressorWindowSizeInBits, 2999 kCompressorWindowSizeInBits,
2999 kCompressorMemLevel, 3000 kCompressorMemLevel,
3000 Z_DEFAULT_STRATEGY); 3001 Z_DEFAULT_STRATEGY);
3001 if (success == Z_OK) { 3002 if (success == Z_OK) {
3002 const char* dictionary = (protocol_version() <= SPDY2) ? 3003 const char* dictionary = (protocol_version() <= SPDY2) ?
3003 kV2Dictionary : kV3Dictionary; 3004 kV2Dictionary : kV3Dictionary;
3004 const int dictionary_size = (protocol_version() <= SPDY2) ? 3005 const int dictionary_size = (protocol_version() <= SPDY2) ?
3005 kV2DictionarySize : kV3DictionarySize; 3006 kV2DictionarySize : kV3DictionarySize;
3006 success = deflateSetDictionary(header_compressor_.get(), 3007 success = deflateSetDictionary(header_compressor_.get(),
3007 reinterpret_cast<const Bytef*>(dictionary), 3008 reinterpret_cast<const Bytef*>(dictionary),
3008 dictionary_size); 3009 dictionary_size);
3009 } 3010 }
3010 if (success != Z_OK) { 3011 if (success != Z_OK) {
3011 LOG(WARNING) << "deflateSetDictionary failure: " << success; 3012 LOG(WARNING) << "deflateSetDictionary failure: " << success;
3012 header_compressor_.reset(NULL); 3013 header_compressor_.reset(NULL);
3013 return NULL; 3014 return NULL;
3014 } 3015 }
3015 return header_compressor_.get(); 3016 return header_compressor_.get();
3016 } 3017 }
3017 3018
3018 z_stream* SpdyFramer::GetHeaderDecompressor() { 3019 z_stream* SpdyFramer::GetHeaderDecompressor() {
3019 if (header_decompressor_.get()) 3020 if (header_decompressor_.get()) {
3020 return header_decompressor_.get(); // Already initialized. 3021 return header_decompressor_.get(); // Already initialized.
3022 }
3021 3023
3022 header_decompressor_.reset(new z_stream); 3024 header_decompressor_.reset(new z_stream);
3023 memset(header_decompressor_.get(), 0, sizeof(z_stream)); 3025 memset(header_decompressor_.get(), 0, sizeof(z_stream));
3024 3026
3025 int success = inflateInit(header_decompressor_.get()); 3027 int success = inflateInit(header_decompressor_.get());
3026 if (success != Z_OK) { 3028 if (success != Z_OK) {
3027 LOG(WARNING) << "inflateInit failure: " << success; 3029 LOG(WARNING) << "inflateInit failure: " << success;
3028 header_decompressor_.reset(NULL); 3030 header_decompressor_.reset(NULL);
3029 return NULL; 3031 return NULL;
3030 } 3032 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3093 const int dictionary_size = (protocol_version() <= SPDY2) ? 3095 const int dictionary_size = (protocol_version() <= SPDY2) ?
3094 kV2DictionarySize : kV3DictionarySize; 3096 kV2DictionarySize : kV3DictionarySize;
3095 const DictionaryIds& ids = g_dictionary_ids.Get(); 3097 const DictionaryIds& ids = g_dictionary_ids.Get();
3096 const uLong dictionary_id = (protocol_version() <= SPDY2) ? 3098 const uLong dictionary_id = (protocol_version() <= SPDY2) ?
3097 ids.v2_dictionary_id : ids.v3_dictionary_id; 3099 ids.v2_dictionary_id : ids.v3_dictionary_id;
3098 // Need to try again with the right dictionary. 3100 // Need to try again with the right dictionary.
3099 if (decomp->adler == dictionary_id) { 3101 if (decomp->adler == dictionary_id) {
3100 rv = inflateSetDictionary(decomp, 3102 rv = inflateSetDictionary(decomp,
3101 reinterpret_cast<const Bytef*>(dictionary), 3103 reinterpret_cast<const Bytef*>(dictionary),
3102 dictionary_size); 3104 dictionary_size);
3103 if (rv == Z_OK) 3105 if (rv == Z_OK) {
3104 rv = inflate(decomp, Z_SYNC_FLUSH); 3106 rv = inflate(decomp, Z_SYNC_FLUSH);
3107 }
3105 } 3108 }
3106 } 3109 }
3107 3110
3108 // Inflate will generate a Z_BUF_ERROR if it runs out of input 3111 // Inflate will generate a Z_BUF_ERROR if it runs out of input
3109 // without producing any output. The input is consumed and 3112 // without producing any output. The input is consumed and
3110 // buffered internally by zlib so we can detect this condition by 3113 // buffered internally by zlib so we can detect this condition by
3111 // checking if avail_in is 0 after the call to inflate. 3114 // checking if avail_in is 0 after the call to inflate.
3112 bool input_exhausted = ((rv == Z_BUF_ERROR) && (decomp->avail_in == 0)); 3115 bool input_exhausted = ((rv == Z_BUF_ERROR) && (decomp->avail_in == 0));
3113 if ((rv == Z_OK) || input_exhausted) { 3116 if ((rv == Z_OK) || input_exhausted) {
3114 size_t decompressed_len = arraysize(buffer) - decomp->avail_out; 3117 size_t decompressed_len = arraysize(buffer) - decomp->avail_out;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3234 #else 3237 #else
3235 WriteHeaderBlockToZ(&frame.header_block(), compressor); 3238 WriteHeaderBlockToZ(&frame.header_block(), compressor);
3236 #endif // defined(USE_SYSTEM_ZLIB) 3239 #endif // defined(USE_SYSTEM_ZLIB)
3237 3240
3238 int compressed_size = compressed_max_size - compressor->avail_out; 3241 int compressed_size = compressed_max_size - compressor->avail_out;
3239 builder->Seek(compressed_size); 3242 builder->Seek(compressed_size);
3240 builder->RewriteLength(*this); 3243 builder->RewriteLength(*this);
3241 } 3244 }
3242 3245
3243 } // namespace net 3246 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_frame_builder.cc ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698