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

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

Issue 8790015: Make SpdyFrame::size a constant instead of a static method so gcc can optimize the call away. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fff Created 9 years 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/spdy_session.cc ('k') | net/tools/flip_server/constants.h » ('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) 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 #include "net/spdy/spdy_test_util.h" 5 #include "net/spdy/spdy_test_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 21 matching lines...) Expand all
32 chunks[index] = MockWrite(true, ptr, chunk_size); 32 chunks[index] = MockWrite(true, ptr, chunk_size);
33 } 33 }
34 return chunks; 34 return chunks;
35 } 35 }
36 36
37 // Chop a SpdyFrame into an array of MockWrites. 37 // Chop a SpdyFrame into an array of MockWrites.
38 // |frame| is the frame to chop. 38 // |frame| is the frame to chop.
39 // |num_chunks| is the number of chunks to create. 39 // |num_chunks| is the number of chunks to create.
40 MockWrite* ChopWriteFrame(const spdy::SpdyFrame& frame, int num_chunks) { 40 MockWrite* ChopWriteFrame(const spdy::SpdyFrame& frame, int num_chunks) {
41 return ChopWriteFrame(frame.data(), 41 return ChopWriteFrame(frame.data(),
42 frame.length() + spdy::SpdyFrame::size(), 42 frame.length() + spdy::SpdyFrame::kHeaderSize,
43 num_chunks); 43 num_chunks);
44 } 44 }
45 45
46 // Chop a frame into an array of MockReads. 46 // Chop a frame into an array of MockReads.
47 // |data| is the frame to chop. 47 // |data| is the frame to chop.
48 // |length| is the length of the frame to chop. 48 // |length| is the length of the frame to chop.
49 // |num_chunks| is the number of chunks to create. 49 // |num_chunks| is the number of chunks to create.
50 MockRead* ChopReadFrame(const char* data, int length, int num_chunks) { 50 MockRead* ChopReadFrame(const char* data, int length, int num_chunks) {
51 MockRead* chunks = new MockRead[num_chunks]; 51 MockRead* chunks = new MockRead[num_chunks];
52 int chunk_size = length / num_chunks; 52 int chunk_size = length / num_chunks;
53 for (int index = 0; index < num_chunks; index++) { 53 for (int index = 0; index < num_chunks; index++) {
54 const char* ptr = data + (index * chunk_size); 54 const char* ptr = data + (index * chunk_size);
55 if (index == num_chunks - 1) 55 if (index == num_chunks - 1)
56 chunk_size += length % chunk_size; // The last chunk takes the remainder. 56 chunk_size += length % chunk_size; // The last chunk takes the remainder.
57 chunks[index] = MockRead(true, ptr, chunk_size); 57 chunks[index] = MockRead(true, ptr, chunk_size);
58 } 58 }
59 return chunks; 59 return chunks;
60 } 60 }
61 61
62 // Chop a SpdyFrame into an array of MockReads. 62 // Chop a SpdyFrame into an array of MockReads.
63 // |frame| is the frame to chop. 63 // |frame| is the frame to chop.
64 // |num_chunks| is the number of chunks to create. 64 // |num_chunks| is the number of chunks to create.
65 MockRead* ChopReadFrame(const spdy::SpdyFrame& frame, int num_chunks) { 65 MockRead* ChopReadFrame(const spdy::SpdyFrame& frame, int num_chunks) {
66 return ChopReadFrame(frame.data(), 66 return ChopReadFrame(frame.data(),
67 frame.length() + spdy::SpdyFrame::size(), 67 frame.length() + spdy::SpdyFrame::kHeaderSize,
68 num_chunks); 68 num_chunks);
69 } 69 }
70 70
71 // Adds headers and values to a map. 71 // Adds headers and values to a map.
72 // |extra_headers| is an array of { name, value } pairs, arranged as strings 72 // |extra_headers| is an array of { name, value } pairs, arranged as strings
73 // where the even entries are the header names, and the odd entries are the 73 // where the even entries are the header names, and the odd entries are the
74 // header values. 74 // header values.
75 // |headers| gets filled in from |extra_headers|. 75 // |headers| gets filled in from |extra_headers|.
76 void AppendHeadersToSpdyFrame(const char* const extra_headers[], 76 void AppendHeadersToSpdyFrame(const char* const extra_headers[],
77 int extra_header_count, 77 int extra_header_count,
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 spdy::SpdyFramer framer; 751 spdy::SpdyFramer framer;
752 return framer.CreateDataFrame( 752 return framer.CreateDataFrame(
753 stream_id, data, len, fin ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE); 753 stream_id, data, len, fin ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE);
754 } 754 }
755 755
756 // Wraps |frame| in the payload of a data frame in stream |stream_id|. 756 // Wraps |frame| in the payload of a data frame in stream |stream_id|.
757 spdy::SpdyFrame* ConstructWrappedSpdyFrame( 757 spdy::SpdyFrame* ConstructWrappedSpdyFrame(
758 const scoped_ptr<spdy::SpdyFrame>& frame, 758 const scoped_ptr<spdy::SpdyFrame>& frame,
759 int stream_id) { 759 int stream_id) {
760 return ConstructSpdyBodyFrame(stream_id, frame->data(), 760 return ConstructSpdyBodyFrame(stream_id, frame->data(),
761 frame->length() + spdy::SpdyFrame::size(), 761 frame->length() + spdy::SpdyFrame::kHeaderSize,
762 false); 762 false);
763 } 763 }
764 764
765 // Construct an expected SPDY reply string. 765 // Construct an expected SPDY reply string.
766 // |extra_headers| are the extra header-value pairs, which typically 766 // |extra_headers| are the extra header-value pairs, which typically
767 // will vary the most between calls. 767 // will vary the most between calls.
768 // |buffer| is the buffer we're filling in. 768 // |buffer| is the buffer we're filling in.
769 // Returns the number of bytes written into |buffer|. 769 // Returns the number of bytes written into |buffer|.
770 int ConstructSpdyReplyString(const char* const extra_headers[], 770 int ConstructSpdyReplyString(const char* const extra_headers[],
771 int extra_header_count, 771 int extra_header_count,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 strlen("\n"), 834 strlen("\n"),
835 &buffer_write, 835 &buffer_write,
836 &buffer_left); 836 &buffer_left);
837 } 837 }
838 return packet_size; 838 return packet_size;
839 } 839 }
840 840
841 // Create a MockWrite from the given SpdyFrame. 841 // Create a MockWrite from the given SpdyFrame.
842 MockWrite CreateMockWrite(const spdy::SpdyFrame& req) { 842 MockWrite CreateMockWrite(const spdy::SpdyFrame& req) {
843 return MockWrite( 843 return MockWrite(
844 true, req.data(), req.length() + spdy::SpdyFrame::size()); 844 true, req.data(), req.length() + spdy::SpdyFrame::kHeaderSize);
845 } 845 }
846 846
847 // Create a MockWrite from the given SpdyFrame and sequence number. 847 // Create a MockWrite from the given SpdyFrame and sequence number.
848 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq) { 848 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq) {
849 return CreateMockWrite(req, seq, true); 849 return CreateMockWrite(req, seq, true);
850 } 850 }
851 851
852 // Create a MockWrite from the given SpdyFrame and sequence number. 852 // Create a MockWrite from the given SpdyFrame and sequence number.
853 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq, bool async) { 853 MockWrite CreateMockWrite(const spdy::SpdyFrame& req, int seq, bool async) {
854 return MockWrite( 854 return MockWrite(
855 async, req.data(), req.length() + spdy::SpdyFrame::size(), seq); 855 async, req.data(), req.length() + spdy::SpdyFrame::kHeaderSize, seq);
856 } 856 }
857 857
858 // Create a MockRead from the given SpdyFrame. 858 // Create a MockRead from the given SpdyFrame.
859 MockRead CreateMockRead(const spdy::SpdyFrame& resp) { 859 MockRead CreateMockRead(const spdy::SpdyFrame& resp) {
860 return MockRead( 860 return MockRead(
861 true, resp.data(), resp.length() + spdy::SpdyFrame::size()); 861 true, resp.data(), resp.length() + spdy::SpdyFrame::kHeaderSize);
862 } 862 }
863 863
864 // Create a MockRead from the given SpdyFrame and sequence number. 864 // Create a MockRead from the given SpdyFrame and sequence number.
865 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq) { 865 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq) {
866 return CreateMockRead(resp, seq, true); 866 return CreateMockRead(resp, seq, true);
867 } 867 }
868 868
869 // Create a MockRead from the given SpdyFrame and sequence number. 869 // Create a MockRead from the given SpdyFrame and sequence number.
870 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq, bool async) { 870 MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq, bool async) {
871 return MockRead( 871 return MockRead(
872 async, resp.data(), resp.length() + spdy::SpdyFrame::size(), seq); 872 async, resp.data(), resp.length() + spdy::SpdyFrame::kHeaderSize, seq);
873 } 873 }
874 874
875 // Combines the given SpdyFrames into the given char array and returns 875 // Combines the given SpdyFrames into the given char array and returns
876 // the total length. 876 // the total length.
877 int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, 877 int CombineFrames(const spdy::SpdyFrame** frames, int num_frames,
878 char* buff, int buff_len) { 878 char* buff, int buff_len) {
879 int total_len = 0; 879 int total_len = 0;
880 for (int i = 0; i < num_frames; ++i) { 880 for (int i = 0; i < num_frames; ++i) {
881 total_len += frames[i]->length() + spdy::SpdyFrame::size(); 881 total_len += frames[i]->length() + spdy::SpdyFrame::kHeaderSize;
882 } 882 }
883 DCHECK_LE(total_len, buff_len); 883 DCHECK_LE(total_len, buff_len);
884 char* ptr = buff; 884 char* ptr = buff;
885 for (int i = 0; i < num_frames; ++i) { 885 for (int i = 0; i < num_frames; ++i) {
886 int len = frames[i]->length() + spdy::SpdyFrame::size(); 886 int len = frames[i]->length() + spdy::SpdyFrame::kHeaderSize;
887 memcpy(ptr, frames[i]->data(), len); 887 memcpy(ptr, frames[i]->data(), len);
888 ptr += len; 888 ptr += len;
889 } 889 }
890 return total_len; 890 return total_len;
891 } 891 }
892 892
893 SpdySessionDependencies::SpdySessionDependencies() 893 SpdySessionDependencies::SpdySessionDependencies()
894 : host_resolver(new MockCachingHostResolver), 894 : host_resolver(new MockCachingHostResolver),
895 cert_verifier(new CertVerifier), 895 cert_verifier(new CertVerifier),
896 proxy_service(ProxyService::CreateDirect()), 896 proxy_service(ProxyService::CreateDirect()),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 spdy::CONTROL_FLAG_FIN, // Control Flags 988 spdy::CONTROL_FLAG_FIN, // Control Flags
989 false, // Compressed 989 false, // Compressed
990 spdy::INVALID, // Status 990 spdy::INVALID, // Status
991 NULL, // Data 991 NULL, // Data
992 0, // Length 992 0, // Length
993 spdy::DATA_FLAG_NONE // Data Flags 993 spdy::DATA_FLAG_NONE // Data Flags
994 }; 994 };
995 return kHeader; 995 return kHeader;
996 } 996 }
997 } // namespace net 997 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/tools/flip_server/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698