OLD | NEW |
---|---|
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_stream.h" | 5 #include "net/spdy/spdy_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); | 787 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); |
788 } | 788 } |
789 | 789 |
790 void SpdyStream::QueueNextDataFrame() { | 790 void SpdyStream::QueueNextDataFrame() { |
791 // Until the request has been completely sent, we cannot be sure | 791 // Until the request has been completely sent, we cannot be sure |
792 // that our stream_id is correct. | 792 // that our stream_id is correct. |
793 CHECK(io_state_ == STATE_OPEN || | 793 CHECK(io_state_ == STATE_OPEN || |
794 io_state_ == STATE_HALF_CLOSED_REMOTE) << io_state_; | 794 io_state_ == STATE_HALF_CLOSED_REMOTE) << io_state_; |
795 CHECK_GT(stream_id_, 0u); | 795 CHECK_GT(stream_id_, 0u); |
796 CHECK(pending_send_data_.get()); | 796 CHECK(pending_send_data_.get()); |
797 CHECK_GT(pending_send_data_->BytesRemaining(), 0); | 797 // Only the final fame may have a length of 0. |
mef
2014/08/26 12:58:41
nit: fame -> frame.
| |
798 if (pending_send_status_ == NO_MORE_DATA_TO_SEND) { | |
799 CHECK_GE(pending_send_data_->BytesRemaining(), 0); | |
800 } else { | |
801 CHECK_GT(pending_send_data_->BytesRemaining(), 0); | |
802 } | |
798 | 803 |
799 SpdyDataFlags flags = | 804 SpdyDataFlags flags = |
800 (pending_send_status_ == NO_MORE_DATA_TO_SEND) ? | 805 (pending_send_status_ == NO_MORE_DATA_TO_SEND) ? |
801 DATA_FLAG_FIN : DATA_FLAG_NONE; | 806 DATA_FLAG_FIN : DATA_FLAG_NONE; |
802 scoped_ptr<SpdyBuffer> data_buffer( | 807 scoped_ptr<SpdyBuffer> data_buffer( |
803 session_->CreateDataBuffer(stream_id_, | 808 session_->CreateDataBuffer(stream_id_, |
804 pending_send_data_.get(), | 809 pending_send_data_.get(), |
805 pending_send_data_->BytesRemaining(), | 810 pending_send_data_->BytesRemaining(), |
806 flags)); | 811 flags)); |
807 // We'll get called again by PossiblyResumeIfSendStalled(). | 812 // We'll get called again by PossiblyResumeIfSendStalled(). |
808 if (!data_buffer) | 813 if (!data_buffer) |
809 return; | 814 return; |
810 | 815 |
811 if (session_->flow_control_state() >= SpdySession::FLOW_CONTROL_STREAM) { | 816 if (session_->flow_control_state() >= SpdySession::FLOW_CONTROL_STREAM) { |
812 DCHECK_GE(data_buffer->GetRemainingSize(), | 817 DCHECK_GE(data_buffer->GetRemainingSize(), |
813 session_->GetDataFrameMinimumSize()); | 818 session_->GetDataFrameMinimumSize()); |
814 size_t payload_size = | 819 size_t payload_size = |
815 data_buffer->GetRemainingSize() - session_->GetDataFrameMinimumSize(); | 820 data_buffer->GetRemainingSize() - session_->GetDataFrameMinimumSize(); |
816 DCHECK_LE(payload_size, session_->GetDataFrameMaximumPayload()); | 821 DCHECK_LE(payload_size, session_->GetDataFrameMaximumPayload()); |
817 DecreaseSendWindowSize(static_cast<int32>(payload_size)); | 822 |
818 // This currently isn't strictly needed, since write frames are | 823 // Send window size is based on payload size, so nothing to do if this is |
819 // discarded only if the stream is about to be closed. But have it | 824 // just a FIN with no payload. |
820 // here anyway just in case this changes. | 825 if (payload_size != 0) { |
821 data_buffer->AddConsumeCallback( | 826 DecreaseSendWindowSize(static_cast<int32>(payload_size)); |
822 base::Bind(&SpdyStream::OnWriteBufferConsumed, | 827 // This currently isn't strictly needed, since write frames are |
823 GetWeakPtr(), payload_size)); | 828 // discarded only if the stream is about to be closed. But have it |
829 // here anyway just in case this changes. | |
830 data_buffer->AddConsumeCallback( | |
831 base::Bind(&SpdyStream::OnWriteBufferConsumed, | |
832 GetWeakPtr(), payload_size)); | |
833 } | |
824 } | 834 } |
825 | 835 |
826 session_->EnqueueStreamWrite( | 836 session_->EnqueueStreamWrite( |
827 GetWeakPtr(), DATA, | 837 GetWeakPtr(), DATA, |
828 scoped_ptr<SpdyBufferProducer>( | 838 scoped_ptr<SpdyBufferProducer>( |
829 new SimpleBufferProducer(data_buffer.Pass()))); | 839 new SimpleBufferProducer(data_buffer.Pass()))); |
830 } | 840 } |
831 | 841 |
832 int SpdyStream::MergeWithResponseHeaders( | 842 int SpdyStream::MergeWithResponseHeaders( |
833 const SpdyHeaderBlock& new_response_headers) { | 843 const SpdyHeaderBlock& new_response_headers) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 913 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
904 state); | 914 state); |
905 break; | 915 break; |
906 } | 916 } |
907 return description; | 917 return description; |
908 } | 918 } |
909 | 919 |
910 #undef STATE_CASE | 920 #undef STATE_CASE |
911 | 921 |
912 } // namespace net | 922 } // namespace net |
OLD | NEW |