| 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/socket/tcp_client_socket.h" | 5 #include "net/socket/tcp_client_socket.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | 283 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
| 284 uint32 bytes_read = DrainClientSocket(buf, 4096, arraysize(kServerReply) - 1, | 284 uint32 bytes_read = DrainClientSocket(buf, 4096, arraysize(kServerReply) - 1, |
| 285 &callback); | 285 &callback); |
| 286 ASSERT_EQ(bytes_read, arraysize(kServerReply) - 1); | 286 ASSERT_EQ(bytes_read, arraysize(kServerReply) - 1); |
| 287 | 287 |
| 288 // All data has been read now. Read once more to force an ERR_IO_PENDING, and | 288 // All data has been read now. Read once more to force an ERR_IO_PENDING, and |
| 289 // then close the server socket, and note the close. | 289 // then close the server socket, and note the close. |
| 290 | 290 |
| 291 rv = sock_->Read(buf, 4096, callback.callback()); | 291 rv = sock_->Read(buf, 4096, callback.callback()); |
| 292 ASSERT_EQ(ERR_IO_PENDING, rv); | 292 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 293 EXPECT_EQ(static_cast<int64>(std::string(kServerReply).size()), | |
| 294 sock_->NumBytesRead()); | |
| 295 CloseServerSocket(); | 293 CloseServerSocket(); |
| 296 EXPECT_EQ(0, callback.WaitForResult()); | 294 EXPECT_EQ(0, callback.WaitForResult()); |
| 297 } | 295 } |
| 298 | 296 |
| 299 TEST_P(TransportClientSocketTest, Read_SmallChunks) { | 297 TEST_P(TransportClientSocketTest, Read_SmallChunks) { |
| 300 TestCompletionCallback callback; | 298 TestCompletionCallback callback; |
| 301 int rv = sock_->Connect(callback.callback()); | 299 int rv = sock_->Connect(callback.callback()); |
| 302 if (rv != OK) { | 300 if (rv != OK) { |
| 303 ASSERT_EQ(rv, ERR_IO_PENDING); | 301 ASSERT_EQ(rv, ERR_IO_PENDING); |
| 304 | 302 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 317 rv = callback.WaitForResult(); | 315 rv = callback.WaitForResult(); |
| 318 | 316 |
| 319 ASSERT_EQ(1, rv); | 317 ASSERT_EQ(1, rv); |
| 320 bytes_read += rv; | 318 bytes_read += rv; |
| 321 } | 319 } |
| 322 | 320 |
| 323 // All data has been read now. Read once more to force an ERR_IO_PENDING, and | 321 // All data has been read now. Read once more to force an ERR_IO_PENDING, and |
| 324 // then close the server socket, and note the close. | 322 // then close the server socket, and note the close. |
| 325 | 323 |
| 326 rv = sock_->Read(buf, 1, callback.callback()); | 324 rv = sock_->Read(buf, 1, callback.callback()); |
| 327 EXPECT_EQ(static_cast<int64>(std::string(kServerReply).size()), | |
| 328 sock_->NumBytesRead()); | |
| 329 ASSERT_EQ(ERR_IO_PENDING, rv); | 325 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 330 CloseServerSocket(); | 326 CloseServerSocket(); |
| 331 EXPECT_EQ(0, callback.WaitForResult()); | 327 EXPECT_EQ(0, callback.WaitForResult()); |
| 332 } | 328 } |
| 333 | 329 |
| 334 TEST_P(TransportClientSocketTest, Read_Interrupted) { | 330 TEST_P(TransportClientSocketTest, Read_Interrupted) { |
| 335 TestCompletionCallback callback; | 331 TestCompletionCallback callback; |
| 336 int rv = sock_->Connect(callback.callback()); | 332 int rv = sock_->Connect(callback.callback()); |
| 337 if (rv != OK) { | 333 if (rv != OK) { |
| 338 ASSERT_EQ(ERR_IO_PENDING, rv); | 334 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 339 | 335 |
| 340 rv = callback.WaitForResult(); | 336 rv = callback.WaitForResult(); |
| 341 EXPECT_EQ(rv, OK); | 337 EXPECT_EQ(rv, OK); |
| 342 } | 338 } |
| 343 SendClientRequest(); | 339 SendClientRequest(); |
| 344 | 340 |
| 345 // Do a partial read and then exit. This test should not crash! | 341 // Do a partial read and then exit. This test should not crash! |
| 346 scoped_refptr<IOBuffer> buf(new IOBuffer(16)); | 342 scoped_refptr<IOBuffer> buf(new IOBuffer(16)); |
| 347 rv = sock_->Read(buf, 16, callback.callback()); | 343 rv = sock_->Read(buf, 16, callback.callback()); |
| 348 EXPECT_TRUE(rv >= 0 || rv == ERR_IO_PENDING); | 344 EXPECT_TRUE(rv >= 0 || rv == ERR_IO_PENDING); |
| 349 EXPECT_EQ(0, sock_->NumBytesRead()); | |
| 350 | 345 |
| 351 if (rv == ERR_IO_PENDING) { | 346 if (rv == ERR_IO_PENDING) |
| 352 rv = callback.WaitForResult(); | 347 rv = callback.WaitForResult(); |
| 353 EXPECT_EQ(16, sock_->NumBytesRead()); | |
| 354 } | |
| 355 | 348 |
| 356 EXPECT_NE(0, rv); | 349 EXPECT_NE(0, rv); |
| 357 } | 350 } |
| 358 | 351 |
| 359 TEST_P(TransportClientSocketTest, DISABLED_FullDuplex_ReadFirst) { | 352 TEST_P(TransportClientSocketTest, DISABLED_FullDuplex_ReadFirst) { |
| 360 TestCompletionCallback callback; | 353 TestCompletionCallback callback; |
| 361 int rv = sock_->Connect(callback.callback()); | 354 int rv = sock_->Connect(callback.callback()); |
| 362 if (rv != OK) { | 355 if (rv != OK) { |
| 363 ASSERT_EQ(rv, ERR_IO_PENDING); | 356 ASSERT_EQ(rv, ERR_IO_PENDING); |
| 364 | 357 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 438 |
| 446 // It's possible the read is blocked because it's already read all the data. | 439 // It's possible the read is blocked because it's already read all the data. |
| 447 // Close the server socket, so there will at least be a 0-byte read. | 440 // Close the server socket, so there will at least be a 0-byte read. |
| 448 CloseServerSocket(); | 441 CloseServerSocket(); |
| 449 | 442 |
| 450 rv = callback.WaitForResult(); | 443 rv = callback.WaitForResult(); |
| 451 EXPECT_GE(rv, 0); | 444 EXPECT_GE(rv, 0); |
| 452 } | 445 } |
| 453 | 446 |
| 454 } // namespace net | 447 } // namespace net |
| OLD | NEW |