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

Side by Side Diff: components/cronet/ios/cronet_bidirectional_stream.cc

Issue 1892423002: [Cronet] Add Hello World response to QuicTestServer and use it in bidirectional stream test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cronet7
Patch Set: Sync and lint. Created 4 years, 7 months 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
« no previous file with comments | « no previous file | components/cronet/ios/test/cronet_bidirectional_stream_test.mm » ('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 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 "components/cronet/ios/cronet_bidirectional_stream.h" 5 #include "components/cronet/ios/cronet_bidirectional_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 201 }
202 202
203 void CronetBidirectionalStream::ReadDataOnNetworkThread( 203 void CronetBidirectionalStream::ReadDataOnNetworkThread(
204 scoped_refptr<net::WrappedIOBuffer> read_buffer, 204 scoped_refptr<net::WrappedIOBuffer> read_buffer,
205 int buffer_size) { 205 int buffer_size) {
206 DCHECK(environment_->IsOnNetworkThread()); 206 DCHECK(environment_->IsOnNetworkThread());
207 DCHECK(read_buffer); 207 DCHECK(read_buffer);
208 DCHECK(!read_buffer_); 208 DCHECK(!read_buffer_);
209 if (read_state_ != WAITING_FOR_READ) { 209 if (read_state_ != WAITING_FOR_READ) {
210 DLOG(ERROR) << "Unexpected Read Data in read_state " << WAITING_FOR_READ; 210 DLOG(ERROR) << "Unexpected Read Data in read_state " << WAITING_FOR_READ;
211 OnFailed(net::ERR_UNEXPECTED); 211 // Invoke OnFailed unless it is already invoked.
212 if (read_state_ != ERROR)
213 OnFailed(net::ERR_UNEXPECTED);
212 return; 214 return;
213 } 215 }
214 read_state_ = READING; 216 read_state_ = READING;
215 read_buffer_ = read_buffer; 217 read_buffer_ = read_buffer;
216 218
217 int bytes_read = bidi_stream_->ReadData(read_buffer_.get(), buffer_size); 219 int bytes_read = bidi_stream_->ReadData(read_buffer_.get(), buffer_size);
218 // If IO is pending, wait for the BidirectionalStream to call OnDataRead. 220 // If IO is pending, wait for the BidirectionalStream to call OnDataRead.
219 if (bytes_read == net::ERR_IO_PENDING) 221 if (bytes_read == net::ERR_IO_PENDING)
220 return; 222 return;
221 223
222 if (bytes_read < 0) { 224 if (bytes_read < 0) {
223 OnFailed(bytes_read); 225 OnFailed(bytes_read);
224 return; 226 return;
225 } 227 }
226 OnDataRead(bytes_read); 228 OnDataRead(bytes_read);
227 } 229 }
228 230
229 void CronetBidirectionalStream::WriteDataOnNetworkThread( 231 void CronetBidirectionalStream::WriteDataOnNetworkThread(
230 scoped_refptr<net::WrappedIOBuffer> write_buffer, 232 scoped_refptr<net::WrappedIOBuffer> write_buffer,
231 int buffer_size, 233 int buffer_size,
232 bool end_of_stream) { 234 bool end_of_stream) {
233 DCHECK(environment_->IsOnNetworkThread()); 235 DCHECK(environment_->IsOnNetworkThread());
234 DCHECK(write_buffer); 236 DCHECK(write_buffer);
235 DCHECK(!write_buffer_); 237 DCHECK(!write_buffer_);
236 if (write_state_ != WAITING_FOR_WRITE) { 238 if (write_state_ != WAITING_FOR_WRITE) {
237 DLOG(ERROR) << "Unexpected Write Data in write_state " << write_state_; 239 DLOG(ERROR) << "Unexpected Write Data in write_state " << write_state_;
238 OnFailed(net::ERR_UNEXPECTED); 240 // Invoke OnFailed unless it is already invoked.
241 if (write_state_ != ERROR)
242 OnFailed(net::ERR_UNEXPECTED);
239 return; 243 return;
240 } 244 }
241 write_state_ = WRITING; 245 write_state_ = WRITING;
242 write_end_of_stream_ = end_of_stream; 246 write_end_of_stream_ = end_of_stream;
243 247
244 write_buffer_ = write_buffer; 248 write_buffer_ = write_buffer;
245 bidi_stream_->SendData(write_buffer_.get(), buffer_size, end_of_stream); 249 bidi_stream_->SendData(write_buffer_.get(), buffer_size, end_of_stream);
246 } 250 }
247 251
248 void CronetBidirectionalStream::CancelOnNetworkThread() { 252 void CronetBidirectionalStream::CancelOnNetworkThread() {
(...skipping 13 matching lines...) Expand all
262 void CronetBidirectionalStream::MaybeOnSucceded() { 266 void CronetBidirectionalStream::MaybeOnSucceded() {
263 DCHECK(environment_->IsOnNetworkThread()); 267 DCHECK(environment_->IsOnNetworkThread());
264 if (read_state_ == READING_DONE && write_state_ == WRITING_DONE) { 268 if (read_state_ == READING_DONE && write_state_ == WRITING_DONE) {
265 read_state_ = write_state_ = SUCCESS; 269 read_state_ = write_state_ = SUCCESS;
266 bidi_stream_.reset(); 270 bidi_stream_.reset();
267 delegate_->OnSucceeded(); 271 delegate_->OnSucceeded();
268 } 272 }
269 } 273 }
270 274
271 } // namespace cronet 275 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | components/cronet/ios/test/cronet_bidirectional_stream_test.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698