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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // For a bidirectional stream, we're ready for the response | 390 // For a bidirectional stream, we're ready for the response |
391 // headers once we've finished sending the request headers. | 391 // headers once we've finished sending the request headers. |
392 if (io_state_ < STATE_OPEN) | 392 if (io_state_ < STATE_OPEN) |
393 return ERR_SPDY_PROTOCOL_ERROR; | 393 return ERR_SPDY_PROTOCOL_ERROR; |
394 break; | 394 break; |
395 | 395 |
396 case SPDY_REQUEST_RESPONSE_STREAM: | 396 case SPDY_REQUEST_RESPONSE_STREAM: |
397 // For a request/response stream, we're ready for the response | 397 // For a request/response stream, we're ready for the response |
398 // headers once we've finished sending the request headers and | 398 // headers once we've finished sending the request headers and |
399 // the request body (if we have one). | 399 // the request body (if we have one). |
400 if ((io_state_ < STATE_OPEN) || | 400 if ((io_state_ < STATE_OPEN) || (send_status_ == MORE_DATA_TO_SEND) || |
401 (send_status_ == MORE_DATA_TO_SEND) || | 401 pending_send_data_.get()) |
402 pending_send_data_) | |
403 return ERR_SPDY_PROTOCOL_ERROR; | 402 return ERR_SPDY_PROTOCOL_ERROR; |
404 break; | 403 break; |
405 | 404 |
406 case SPDY_PUSH_STREAM: | 405 case SPDY_PUSH_STREAM: |
407 // For a push stream, we're ready immediately. | 406 // For a push stream, we're ready immediately. |
408 DCHECK_EQ(send_status_, NO_MORE_DATA_TO_SEND); | 407 DCHECK_EQ(send_status_, NO_MORE_DATA_TO_SEND); |
409 DCHECK_EQ(io_state_, STATE_OPEN); | 408 DCHECK_EQ(io_state_, STATE_OPEN); |
410 break; | 409 break; |
411 } | 410 } |
412 | 411 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 } else { | 588 } else { |
590 session_->CloseCreatedStream(GetWeakPtr(), OK); | 589 session_->CloseCreatedStream(GetWeakPtr(), OK); |
591 } | 590 } |
592 } | 591 } |
593 | 592 |
594 int SpdyStream::SendRequestHeaders(scoped_ptr<SpdyHeaderBlock> headers, | 593 int SpdyStream::SendRequestHeaders(scoped_ptr<SpdyHeaderBlock> headers, |
595 SpdySendStatus send_status) { | 594 SpdySendStatus send_status) { |
596 CHECK_NE(type_, SPDY_PUSH_STREAM); | 595 CHECK_NE(type_, SPDY_PUSH_STREAM); |
597 CHECK_EQ(send_status_, MORE_DATA_TO_SEND); | 596 CHECK_EQ(send_status_, MORE_DATA_TO_SEND); |
598 CHECK(!request_); | 597 CHECK(!request_); |
599 CHECK(!pending_send_data_); | 598 CHECK(!pending_send_data_.get()); |
600 CHECK_EQ(io_state_, STATE_NONE); | 599 CHECK_EQ(io_state_, STATE_NONE); |
601 request_ = headers.Pass(); | 600 request_ = headers.Pass(); |
602 send_status_ = send_status; | 601 send_status_ = send_status; |
603 io_state_ = STATE_GET_DOMAIN_BOUND_CERT; | 602 io_state_ = STATE_GET_DOMAIN_BOUND_CERT; |
604 return DoLoop(OK); | 603 return DoLoop(OK); |
605 } | 604 } |
606 | 605 |
607 void SpdyStream::SendData(IOBuffer* data, | 606 void SpdyStream::SendData(IOBuffer* data, |
608 int length, | 607 int length, |
609 SpdySendStatus send_status) { | 608 SpdySendStatus send_status) { |
610 CHECK_NE(type_, SPDY_PUSH_STREAM); | 609 CHECK_NE(type_, SPDY_PUSH_STREAM); |
611 CHECK_EQ(send_status_, MORE_DATA_TO_SEND); | 610 CHECK_EQ(send_status_, MORE_DATA_TO_SEND); |
612 CHECK_GE(io_state_, STATE_SEND_REQUEST_HEADERS_COMPLETE); | 611 CHECK_GE(io_state_, STATE_SEND_REQUEST_HEADERS_COMPLETE); |
613 CHECK(!pending_send_data_); | 612 CHECK(!pending_send_data_.get()); |
614 pending_send_data_ = new DrainableIOBuffer(data, length); | 613 pending_send_data_ = new DrainableIOBuffer(data, length); |
615 send_status_ = send_status; | 614 send_status_ = send_status; |
616 QueueNextDataFrame(); | 615 QueueNextDataFrame(); |
617 } | 616 } |
618 | 617 |
619 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info, | 618 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info, |
620 bool* was_npn_negotiated, | 619 bool* was_npn_negotiated, |
621 NextProto* protocol_negotiated) { | 620 NextProto* protocol_negotiated) { |
622 return session_->GetSSLInfo( | 621 return session_->GetSSLInfo( |
623 ssl_info, was_npn_negotiated, protocol_negotiated); | 622 ssl_info, was_npn_negotiated, protocol_negotiated); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 | 938 |
940 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); | 939 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); |
941 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); | 940 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); |
942 } | 941 } |
943 | 942 |
944 void SpdyStream::QueueNextDataFrame() { | 943 void SpdyStream::QueueNextDataFrame() { |
945 // Until the request has been completely sent, we cannot be sure | 944 // Until the request has been completely sent, we cannot be sure |
946 // that our stream_id is correct. | 945 // that our stream_id is correct. |
947 DCHECK_GT(io_state_, STATE_SEND_REQUEST_HEADERS_COMPLETE); | 946 DCHECK_GT(io_state_, STATE_SEND_REQUEST_HEADERS_COMPLETE); |
948 CHECK_GT(stream_id_, 0u); | 947 CHECK_GT(stream_id_, 0u); |
949 CHECK(pending_send_data_); | 948 CHECK(pending_send_data_.get()); |
950 CHECK_GT(pending_send_data_->BytesRemaining(), 0); | 949 CHECK_GT(pending_send_data_->BytesRemaining(), 0); |
951 | 950 |
952 SpdyDataFlags flags = | 951 SpdyDataFlags flags = |
953 (send_status_ == NO_MORE_DATA_TO_SEND) ? | 952 (send_status_ == NO_MORE_DATA_TO_SEND) ? |
954 DATA_FLAG_FIN : DATA_FLAG_NONE; | 953 DATA_FLAG_FIN : DATA_FLAG_NONE; |
955 scoped_ptr<SpdyBuffer> data_buffer(session_->CreateDataBuffer( | 954 scoped_ptr<SpdyBuffer> data_buffer( |
956 stream_id_, | 955 session_->CreateDataBuffer(stream_id_, |
957 pending_send_data_, pending_send_data_->BytesRemaining(), | 956 pending_send_data_.get(), |
958 flags)); | 957 pending_send_data_->BytesRemaining(), |
| 958 flags)); |
959 // We'll get called again by PossiblyResumeIfSendStalled(). | 959 // We'll get called again by PossiblyResumeIfSendStalled(). |
960 if (!data_buffer) | 960 if (!data_buffer) |
961 return; | 961 return; |
962 | 962 |
963 if (session_->flow_control_state() >= SpdySession::FLOW_CONTROL_STREAM) { | 963 if (session_->flow_control_state() >= SpdySession::FLOW_CONTROL_STREAM) { |
964 DCHECK_GE(data_buffer->GetRemainingSize(), | 964 DCHECK_GE(data_buffer->GetRemainingSize(), |
965 session_->GetDataFrameMinimumSize()); | 965 session_->GetDataFrameMinimumSize()); |
966 size_t payload_size = | 966 size_t payload_size = |
967 data_buffer->GetRemainingSize() - session_->GetDataFrameMinimumSize(); | 967 data_buffer->GetRemainingSize() - session_->GetDataFrameMinimumSize(); |
968 DCHECK_LE(payload_size, session_->GetDataFrameMaximumPayload()); | 968 DCHECK_LE(payload_size, session_->GetDataFrameMaximumPayload()); |
969 DecreaseSendWindowSize(static_cast<int32>(payload_size)); | 969 DecreaseSendWindowSize(static_cast<int32>(payload_size)); |
970 // This currently isn't strictly needed, since write frames are | 970 // This currently isn't strictly needed, since write frames are |
971 // discarded only if the stream is about to be closed. But have it | 971 // discarded only if the stream is about to be closed. But have it |
972 // here anyway just in case this changes. | 972 // here anyway just in case this changes. |
973 data_buffer->AddConsumeCallback( | 973 data_buffer->AddConsumeCallback( |
974 base::Bind(&SpdyStream::OnWriteBufferConsumed, | 974 base::Bind(&SpdyStream::OnWriteBufferConsumed, |
975 GetWeakPtr(), payload_size)); | 975 GetWeakPtr(), payload_size)); |
976 } | 976 } |
977 | 977 |
978 session_->EnqueueStreamWrite( | 978 session_->EnqueueStreamWrite( |
979 GetWeakPtr(), DATA, | 979 GetWeakPtr(), DATA, |
980 scoped_ptr<SpdyBufferProducer>( | 980 scoped_ptr<SpdyBufferProducer>( |
981 new SimpleBufferProducer(data_buffer.Pass()))); | 981 new SimpleBufferProducer(data_buffer.Pass()))); |
982 } | 982 } |
983 | 983 |
984 } // namespace net | 984 } // namespace net |
OLD | NEW |