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

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

Issue 357513003: Stop using SpdySynStreamIR for SPDY 4. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WebSocket test fix. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/buffered_spdy_framer_unittest.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 "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/stats_counters.h" 9 #include "base/metrics/stats_counters.h"
10 #include "base/third_party/valgrind/memcheck.h" 10 #include "base/third_party/valgrind/memcheck.h"
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2341 data_ir.data().length() + data_ir.padding_payload_len()); 2341 data_ir.data().length() + data_ir.padding_payload_len());
2342 } else { 2342 } else {
2343 builder.OverwriteLength(*this, data_ir.data().length()); 2343 builder.OverwriteLength(*this, data_ir.data().length());
2344 } 2344 }
2345 DCHECK_EQ(frame_size, builder.length()); 2345 DCHECK_EQ(frame_size, builder.length());
2346 return builder.take(); 2346 return builder.take();
2347 } 2347 }
2348 2348
2349 SpdySerializedFrame* SpdyFramer::SerializeSynStream( 2349 SpdySerializedFrame* SpdyFramer::SerializeSynStream(
2350 const SpdySynStreamIR& syn_stream) { 2350 const SpdySynStreamIR& syn_stream) {
2351 DCHECK_GE(SPDY3, protocol_version());
2351 uint8 flags = 0; 2352 uint8 flags = 0;
2352 if (syn_stream.fin()) { 2353 if (syn_stream.fin()) {
2353 flags |= CONTROL_FLAG_FIN; 2354 flags |= CONTROL_FLAG_FIN;
2354 } 2355 }
2355 if (syn_stream.unidirectional()) { 2356 if (syn_stream.unidirectional()) {
2356 // TODO(hkhalil): invalid for HTTP2. 2357 // TODO(hkhalil): invalid for HTTP2.
2357 flags |= CONTROL_FLAG_UNIDIRECTIONAL; 2358 flags |= CONTROL_FLAG_UNIDIRECTIONAL;
2358 } 2359 }
2359 // In SPDY >= 4, SYN_STREAM frames are HEADERS frames, but for now
2360 // we never expect to have to overflow into a CONTINUATION frame.
2361 if (protocol_version() > SPDY3) {
2362 flags |= HEADERS_FLAG_PRIORITY;
2363 flags |= HEADERS_FLAG_END_HEADERS;
2364 }
2365 2360
2366 // Sanitize priority. 2361 // Sanitize priority.
2367 uint8 priority = syn_stream.priority(); 2362 uint8 priority = syn_stream.priority();
2368 if (priority > GetLowestPriority()) { 2363 if (priority > GetLowestPriority()) {
2369 DLOG(DFATAL) << "Priority out-of-bounds."; 2364 DLOG(DFATAL) << "Priority out-of-bounds.";
2370 priority = GetLowestPriority(); 2365 priority = GetLowestPriority();
2371 } 2366 }
2372 2367
2373 // The size of this frame, including variable-length name-value block. 2368 // The size of this frame, including variable-length name-value block.
2374 size_t size = GetSynStreamMinimumSize(); 2369 size_t size = GetSynStreamMinimumSize() +
2375 2370 GetSerializedLength(syn_stream.name_value_block());
2376 string hpack_encoding;
2377 if (protocol_version() > SPDY3) {
2378 if (enable_compression_) {
2379 GetHpackEncoder()->EncodeHeaderSet(
2380 syn_stream.name_value_block(), &hpack_encoding);
2381 } else {
2382 GetHpackEncoder()->EncodeHeaderSetWithoutCompression(
2383 syn_stream.name_value_block(), &hpack_encoding);
2384 }
2385 size += hpack_encoding.size();
2386 } else {
2387 size += GetSerializedLength(syn_stream.name_value_block());
2388 }
2389 2371
2390 SpdyFrameBuilder builder(size, protocol_version()); 2372 SpdyFrameBuilder builder(size, protocol_version());
2391 if (protocol_version() <= SPDY3) { 2373 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags);
2392 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags); 2374 builder.WriteUInt32(syn_stream.stream_id());
2393 builder.WriteUInt32(syn_stream.stream_id()); 2375 builder.WriteUInt32(syn_stream.associated_to_stream_id());
2394 builder.WriteUInt32(syn_stream.associated_to_stream_id()); 2376 builder.WriteUInt8(priority << ((protocol_version() <= SPDY2) ? 6 : 5));
2395 builder.WriteUInt8(priority << ((protocol_version() <= SPDY2) ? 6 : 5)); 2377 builder.WriteUInt8(0); // Unused byte where credential slot used to be.
2396 builder.WriteUInt8(0); // Unused byte where credential slot used to be.
2397 } else {
2398 builder.BeginNewFrame(*this,
2399 HEADERS,
2400 flags,
2401 syn_stream.stream_id());
2402 // TODO(jgraettinger): Plumb priorities and stream dependencies.
2403 builder.WriteUInt32(0); // Non-exclusive bit and root stream ID.
2404 builder.WriteUInt8(MapPriorityToWeight(priority));
2405 }
2406 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length()); 2378 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length());
2407 if (protocol_version() > SPDY3) { 2379 SerializeNameValueBlock(&builder, syn_stream);
2408 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
2409 } else {
2410 SerializeNameValueBlock(&builder, syn_stream);
2411 }
2412 2380
2413 if (debug_visitor_) { 2381 if (debug_visitor_) {
2414 const size_t payload_len = 2382 const size_t payload_len =
2415 GetSerializedLength(protocol_version(), 2383 GetSerializedLength(protocol_version(),
2416 &(syn_stream.name_value_block())); 2384 &(syn_stream.name_value_block()));
2417 // SPDY 4 reports this compression as a SYN_STREAM compression. 2385 // SPDY 4 reports this compression as a SYN_STREAM compression.
2418 debug_visitor_->OnSendCompressedFrame(syn_stream.stream_id(), 2386 debug_visitor_->OnSendCompressedFrame(syn_stream.stream_id(),
2419 SYN_STREAM, 2387 SYN_STREAM,
2420 payload_len, 2388 payload_len,
2421 builder.length()); 2389 builder.length());
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 2596
2629 // The size of this frame, including variable-length name-value block. 2597 // The size of this frame, including variable-length name-value block.
2630 size_t size = GetHeadersMinimumSize(); 2598 size_t size = GetHeadersMinimumSize();
2631 2599
2632 uint32 priority = headers.priority(); 2600 uint32 priority = headers.priority();
2633 if (headers.has_priority()) { 2601 if (headers.has_priority()) {
2634 if (priority > GetLowestPriority()) { 2602 if (priority > GetLowestPriority()) {
2635 DLOG(DFATAL) << "Priority out-of-bounds."; 2603 DLOG(DFATAL) << "Priority out-of-bounds.";
2636 priority = GetLowestPriority(); 2604 priority = GetLowestPriority();
2637 } 2605 }
2638 size += 4; 2606 size += 5;
2639 } 2607 }
2640 2608
2641 string hpack_encoding; 2609 string hpack_encoding;
2642 if (protocol_version() > SPDY3) { 2610 if (protocol_version() > SPDY3) {
2643 if (enable_compression_) { 2611 if (enable_compression_) {
2644 GetHpackEncoder()->EncodeHeaderSet( 2612 GetHpackEncoder()->EncodeHeaderSet(
2645 headers.name_value_block(), &hpack_encoding); 2613 headers.name_value_block(), &hpack_encoding);
2646 } else { 2614 } else {
2647 GetHpackEncoder()->EncodeHeaderSetWithoutCompression( 2615 GetHpackEncoder()->EncodeHeaderSetWithoutCompression(
2648 headers.name_value_block(), &hpack_encoding); 2616 headers.name_value_block(), &hpack_encoding);
(...skipping 10 matching lines...) Expand all
2659 2627
2660 SpdyFrameBuilder builder(size, protocol_version()); 2628 SpdyFrameBuilder builder(size, protocol_version());
2661 if (protocol_version() <= SPDY3) { 2629 if (protocol_version() <= SPDY3) {
2662 builder.WriteControlFrameHeader(*this, HEADERS, flags); 2630 builder.WriteControlFrameHeader(*this, HEADERS, flags);
2663 builder.WriteUInt32(headers.stream_id()); 2631 builder.WriteUInt32(headers.stream_id());
2664 } else { 2632 } else {
2665 builder.BeginNewFrame(*this, 2633 builder.BeginNewFrame(*this,
2666 HEADERS, 2634 HEADERS,
2667 flags, 2635 flags,
2668 headers.stream_id()); 2636 headers.stream_id());
2669 if (headers.has_priority()) {
2670 // TODO(jgraettinger): Plumb priorities and stream dependencies.
2671 builder.WriteUInt32(0); // Non-exclusive bit and root stream ID.
2672 builder.WriteUInt8(MapPriorityToWeight(priority));
2673 }
2674 } 2637 }
2675 if (protocol_version() <= SPDY2) { 2638 if (protocol_version() <= SPDY2) {
2676 builder.WriteUInt16(0); // Unused. 2639 builder.WriteUInt16(0); // Unused.
2677 } 2640 }
2678 DCHECK_EQ(GetHeadersMinimumSize(), builder.length()); 2641 DCHECK_EQ(GetHeadersMinimumSize(), builder.length());
2679 2642
2680 if (protocol_version() > SPDY3) { 2643 if (protocol_version() > SPDY3) {
2644 if (headers.has_priority()) {
2645 // TODO(jgraettinger): Plumb priorities and stream dependencies.
2646 builder.WriteUInt32(0); // Non-exclusive bit and root stream ID.
2647 builder.WriteUInt8(MapPriorityToWeight(priority));
2648 }
2681 WritePayloadWithContinuation(&builder, 2649 WritePayloadWithContinuation(&builder,
2682 hpack_encoding, 2650 hpack_encoding,
2683 headers.stream_id(), 2651 headers.stream_id(),
2684 HEADERS); 2652 HEADERS);
2685 } else { 2653 } else {
2686 SerializeNameValueBlock(&builder, headers); 2654 SerializeNameValueBlock(&builder, headers);
2687 } 2655 }
2688 2656
2689 if (debug_visitor_) { 2657 if (debug_visitor_) {
2690 const size_t payload_len = protocol_version() > SPDY3 ? 2658 const size_t payload_len = protocol_version() > SPDY3 ?
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
3258 builder->Seek(compressed_size); 3226 builder->Seek(compressed_size);
3259 builder->RewriteLength(*this); 3227 builder->RewriteLength(*this);
3260 3228
3261 pre_compress_bytes.Add(uncompressed_len); 3229 pre_compress_bytes.Add(uncompressed_len);
3262 post_compress_bytes.Add(compressed_size); 3230 post_compress_bytes.Add(compressed_size);
3263 3231
3264 compressed_frames.Increment(); 3232 compressed_frames.Increment();
3265 } 3233 }
3266 3234
3267 } // namespace net 3235 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/buffered_spdy_framer_unittest.cc ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698