diff options
author | wtc@google.com <wtc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-30 17:32:12 +0000 |
---|---|---|
committer | wtc@google.com <wtc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-30 17:32:12 +0000 |
commit | 085ae9601431b16db2d143ac0acea8dc6d4801e7 (patch) | |
tree | 10551672cfc61afa6b80b8a0959e85d57320a768 | |
parent | ab9279f87987825e5c40c12fef7fc22c4ceb0301 (diff) | |
download | chromium_src-085ae9601431b16db2d143ac0acea8dc6d4801e7.zip chromium_src-085ae9601431b16db2d143ac0acea8dc6d4801e7.tar.gz chromium_src-085ae9601431b16db2d143ac0acea8dc6d4801e7.tar.bz2 |
Document that the callback parameter of
HostResolver::Resolve can be null.
In tcp_client_socket_unittest.cc, allow sock.Connect
to succeed synchronously. Break out of the infinite
loop if sock.Read fails.
R=darin
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/base/host_resolver.cc | 2 | ||||
-rw-r--r-- | net/base/host_resolver.h | 2 | ||||
-rw-r--r-- | net/base/tcp_client_socket_unittest.cc | 54 |
3 files changed, 35 insertions, 23 deletions
diff --git a/net/base/host_resolver.cc b/net/base/host_resolver.cc index 6d79b46..5ba1c5b 100644 --- a/net/base/host_resolver.cc +++ b/net/base/host_resolver.cc @@ -166,7 +166,7 @@ int HostResolver::Resolve(const std::string& hostname, int port, const std::string& port_str = IntToString(port); - // Do a synchronous resolution? + // Do a synchronous resolution. if (!callback) { struct addrinfo* results; int rv = ResolveAddrInfo(hostname, port_str, &results); diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index 34feacd..3283ac9 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -64,6 +64,8 @@ class HostResolver { // sin(6)_port field of the sockaddr_in{6} struct. Returns OK if successful // or an error code upon failure. // + // When callback is null, the operation completes synchronously. + // // When callback is non-null, ERR_IO_PENDING is returned if the operation // could not be completed synchronously, in which case the result code will // be passed to the callback when available. diff --git a/net/base/tcp_client_socket_unittest.cc b/net/base/tcp_client_socket_unittest.cc index b0de697..f780783 100644 --- a/net/base/tcp_client_socket_unittest.cc +++ b/net/base/tcp_client_socket_unittest.cc @@ -28,8 +28,8 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "net/base/address_list.h" -#include "net/base/net_errors.h" #include "net/base/host_resolver.h" +#include "net/base/net_errors.h" #include "net/base/tcp_client_socket.h" #include "net/base/test_completion_callback.h" #include "testing/gtest/include/gtest/gtest.h" @@ -58,10 +58,12 @@ TEST_F(TCPClientSocketTest, Connect) { EXPECT_FALSE(sock.IsConnected()); rv = sock.Connect(&callback); - ASSERT_EQ(rv, net::ERR_IO_PENDING); + if (rv != net::OK) { + ASSERT_EQ(rv, net::ERR_IO_PENDING); - rv = callback.WaitForResult(); - EXPECT_EQ(rv, net::OK); + rv = callback.WaitForResult(); + EXPECT_EQ(rv, net::OK); + } EXPECT_TRUE(sock.IsConnected()); @@ -83,18 +85,20 @@ TEST_F(TCPClientSocketTest, Read) { net::TCPClientSocket sock(addr); rv = sock.Connect(&callback); - ASSERT_EQ(rv, net::ERR_IO_PENDING); + if (rv != net::OK) { + ASSERT_EQ(rv, net::ERR_IO_PENDING); - rv = callback.WaitForResult(); - EXPECT_EQ(rv, net::OK); + rv = callback.WaitForResult(); + EXPECT_EQ(rv, net::OK); + } const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; - rv = sock.Write(request_text, arraysize(request_text)-1, &callback); + rv = sock.Write(request_text, arraysize(request_text) - 1, &callback); EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); if (rv == net::ERR_IO_PENDING) { rv = callback.WaitForResult(); - EXPECT_EQ(rv, arraysize(request_text)-1); + EXPECT_EQ(rv, arraysize(request_text) - 1); } char buf[4096]; @@ -105,7 +109,8 @@ TEST_F(TCPClientSocketTest, Read) { if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); - if (rv == 0) + EXPECT_GE(rv, 0); + if (rv <= 0) break; } } @@ -121,18 +126,20 @@ TEST_F(TCPClientSocketTest, Read_SmallChunks) { net::TCPClientSocket sock(addr); rv = sock.Connect(&callback); - ASSERT_EQ(rv, net::ERR_IO_PENDING); + if (rv != net::OK) { + ASSERT_EQ(rv, net::ERR_IO_PENDING); - rv = callback.WaitForResult(); - EXPECT_EQ(rv, net::OK); + rv = callback.WaitForResult(); + EXPECT_EQ(rv, net::OK); + } const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; - rv = sock.Write(request_text, arraysize(request_text)-1, &callback); + rv = sock.Write(request_text, arraysize(request_text) - 1, &callback); EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); if (rv == net::ERR_IO_PENDING) { rv = callback.WaitForResult(); - EXPECT_EQ(rv, arraysize(request_text)-1); + EXPECT_EQ(rv, arraysize(request_text) - 1); } char buf[1]; @@ -143,7 +150,8 @@ TEST_F(TCPClientSocketTest, Read_SmallChunks) { if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); - if (rv == 0) + EXPECT_GE(rv, 0); + if (rv <= 0) break; } } @@ -159,18 +167,20 @@ TEST_F(TCPClientSocketTest, Read_Interrupted) { net::TCPClientSocket sock(addr); rv = sock.Connect(&callback); - ASSERT_EQ(rv, net::ERR_IO_PENDING); + if (rv != net::OK) { + ASSERT_EQ(rv, net::ERR_IO_PENDING); - rv = callback.WaitForResult(); - EXPECT_EQ(rv, net::OK); + rv = callback.WaitForResult(); + EXPECT_EQ(rv, net::OK); + } const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; - rv = sock.Write(request_text, arraysize(request_text)-1, &callback); + rv = sock.Write(request_text, arraysize(request_text) - 1, &callback); EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); if (rv == net::ERR_IO_PENDING) { rv = callback.WaitForResult(); - EXPECT_EQ(rv, arraysize(request_text)-1); + EXPECT_EQ(rv, arraysize(request_text) - 1); } // Do a partial read and then exit. This test should not crash! @@ -181,5 +191,5 @@ TEST_F(TCPClientSocketTest, Read_Interrupted) { if (rv == net::ERR_IO_PENDING) rv = callback.WaitForResult(); - EXPECT_TRUE(rv != 0); + EXPECT_NE(rv, 0); } |