diff options
-rw-r--r-- | net/spdy/spdy_framer.cc | 51 | ||||
-rw-r--r-- | net/spdy/spdy_framer.h | 8 | ||||
-rw-r--r-- | net/spdy/spdy_framer_test.cc | 36 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 32 | ||||
-rw-r--r-- | net/spdy/spdy_protocol.h | 69 | ||||
-rw-r--r-- | net/spdy/spdy_protocol_test.cc | 22 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 10 | ||||
-rw-r--r-- | net/spdy/spdy_session.h | 2 |
8 files changed, 142 insertions, 88 deletions
diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc index 0996970..e001d86 100644 --- a/net/spdy/spdy_framer.cc +++ b/net/spdy/spdy_framer.cc @@ -284,9 +284,9 @@ void SpdyFramer::ProcessControlFrameHeader() { SpdySynReplyControlFrame::size() - SpdyControlFrame::size()) set_error(SPDY_INVALID_CONTROL_FRAME); break; - case FIN_STREAM: + case RST_STREAM: if (current_control_frame.length() != - SpdyFinStreamControlFrame::size() - SpdyFrame::size()) + SpdyRstStreamControlFrame::size() - SpdyFrame::size()) set_error(SPDY_INVALID_CONTROL_FRAME); break; case NOOP: @@ -428,9 +428,26 @@ bool SpdyFramer::ParseHeaderBlock(const SpdyFrame* frame, scoped_ptr<SpdyFrame> decompressed_frame(DecompressFrame(frame)); if (!decompressed_frame.get()) return false; - SpdySynStreamControlFrame syn_frame(decompressed_frame->data(), false); - const char *header_data = syn_frame.header_block(); - int header_length = syn_frame.header_block_len(); + + const char *header_data = NULL; + int header_length = 0; + + switch (type) { + case SYN_STREAM: + { + SpdySynStreamControlFrame syn_frame(decompressed_frame->data(), false); + header_data = syn_frame.header_block(); + header_length = syn_frame.header_block_len(); + } + break; + case SYN_REPLY: + { + SpdySynReplyControlFrame syn_frame(decompressed_frame->data(), false); + header_data = syn_frame.header_block(); + header_length = syn_frame.header_block_len(); + } + break; + } SpdyFrameBuilder builder(header_data, header_length); void* iter = NULL; @@ -455,14 +472,15 @@ bool SpdyFramer::ParseHeaderBlock(const SpdyFrame* frame, } SpdySynStreamControlFrame* SpdyFramer::CreateSynStream( - SpdyStreamId stream_id, int priority, SpdyControlFlags flags, - bool compressed, SpdyHeaderBlock* headers) { + SpdyStreamId stream_id, SpdyStreamId associated_stream_id, int priority, + SpdyControlFlags flags, bool compressed, SpdyHeaderBlock* headers) { SpdyFrameBuilder frame; frame.WriteUInt16(kControlFlagMask | kSpdyProtocolVersion); frame.WriteUInt16(SYN_STREAM); frame.WriteUInt32(0); // Placeholder for the length and flags frame.WriteUInt32(stream_id); + frame.WriteUInt32(associated_stream_id); frame.WriteUInt16(ntohs(priority) << 6); // Priority. frame.WriteUInt16(headers->size()); // Number of headers. @@ -489,15 +507,15 @@ SpdySynStreamControlFrame* SpdyFramer::CreateSynStream( } /* static */ -SpdyFinStreamControlFrame* SpdyFramer::CreateFinStream(SpdyStreamId stream_id, +SpdyRstStreamControlFrame* SpdyFramer::CreateRstStream(SpdyStreamId stream_id, int status) { SpdyFrameBuilder frame; frame.WriteUInt16(kControlFlagMask | kSpdyProtocolVersion); - frame.WriteUInt16(FIN_STREAM); + frame.WriteUInt16(RST_STREAM); frame.WriteUInt32(8); frame.WriteUInt32(stream_id); frame.WriteUInt32(status); - return reinterpret_cast<SpdyFinStreamControlFrame*>(frame.take()); + return reinterpret_cast<SpdyRstStreamControlFrame*>(frame.take()); } SpdySynReplyControlFrame* SpdyFramer::CreateSynReply(SpdyStreamId stream_id, @@ -634,7 +652,6 @@ bool SpdyFramer::GetFrameBoundaries(const SpdyFrame* frame, reinterpret_cast<const SpdyControlFrame*>(frame); switch (control_frame->type()) { case SYN_STREAM: - case SYN_REPLY: { const SpdySynStreamControlFrame *syn_frame = reinterpret_cast<const SpdySynStreamControlFrame*>(frame); @@ -644,6 +661,16 @@ bool SpdyFramer::GetFrameBoundaries(const SpdyFrame* frame, *payload = frame->data() + *header_length; } break; + case SYN_REPLY: + { + const SpdySynReplyControlFrame *syn_frame = + reinterpret_cast<const SpdySynReplyControlFrame*>(frame); + frame_size = SpdySynReplyControlFrame::size(); + *payload_length = syn_frame->header_block_len(); + *header_length = frame_size; + *payload = frame->data() + *header_length; + } + break; default: // TODO(mbelshe): set an error? return false; // We can't compress this frame! @@ -654,8 +681,6 @@ bool SpdyFramer::GetFrameBoundaries(const SpdyFrame* frame, *payload_length = frame->length(); *payload = frame->data() + SpdyFrame::size(); } - DCHECK(static_cast<size_t>(*header_length) <= - SpdyFrame::size() + *payload_length); return true; } diff --git a/net/spdy/spdy_framer.h b/net/spdy/spdy_framer.h index 8b129ea..fedb6e3 100644 --- a/net/spdy/spdy_framer.h +++ b/net/spdy/spdy_framer.h @@ -131,19 +131,21 @@ class SpdyFramer { bool ParseHeaderBlock(const SpdyFrame* frame, SpdyHeaderBlock* block); // Create a SpdySynStreamControlFrame. - // |stream_id| is the stream for this frame. - // |priority| is the priority (0-3) for this frame. + // |stream_id| is the id for this stream. + // |associated_stream_id| is the associated stream id for this stream. + // |priority| is the priority (0-3) for this stream. // |flags| is the flags to use with the data. // To mark this frame as the last frame, enable CONTROL_FLAG_FIN. // |compressed| specifies whether the frame should be compressed. // |headers| is the header block to include in the frame. SpdySynStreamControlFrame* CreateSynStream(SpdyStreamId stream_id, + SpdyStreamId associated_stream_id, int priority, SpdyControlFlags flags, bool compressed, SpdyHeaderBlock* headers); - static SpdyFinStreamControlFrame* CreateFinStream(SpdyStreamId stream_id, + static SpdyRstStreamControlFrame* CreateRstStream(SpdyStreamId stream_id, int status); // Create a SpdySynReplyControlFrame. diff --git a/net/spdy/spdy_framer_test.cc b/net/spdy/spdy_framer_test.cc index b4e09cb..bf9b6cd 100644 --- a/net/spdy/spdy_framer_test.cc +++ b/net/spdy/spdy_framer_test.cc @@ -65,7 +65,7 @@ class TestSpdyVisitor : public SpdyFramerVisitorInterface { DCHECK(parsed_headers); syn_reply_frame_count_++; break; - case FIN_STREAM: + case RST_STREAM: fin_frame_count_++; break; default: @@ -103,7 +103,7 @@ class TestSpdyVisitor : public SpdyFramerVisitorInterface { int syn_frame_count_; int syn_reply_frame_count_; int data_bytes_; - int fin_frame_count_; // The count of FIN_STREAM type frames received. + int fin_frame_count_; // The count of RST_STREAM type frames received. int fin_flag_count_; // The count of frames with the FIN flag set. int zero_length_data_frame_count_; // The count of zero-length data frames. }; @@ -139,7 +139,7 @@ TEST_F(SpdyFramerTest, HeaderBlock) { // Encode the header block into a SynStream frame. scoped_ptr<SpdySynStreamControlFrame> frame( - framer.CreateSynStream(1, 1, CONTROL_FLAG_NONE, true, &headers)); + framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, true, &headers)); EXPECT_TRUE(frame.get() != NULL); SpdyHeaderBlock new_headers; @@ -182,6 +182,7 @@ TEST_F(SpdyFramerTest, DuplicateHeader) { frame.WriteUInt16(SYN_STREAM); frame.WriteUInt32(0); // Placeholder for the length. frame.WriteUInt32(3); // stream_id + frame.WriteUInt32(0); // associated stream id frame.WriteUInt16(0); // Priority. frame.WriteUInt16(2); // Number of headers. @@ -208,6 +209,7 @@ TEST_F(SpdyFramerTest, MultiValueHeader) { frame.WriteUInt16(SYN_STREAM); frame.WriteUInt32(0); // Placeholder for the length. frame.WriteUInt32(3); // stream_id + frame.WriteUInt32(0); // associated stream id frame.WriteUInt16(0); // Priority. frame.WriteUInt16(2); // Number of headers. @@ -239,9 +241,11 @@ TEST_F(SpdyFramerTest, BasicCompression) { SpdyFramer framer; FramerSetEnableCompressionHelper(&framer, true); scoped_ptr<SpdySynStreamControlFrame> - frame1(framer.CreateSynStream(1, 1, CONTROL_FLAG_NONE, true, &headers)); + frame1(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, true, + &headers)); scoped_ptr<SpdySynStreamControlFrame> - frame2(framer.CreateSynStream(1, 1, CONTROL_FLAG_NONE, true, &headers)); + frame2(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, true, + &headers)); // Expect the second frame to be more compact than the first. EXPECT_LE(frame2->length(), frame1->length()); @@ -270,7 +274,8 @@ TEST_F(SpdyFramerTest, DecompressUncompressedFrame) { SpdyFramer framer; FramerSetEnableCompressionHelper(&framer, true); scoped_ptr<SpdySynStreamControlFrame> - frame1(framer.CreateSynStream(1, 1, CONTROL_FLAG_NONE, false, &headers)); + frame1(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, false, + &headers)); // Decompress the frame scoped_ptr<SpdyFrame> frame2(framer.DecompressFrame(frame1.get())); @@ -281,8 +286,9 @@ TEST_F(SpdyFramerTest, DecompressUncompressedFrame) { TEST_F(SpdyFramerTest, Basic) { const unsigned char input[] = { 0x80, 0x01, 0x00, 0x01, // SYN Stream #1 - 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 'h', 'h', 0x00, 0x02, 'v', 'v', @@ -294,9 +300,10 @@ TEST_F(SpdyFramerTest, Basic) { 0xde, 0xad, 0xbe, 0xef, 0x80, 0x01, 0x00, 0x01, // SYN Stream #3 - 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 0x00, 0x00, 0x00, 0x08, @@ -307,7 +314,7 @@ TEST_F(SpdyFramerTest, Basic) { 0x00, 0x00, 0x00, 0x04, 0xde, 0xad, 0xbe, 0xef, - 0x80, 0x01, 0x00, 0x03, // FIN on Stream #1 + 0x80, 0x01, 0x00, 0x03, // RST_STREAM on Stream #1 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, @@ -315,7 +322,7 @@ TEST_F(SpdyFramerTest, Basic) { 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 0x00, 0x00, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x03, // FIN on Stream #3 + 0x80, 0x01, 0x00, 0x03, // RST_STREAM on Stream #3 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, @@ -337,8 +344,9 @@ TEST_F(SpdyFramerTest, Basic) { TEST_F(SpdyFramerTest, FinOnDataFrame) { const unsigned char input[] = { 0x80, 0x01, 0x00, 0x01, // SYN Stream #1 - 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 'h', 'h', 0x00, 0x02, 'v', 'v', @@ -377,15 +385,17 @@ TEST_F(SpdyFramerTest, FinOnDataFrame) { TEST_F(SpdyFramerTest, FinOnSynReplyFrame) { const unsigned char input[] = { 0x80, 0x01, 0x00, 0x01, // SYN Stream #1 - 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 'h', 'h', 0x00, 0x02, 'v', 'v', 0x80, 0x01, 0x00, 0x02, // SYN REPLY Stream #1 - 0x01, 0x00, 0x00, 0x10, + 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 'a', 'a', 0x00, 0x02, 'b', 'b', diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 805de3c3..c4caf88 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -99,8 +99,9 @@ MockWrite* ChopFrame(const char* data, int length, int num_chunks) { static const unsigned char kGetSyn[] = { 0x80, 0x01, 0x00, 0x01, // header - 0x01, 0x00, 0x00, 0x45, // FIN, len + 0x01, 0x00, 0x00, 0x49, // FIN, len 0x00, 0x00, 0x00, 0x01, // stream id + 0x00, 0x00, 0x00, 0x00, // associated 0xc0, 0x00, 0x00, 0x03, // 4 headers 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', 0x00, 0x03, 'G', 'E', 'T', @@ -113,16 +114,16 @@ static const unsigned char kGetSyn[] = { }; static const unsigned char kGetSynCompressed[] = { - 0x80, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x43, - 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x78, 0xbb, - 0xdf, 0xa2, 0x51, 0xb2, 0x62, 0x60, 0x66, 0x60, - 0xcb, 0x05, 0xe6, 0xc3, 0xfc, 0x14, 0x06, 0x66, - 0x77, 0xd7, 0x10, 0x06, 0x66, 0x90, 0xa0, 0x58, - 0x46, 0x49, 0x49, 0x81, 0x95, 0xbe, 0x3e, 0x30, - 0xe2, 0xf5, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, - 0xf5, 0x92, 0xf3, 0x73, 0xf5, 0x19, 0xd8, 0xa1, - 0x1a, 0x19, 0x38, 0x60, 0xe6, 0x01, 0x00, 0x00, - 0x00, 0xff, 0xff + 0x80, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x47, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x00, 0x78, 0xbb, 0xdf, 0xa2, 0x51, 0xb2, + 0x62, 0x60, 0x66, 0x60, 0xcb, 0x05, 0xe6, 0xc3, + 0xfc, 0x14, 0x06, 0x66, 0x77, 0xd7, 0x10, 0x06, + 0x66, 0x90, 0xa0, 0x58, 0x46, 0x49, 0x49, 0x81, + 0x95, 0xbe, 0x3e, 0x30, 0xe2, 0xf5, 0xd2, 0xf3, + 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x92, 0xf3, 0x73, + 0xf5, 0x19, 0xd8, 0xa1, 0x1a, 0x19, 0x38, 0x60, + 0xe6, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff }; static const unsigned char kGetSynReply[] = { @@ -148,8 +149,9 @@ static const unsigned char kGetBodyFrame[] = { static const unsigned char kPostSyn[] = { 0x80, 0x01, 0x00, 0x01, // header - 0x00, 0x00, 0x00, 0x46, // flags, len + 0x00, 0x00, 0x00, 0x4a, // flags, len 0x00, 0x00, 0x00, 0x01, // stream id + 0x00, 0x00, 0x00, 0x00, // associated 0xc0, 0x00, 0x00, 0x03, // 4 headers 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', 0x00, 0x04, 'P', 'O', 'S', 'T', @@ -409,8 +411,9 @@ TEST_F(SpdyNetworkTransactionTest, Post) { TEST_F(SpdyNetworkTransactionTest, EmptyPost) { static const unsigned char kEmptyPostSyn[] = { 0x80, 0x01, 0x00, 0x01, // header - 0x01, 0x00, 0x00, 0x46, // flags, len + 0x01, 0x00, 0x00, 0x4a, // flags, len 0x00, 0x00, 0x00, 0x01, // stream id + 0x00, 0x00, 0x00, 0x00, // associated 0xc0, 0x00, 0x00, 0x03, // 4 headers 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', 0x00, 0x04, 'P', 'O', 'S', 'T', @@ -766,8 +769,9 @@ TEST_F(SpdyNetworkTransactionTest, ServerPush) { // Syn for the X-Associated-Content (foo.dat) static const unsigned char syn_push[] = { 0x80, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x47, + 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, // TODO(mbelshe): use new server push protocol. 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 'p', 'a', 't', 'h', 0x00, 0x08, '/', 'f', 'o', 'o', '.', 'd', 'a', 't', diff --git a/net/spdy/spdy_protocol.h b/net/spdy/spdy_protocol.h index f82ed11..c40b555 100644 --- a/net/spdy/spdy_protocol.h +++ b/net/spdy/spdy_protocol.h @@ -43,6 +43,8 @@ // +----------------------------------+ // |X| Stream-ID(31bits) | // +----------------------------------+ +// |X|Associated-To-Stream-ID (31bits)| +// +----------------------------------+ // |Pri| unused | Length (16bits)| // +----------------------------------+ // @@ -57,7 +59,7 @@ // | unused (16 bits)| Length (16bits)| // +----------------------------------+ // -// Control Frame: FIN_STREAM +// Control Frame: RST_STREAM // +----------------------------------+ // |1|000000000000001|0000000000000011| // +----------------------------------+ @@ -65,19 +67,9 @@ // +----------------------------------+ // |X| Stream-ID(31bits) | // +----------------------------------+ -// | Status (32 bits) | +// | Status code (32 bits) | // +----------------------------------+ // -// Control Frame: SetMaxStreams -// +----------------------------------+ -// |1|000000000000001|0000000000000100| -// +----------------------------------+ -// | flags (8) | Length (24 bits) | >= 4 -// +----------------------------------+ -// |X| Stream-ID(31bits) | -// +----------------------------------+ - -// TODO(fenix): add ChangePriority support. namespace spdy { @@ -92,8 +84,12 @@ const int kSpdyProtocolVersion = 1; enum SpdyControlType { SYN_STREAM = 1, SYN_REPLY, - FIN_STREAM, + RST_STREAM, + HELLO, NOOP, + PING, + GOAWAY, + HEADERS, NUM_CONTROL_FRAME_TYPES }; @@ -107,15 +103,19 @@ enum SpdyDataFlags { // Flags on control packets enum SpdyControlFlags { CONTROL_FLAG_NONE = 0, - CONTROL_FLAG_FIN = 1 + CONTROL_FLAG_FIN = 1, + CONTROL_FLAG_UNIDIRECTIONAL = 2 }; -// Status codes, as used in control frames (primarily FIN_STREAM). +// Status codes, as used in control frames (primarily RST_STREAM). enum SpdyStatusCodes { INVALID = 0, PROTOCOL_ERROR = 1, INVALID_STREAM = 2, - REFUSED_STREAM = 3 + REFUSED_STREAM = 3, + UNSUPPORTED_VERSION = 4, + CANCEL = 5, + INTERNAL_ERROR = 6 }; // A SPDY stream id is a 31 bit entity. @@ -166,6 +166,7 @@ struct SpdyControlFrameBlock : SpdyFrameBlock { // A SYN_STREAM Control Frame structure. struct SpdySynStreamControlFrameBlock : SpdyControlFrameBlock { + SpdyStreamId associated_stream_id_; SpdyPriority priority_; uint8 unused_; }; @@ -176,7 +177,7 @@ struct SpdySynReplyControlFrameBlock : SpdyControlFrameBlock { }; // A FNI_STREAM Control Frame structure. -struct SpdyFinStreamControlFrameBlock : SpdyControlFrameBlock { +struct SpdyRstStreamControlFrameBlock : SpdyControlFrameBlock { uint32 status_; }; @@ -349,6 +350,14 @@ class SpdySynStreamControlFrame : public SpdyControlFrame { : SpdyControlFrame(data, owns_buffer) {} virtual ~SpdySynStreamControlFrame() {} + SpdyStreamId associated_stream_id() const { + return ntohl(block()->associated_stream_id_) & kStreamIdMask; + } + + void set_associated_stream_id(SpdyStreamId id) { + mutable_block()->associated_stream_id_ = htonl(id & kStreamIdMask); + } + SpdyPriority priority() const { return (block()->priority_ & kPriorityMask) >> 6; } @@ -406,29 +415,29 @@ class SpdySynReplyControlFrame : public SpdyControlFrame { DISALLOW_COPY_AND_ASSIGN(SpdySynReplyControlFrame); }; -// A FIN_STREAM frame. -class SpdyFinStreamControlFrame : public SpdyControlFrame { +// A RST_STREAM frame. +class SpdyRstStreamControlFrame : public SpdyControlFrame { public: - SpdyFinStreamControlFrame() : SpdyControlFrame(size()) {} - SpdyFinStreamControlFrame(char* data, bool owns_buffer) + SpdyRstStreamControlFrame() : SpdyControlFrame(size()) {} + SpdyRstStreamControlFrame(char* data, bool owns_buffer) : SpdyControlFrame(data, owns_buffer) {} - virtual ~SpdyFinStreamControlFrame() {} + virtual ~SpdyRstStreamControlFrame() {} uint32 status() const { return ntohl(block()->status_); } void set_status(uint32 status) { mutable_block()->status_ = htonl(status); } - // Returns the size of the SpdyFinStreamControlFrameBlock structure. - // Note: this is not the size of the SpdyFinStreamControlFrame class. - static size_t size() { return sizeof(SpdyFinStreamControlFrameBlock); } + // Returns the size of the SpdyRstStreamControlFrameBlock structure. + // Note: this is not the size of the SpdyRstStreamControlFrame class. + static size_t size() { return sizeof(SpdyRstStreamControlFrameBlock); } private: - const struct SpdyFinStreamControlFrameBlock* block() const { - return static_cast<SpdyFinStreamControlFrameBlock*>(frame_); + const struct SpdyRstStreamControlFrameBlock* block() const { + return static_cast<SpdyRstStreamControlFrameBlock*>(frame_); } - struct SpdyFinStreamControlFrameBlock* mutable_block() { - return static_cast<SpdyFinStreamControlFrameBlock*>(frame_); + struct SpdyRstStreamControlFrameBlock* mutable_block() { + return static_cast<SpdyRstStreamControlFrameBlock*>(frame_); } - DISALLOW_COPY_AND_ASSIGN(SpdyFinStreamControlFrame); + DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamControlFrame); }; } // namespace spdy diff --git a/net/spdy/spdy_protocol_test.cc b/net/spdy/spdy_protocol_test.cc index 7d75113..7c171bf 100644 --- a/net/spdy/spdy_protocol_test.cc +++ b/net/spdy/spdy_protocol_test.cc @@ -14,7 +14,7 @@ using spdy::SpdyFrame; using spdy::SpdyControlFrame; using spdy::SpdySynStreamControlFrame; using spdy::SpdySynReplyControlFrame; -using spdy::SpdyFinStreamControlFrame; +using spdy::SpdyRstStreamControlFrame; using spdy::SpdyFramer; using spdy::SpdyHeaderBlock; using spdy::FlagsAndLength; @@ -23,7 +23,7 @@ using spdy::kStreamIdMask; using spdy::kSpdyProtocolVersion; using spdy::SYN_STREAM; using spdy::SYN_REPLY; -using spdy::FIN_STREAM; +using spdy::RST_STREAM; using spdy::CONTROL_FLAG_FIN; using spdy::CONTROL_FLAG_NONE; @@ -34,13 +34,13 @@ TEST(SpdyProtocolTest, ProtocolConstants) { EXPECT_EQ(8u, SpdyFrame::size()); EXPECT_EQ(8u, SpdyDataFrame::size()); EXPECT_EQ(12u, SpdyControlFrame::size()); - EXPECT_EQ(14u, SpdySynStreamControlFrame::size()); + EXPECT_EQ(18u, SpdySynStreamControlFrame::size()); EXPECT_EQ(14u, SpdySynReplyControlFrame::size()); - EXPECT_EQ(16u, SpdyFinStreamControlFrame::size()); + EXPECT_EQ(16u, SpdyRstStreamControlFrame::size()); EXPECT_EQ(4u, sizeof(FlagsAndLength)); EXPECT_EQ(1, SYN_STREAM); EXPECT_EQ(2, SYN_REPLY); - EXPECT_EQ(3, FIN_STREAM); + EXPECT_EQ(3, RST_STREAM); } // Test some of the protocol helper functions @@ -70,14 +70,18 @@ TEST(SpdyProtocolTest, ControlFrameStructs) { SpdyHeaderBlock headers; scoped_ptr<SpdySynStreamControlFrame> syn_frame( - framer.CreateSynStream(123, 2, CONTROL_FLAG_FIN, false, &headers)); + framer.CreateSynStream(123, 456, 2, CONTROL_FLAG_FIN, false, &headers)); EXPECT_EQ(kSpdyProtocolVersion, syn_frame->version()); EXPECT_EQ(true, syn_frame->is_control_frame()); EXPECT_EQ(SYN_STREAM, syn_frame->type()); EXPECT_EQ(123u, syn_frame->stream_id()); + EXPECT_EQ(456u, syn_frame->associated_stream_id()); EXPECT_EQ(2u, syn_frame->priority()); EXPECT_EQ(2, syn_frame->header_block_len()); EXPECT_EQ(1u, syn_frame->flags()); + syn_frame->set_associated_stream_id(999u); + EXPECT_EQ(123u, syn_frame->stream_id()); + EXPECT_EQ(999u, syn_frame->associated_stream_id()); scoped_ptr<SpdySynReplyControlFrame> syn_reply( framer.CreateSynReply(123, CONTROL_FLAG_NONE, false, &headers)); @@ -88,11 +92,11 @@ TEST(SpdyProtocolTest, ControlFrameStructs) { EXPECT_EQ(2, syn_reply->header_block_len()); EXPECT_EQ(0, syn_reply->flags()); - scoped_ptr<SpdyFinStreamControlFrame> fin_frame( - framer.CreateFinStream(123, 444)); + scoped_ptr<SpdyRstStreamControlFrame> fin_frame( + framer.CreateRstStream(123, 444)); EXPECT_EQ(kSpdyProtocolVersion, fin_frame->version()); EXPECT_EQ(true, fin_frame->is_control_frame()); - EXPECT_EQ(FIN_STREAM, fin_frame->type()); + EXPECT_EQ(RST_STREAM, fin_frame->type()); EXPECT_EQ(123u, fin_frame->stream_id()); EXPECT_EQ(444u, fin_frame->status()); fin_frame->set_status(555); diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index 63ee561..9879306 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -353,7 +353,7 @@ scoped_refptr<SpdyStream> SpdySession::GetOrCreateStream( // Create a SYN_STREAM packet and add to the output queue. scoped_ptr<spdy::SpdySynStreamControlFrame> syn_frame( - spdy_framer_.CreateSynStream(stream_id, request.priority, flags, false, + spdy_framer_.CreateSynStream(stream_id, 0, request.priority, flags, false, &headers)); int length = spdy::SpdyFrame::size() + syn_frame->length(); IOBuffer* buffer = new IOBuffer(length); @@ -428,7 +428,7 @@ bool SpdySession::CancelStream(spdy::SpdyStreamId stream_id) { if (!IsStreamActive(stream_id)) return false; - // TODO(mbelshe): We should send a FIN_STREAM control frame here + // TODO(mbelshe): We should send a RST_STREAM control frame here // so that the server can cancel a large send. // TODO(mbelshe): Write a method for tearing down a stream @@ -1021,16 +1021,16 @@ void SpdySession::OnControl(const spdy::SpdyControlFrame* frame) { reinterpret_cast<const spdy::SpdySynReplyControlFrame*>(frame), &headers); break; - case spdy::FIN_STREAM: + case spdy::RST_STREAM: LOG(INFO) << "Spdy Fin for stream " << frame->stream_id(); - OnFin(reinterpret_cast<const spdy::SpdyFinStreamControlFrame*>(frame)); + OnFin(reinterpret_cast<const spdy::SpdyRstStreamControlFrame*>(frame)); break; default: DCHECK(false); // Error! } } -void SpdySession::OnFin(const spdy::SpdyFinStreamControlFrame* frame) { +void SpdySession::OnFin(const spdy::SpdyRstStreamControlFrame* frame) { spdy::SpdyStreamId stream_id = frame->stream_id(); bool valid_stream = IsStreamActive(stream_id); if (!valid_stream) { diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h index 66c8a3c..e443580 100644 --- a/net/spdy/spdy_session.h +++ b/net/spdy/spdy_session.h @@ -123,7 +123,7 @@ class SpdySession : public base::RefCounted<SpdySession>, const spdy::SpdyHeaderBlock* headers); void OnSynReply(const spdy::SpdySynReplyControlFrame* frame, const spdy::SpdyHeaderBlock* headers); - void OnFin(const spdy::SpdyFinStreamControlFrame* frame); + void OnFin(const spdy::SpdyRstStreamControlFrame* frame); // IO Callbacks void OnTCPConnect(int result); |