OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 class PseudoTcpTest : public PseudoTcpTestBase { | 208 class PseudoTcpTest : public PseudoTcpTestBase { |
209 public: | 209 public: |
210 void TestTransfer(int size) { | 210 void TestTransfer(int size) { |
211 uint32_t start; | 211 uint32_t start; |
212 int32_t elapsed; | 212 int32_t elapsed; |
213 size_t received; | 213 size_t received; |
214 // Create some dummy data to send. | 214 // Create some dummy data to send. |
215 send_stream_.ReserveSize(size); | 215 send_stream_.ReserveSize(size); |
216 for (int i = 0; i < size; ++i) { | 216 for (int i = 0; i < size; ++i) { |
217 char ch = static_cast<char>(i); | 217 char ch = static_cast<char>(i); |
218 send_stream_.Write(&ch, 1, NULL, NULL); | 218 send_stream_.Write(&ch, 1, nullptr, nullptr); |
219 } | 219 } |
220 send_stream_.Rewind(); | 220 send_stream_.Rewind(); |
221 // Prepare the receive stream. | 221 // Prepare the receive stream. |
222 recv_stream_.ReserveSize(size); | 222 recv_stream_.ReserveSize(size); |
223 // Connect and wait until connected. | 223 // Connect and wait until connected. |
224 start = rtc::Time32(); | 224 start = rtc::Time32(); |
225 EXPECT_EQ(0, Connect()); | 225 EXPECT_EQ(0, Connect()); |
226 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); | 226 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); |
227 // Sending will start from OnTcpWriteable and complete when all data has | 227 // Sending will start from OnTcpWriteable and complete when all data has |
228 // been received. | 228 // been received. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 void ReadData() { | 274 void ReadData() { |
275 char block[kBlockSize]; | 275 char block[kBlockSize]; |
276 size_t position; | 276 size_t position; |
277 int rcvd; | 277 int rcvd; |
278 do { | 278 do { |
279 rcvd = remote_.Recv(block, sizeof(block)); | 279 rcvd = remote_.Recv(block, sizeof(block)); |
280 if (rcvd != -1) { | 280 if (rcvd != -1) { |
281 recv_stream_.Write(block, rcvd, NULL, NULL); | 281 recv_stream_.Write(block, rcvd, nullptr, nullptr); |
282 recv_stream_.GetPosition(&position); | 282 recv_stream_.GetPosition(&position); |
283 LOG(LS_VERBOSE) << "Received: " << position; | 283 LOG(LS_VERBOSE) << "Received: " << position; |
284 } | 284 } |
285 } while (rcvd > 0); | 285 } while (rcvd > 0); |
286 } | 286 } |
287 void WriteData(bool* done) { | 287 void WriteData(bool* done) { |
288 size_t position, tosend; | 288 size_t position, tosend; |
289 int sent; | 289 int sent; |
290 char block[kBlockSize]; | 290 char block[kBlockSize]; |
291 do { | 291 do { |
292 send_stream_.GetPosition(&position); | 292 send_stream_.GetPosition(&position); |
293 if (send_stream_.Read(block, sizeof(block), &tosend, NULL) != | 293 if (send_stream_.Read(block, sizeof(block), &tosend, nullptr) != |
294 rtc::SR_EOS) { | 294 rtc::SR_EOS) { |
295 sent = local_.Send(block, tosend); | 295 sent = local_.Send(block, tosend); |
296 UpdateLocalClock(); | 296 UpdateLocalClock(); |
297 if (sent != -1) { | 297 if (sent != -1) { |
298 send_stream_.SetPosition(position + sent); | 298 send_stream_.SetPosition(position + sent); |
299 LOG(LS_VERBOSE) << "Sent: " << position + sent; | 299 LOG(LS_VERBOSE) << "Sent: " << position + sent; |
300 } else { | 300 } else { |
301 send_stream_.SetPosition(position); | 301 send_stream_.SetPosition(position); |
302 LOG(LS_VERBOSE) << "Flow Controlled"; | 302 LOG(LS_VERBOSE) << "Flow Controlled"; |
303 } | 303 } |
304 } else { | 304 } else { |
305 sent = static_cast<int>(tosend = 0); | 305 sent = static_cast<int>(tosend = 0); |
306 } | 306 } |
307 } while (sent > 0); | 307 } while (sent > 0); |
308 *done = (tosend == 0); | 308 *done = (tosend == 0); |
309 } | 309 } |
310 | 310 |
311 private: | 311 private: |
312 rtc::MemoryStream send_stream_; | 312 rtc::MemoryStream send_stream_; |
313 rtc::MemoryStream recv_stream_; | 313 rtc::MemoryStream recv_stream_; |
314 }; | 314 }; |
315 | 315 |
316 | 316 |
317 class PseudoTcpTestPingPong : public PseudoTcpTestBase { | 317 class PseudoTcpTestPingPong : public PseudoTcpTestBase { |
318 public: | 318 public: |
319 PseudoTcpTestPingPong() | 319 PseudoTcpTestPingPong() |
320 : iterations_remaining_(0), | 320 : iterations_remaining_(0), |
321 » sender_(NULL), | 321 sender_(nullptr), |
322 » receiver_(NULL), | 322 receiver_(nullptr), |
323 » bytes_per_send_(0) { | 323 bytes_per_send_(0) {} |
324 } | |
325 void SetBytesPerSend(int bytes) { | 324 void SetBytesPerSend(int bytes) { |
326 bytes_per_send_ = bytes; | 325 bytes_per_send_ = bytes; |
327 } | 326 } |
328 void TestPingPong(int size, int iterations) { | 327 void TestPingPong(int size, int iterations) { |
329 uint32_t start, elapsed; | 328 uint32_t start, elapsed; |
330 iterations_remaining_ = iterations; | 329 iterations_remaining_ = iterations; |
331 receiver_ = &remote_; | 330 receiver_ = &remote_; |
332 sender_ = &local_; | 331 sender_ = &local_; |
333 // Create some dummy data to send. | 332 // Create some dummy data to send. |
334 send_stream_.ReserveSize(size); | 333 send_stream_.ReserveSize(size); |
335 for (int i = 0; i < size; ++i) { | 334 for (int i = 0; i < size; ++i) { |
336 char ch = static_cast<char>(i); | 335 char ch = static_cast<char>(i); |
337 send_stream_.Write(&ch, 1, NULL, NULL); | 336 send_stream_.Write(&ch, 1, nullptr, nullptr); |
338 } | 337 } |
339 send_stream_.Rewind(); | 338 send_stream_.Rewind(); |
340 // Prepare the receive stream. | 339 // Prepare the receive stream. |
341 recv_stream_.ReserveSize(size); | 340 recv_stream_.ReserveSize(size); |
342 // Connect and wait until connected. | 341 // Connect and wait until connected. |
343 start = rtc::Time32(); | 342 start = rtc::Time32(); |
344 EXPECT_EQ(0, Connect()); | 343 EXPECT_EQ(0, Connect()); |
345 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); | 344 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); |
346 // Sending will start from OnTcpWriteable and stop when the required | 345 // Sending will start from OnTcpWriteable and stop when the required |
347 // number of iterations have completed. | 346 // number of iterations have completed. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 WriteData(); | 389 WriteData(); |
391 } | 390 } |
392 | 391 |
393 void ReadData() { | 392 void ReadData() { |
394 char block[kBlockSize]; | 393 char block[kBlockSize]; |
395 size_t position; | 394 size_t position; |
396 int rcvd; | 395 int rcvd; |
397 do { | 396 do { |
398 rcvd = receiver_->Recv(block, sizeof(block)); | 397 rcvd = receiver_->Recv(block, sizeof(block)); |
399 if (rcvd != -1) { | 398 if (rcvd != -1) { |
400 recv_stream_.Write(block, rcvd, NULL, NULL); | 399 recv_stream_.Write(block, rcvd, nullptr, nullptr); |
401 recv_stream_.GetPosition(&position); | 400 recv_stream_.GetPosition(&position); |
402 LOG(LS_VERBOSE) << "Received: " << position; | 401 LOG(LS_VERBOSE) << "Received: " << position; |
403 } | 402 } |
404 } while (rcvd > 0); | 403 } while (rcvd > 0); |
405 } | 404 } |
406 void WriteData() { | 405 void WriteData() { |
407 size_t position, tosend; | 406 size_t position, tosend; |
408 int sent; | 407 int sent; |
409 char block[kBlockSize]; | 408 char block[kBlockSize]; |
410 do { | 409 do { |
411 send_stream_.GetPosition(&position); | 410 send_stream_.GetPosition(&position); |
412 tosend = bytes_per_send_ ? bytes_per_send_ : sizeof(block); | 411 tosend = bytes_per_send_ ? bytes_per_send_ : sizeof(block); |
413 if (send_stream_.Read(block, tosend, &tosend, NULL) != | 412 if (send_stream_.Read(block, tosend, &tosend, nullptr) != rtc::SR_EOS) { |
414 rtc::SR_EOS) { | |
415 sent = sender_->Send(block, tosend); | 413 sent = sender_->Send(block, tosend); |
416 UpdateLocalClock(); | 414 UpdateLocalClock(); |
417 if (sent != -1) { | 415 if (sent != -1) { |
418 send_stream_.SetPosition(position + sent); | 416 send_stream_.SetPosition(position + sent); |
419 LOG(LS_VERBOSE) << "Sent: " << position + sent; | 417 LOG(LS_VERBOSE) << "Sent: " << position + sent; |
420 } else { | 418 } else { |
421 send_stream_.SetPosition(position); | 419 send_stream_.SetPosition(position); |
422 LOG(LS_VERBOSE) << "Flow Controlled"; | 420 LOG(LS_VERBOSE) << "Flow Controlled"; |
423 } | 421 } |
424 } else { | 422 } else { |
(...skipping 14 matching lines...) Expand all Loading... |
439 // contracts and enlarges correctly. | 437 // contracts and enlarges correctly. |
440 class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase { | 438 class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase { |
441 public: | 439 public: |
442 // Not all the data are transfered, |size| just need to be big enough | 440 // Not all the data are transfered, |size| just need to be big enough |
443 // to fill up the receiver window twice. | 441 // to fill up the receiver window twice. |
444 void TestTransfer(int size) { | 442 void TestTransfer(int size) { |
445 // Create some dummy data to send. | 443 // Create some dummy data to send. |
446 send_stream_.ReserveSize(size); | 444 send_stream_.ReserveSize(size); |
447 for (int i = 0; i < size; ++i) { | 445 for (int i = 0; i < size; ++i) { |
448 char ch = static_cast<char>(i); | 446 char ch = static_cast<char>(i); |
449 send_stream_.Write(&ch, 1, NULL, NULL); | 447 send_stream_.Write(&ch, 1, nullptr, nullptr); |
450 } | 448 } |
451 send_stream_.Rewind(); | 449 send_stream_.Rewind(); |
452 | 450 |
453 // Prepare the receive stream. | 451 // Prepare the receive stream. |
454 recv_stream_.ReserveSize(size); | 452 recv_stream_.ReserveSize(size); |
455 | 453 |
456 // Connect and wait until connected. | 454 // Connect and wait until connected. |
457 EXPECT_EQ(0, Connect()); | 455 EXPECT_EQ(0, Connect()); |
458 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); | 456 EXPECT_TRUE_WAIT(have_connected_, kConnectTimeoutMs); |
459 | 457 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 504 } |
507 | 505 |
508 void ReadUntilIOPending() { | 506 void ReadUntilIOPending() { |
509 char block[kBlockSize]; | 507 char block[kBlockSize]; |
510 size_t position; | 508 size_t position; |
511 int rcvd; | 509 int rcvd; |
512 | 510 |
513 do { | 511 do { |
514 rcvd = remote_.Recv(block, sizeof(block)); | 512 rcvd = remote_.Recv(block, sizeof(block)); |
515 if (rcvd != -1) { | 513 if (rcvd != -1) { |
516 recv_stream_.Write(block, rcvd, NULL, NULL); | 514 recv_stream_.Write(block, rcvd, nullptr, nullptr); |
517 recv_stream_.GetPosition(&position); | 515 recv_stream_.GetPosition(&position); |
518 LOG(LS_VERBOSE) << "Received: " << position; | 516 LOG(LS_VERBOSE) << "Received: " << position; |
519 } | 517 } |
520 } while (rcvd > 0); | 518 } while (rcvd > 0); |
521 | 519 |
522 recv_stream_.GetPosition(&position); | 520 recv_stream_.GetPosition(&position); |
523 recv_position_.push_back(position); | 521 recv_position_.push_back(position); |
524 | 522 |
525 // Disconnect if we have done two transfers. | 523 // Disconnect if we have done two transfers. |
526 if (recv_position_.size() == 2u) { | 524 if (recv_position_.size() == 2u) { |
527 Close(); | 525 Close(); |
528 OnTcpClosed(&remote_, 0); | 526 OnTcpClosed(&remote_, 0); |
529 } else { | 527 } else { |
530 WriteData(); | 528 WriteData(); |
531 } | 529 } |
532 } | 530 } |
533 | 531 |
534 void WriteData() { | 532 void WriteData() { |
535 size_t position, tosend; | 533 size_t position, tosend; |
536 int sent; | 534 int sent; |
537 char block[kBlockSize]; | 535 char block[kBlockSize]; |
538 do { | 536 do { |
539 send_stream_.GetPosition(&position); | 537 send_stream_.GetPosition(&position); |
540 if (send_stream_.Read(block, sizeof(block), &tosend, NULL) != | 538 if (send_stream_.Read(block, sizeof(block), &tosend, nullptr) != |
541 rtc::SR_EOS) { | 539 rtc::SR_EOS) { |
542 sent = local_.Send(block, tosend); | 540 sent = local_.Send(block, tosend); |
543 UpdateLocalClock(); | 541 UpdateLocalClock(); |
544 if (sent != -1) { | 542 if (sent != -1) { |
545 send_stream_.SetPosition(position + sent); | 543 send_stream_.SetPosition(position + sent); |
546 LOG(LS_VERBOSE) << "Sent: " << position + sent; | 544 LOG(LS_VERBOSE) << "Sent: " << position + sent; |
547 } else { | 545 } else { |
548 send_stream_.SetPosition(position); | 546 send_stream_.SetPosition(position); |
549 LOG(LS_VERBOSE) << "Flow Controlled"; | 547 LOG(LS_VERBOSE) << "Flow Controlled"; |
550 } | 548 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 /* Test sending data with mismatched MTUs. We should detect this and reduce | 830 /* Test sending data with mismatched MTUs. We should detect this and reduce |
833 // our packet size accordingly. | 831 // our packet size accordingly. |
834 // TODO: This doesn't actually work right now. The current code | 832 // TODO: This doesn't actually work right now. The current code |
835 // doesn't detect if the MTU is set too high on either side. | 833 // doesn't detect if the MTU is set too high on either side. |
836 TEST_F(PseudoTcpTest, TestSendWithMismatchedMtus) { | 834 TEST_F(PseudoTcpTest, TestSendWithMismatchedMtus) { |
837 SetLocalMtu(1500); | 835 SetLocalMtu(1500); |
838 SetRemoteMtu(1280); | 836 SetRemoteMtu(1280); |
839 TestTransfer(1000000); | 837 TestTransfer(1000000); |
840 } | 838 } |
841 */ | 839 */ |
OLD | NEW |