OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/quic/chromium/bidirectional_stream_quic_impl.h" | 5 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return rv; | 138 return rv; |
139 | 139 |
140 if (stream_->IsDoneReading()) { | 140 if (stream_->IsDoneReading()) { |
141 // If the write side is closed, OnFinRead() will call | 141 // If the write side is closed, OnFinRead() will call |
142 // BidirectionalStreamQuicImpl::OnClose(). | 142 // BidirectionalStreamQuicImpl::OnClose(). |
143 stream_->OnFinRead(); | 143 stream_->OnFinRead(); |
144 } | 144 } |
145 return rv; | 145 return rv; |
146 } | 146 } |
147 | 147 |
148 void BidirectionalStreamQuicImpl::SendData(const scoped_refptr<IOBuffer>& data, | |
149 int length, | |
150 bool end_stream) { | |
151 DCHECK(length > 0 || (length == 0 && end_stream)); | |
152 if (!stream_) { | |
153 LOG(ERROR) << "Trying to send data after stream has been destroyed."; | |
154 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
155 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, | |
156 weak_factory_.GetWeakPtr(), ERR_UNEXPECTED)); | |
157 return; | |
158 } | |
159 | |
160 std::unique_ptr<QuicConnection::ScopedPacketBundler> bundler; | |
161 if (!has_sent_headers_) { | |
162 DCHECK(!send_request_headers_automatically_); | |
163 // Creates a bundler only if there are headers to be sent along with the | |
164 // single data buffer. | |
165 bundler = | |
166 session_->CreatePacketBundler(QuicConnection::SEND_ACK_IF_PENDING); | |
167 // Sending the request might result in the stream being closed. | |
168 if (!WriteHeaders()) | |
169 return; | |
170 } | |
171 | |
172 QuicStringPiece string_data(data->data(), length); | |
173 int rv = stream_->WriteStreamData( | |
174 string_data, end_stream, | |
175 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, | |
176 weak_factory_.GetWeakPtr())); | |
177 DCHECK(rv == OK || rv == ERR_IO_PENDING); | |
178 if (rv == OK) { | |
179 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
180 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, | |
181 weak_factory_.GetWeakPtr(), OK)); | |
182 } | |
183 } | |
184 | |
185 void BidirectionalStreamQuicImpl::SendvData( | 148 void BidirectionalStreamQuicImpl::SendvData( |
186 const std::vector<scoped_refptr<IOBuffer>>& buffers, | 149 const std::vector<scoped_refptr<IOBuffer>>& buffers, |
187 const std::vector<int>& lengths, | 150 const std::vector<int>& lengths, |
188 bool end_stream) { | 151 bool end_stream) { |
189 DCHECK_EQ(buffers.size(), lengths.size()); | 152 DCHECK_EQ(buffers.size(), lengths.size()); |
190 | 153 |
191 if (!stream_) { | 154 if (!stream_) { |
192 LOG(ERROR) << "Trying to send data after stream has been destroyed."; | 155 LOG(ERROR) << "Trying to send data after stream has been destroyed."; |
193 base::ThreadTaskRunnerHandle::Get()->PostTask( | 156 base::ThreadTaskRunnerHandle::Get()->PostTask( |
194 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, | 157 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 if (!stream_) | 378 if (!stream_) |
416 return; | 379 return; |
417 closed_stream_received_bytes_ = stream_->stream_bytes_read(); | 380 closed_stream_received_bytes_ = stream_->stream_bytes_read(); |
418 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 381 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
419 closed_is_first_stream_ = stream_->IsFirstStream(); | 382 closed_is_first_stream_ = stream_->IsFirstStream(); |
420 stream_->ClearDelegate(); | 383 stream_->ClearDelegate(); |
421 stream_ = nullptr; | 384 stream_ = nullptr; |
422 } | 385 } |
423 | 386 |
424 } // namespace net | 387 } // namespace net |
OLD | NEW |