| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2007 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // Create server and listen. | 217 // Create server and listen. |
| 218 std::unique_ptr<AsyncSocket> server( | 218 std::unique_ptr<AsyncSocket> server( |
| 219 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); | 219 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
| 220 sink.Monitor(server.get()); | 220 sink.Monitor(server.get()); |
| 221 EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0))); | 221 EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0))); |
| 222 EXPECT_EQ(0, server->Listen(5)); | 222 EXPECT_EQ(0, server->Listen(5)); |
| 223 EXPECT_EQ(AsyncSocket::CS_CONNECTING, server->GetState()); | 223 EXPECT_EQ(AsyncSocket::CS_CONNECTING, server->GetState()); |
| 224 | 224 |
| 225 // Ensure no pending server connections, since we haven't done anything yet. | 225 // Ensure no pending server connections, since we haven't done anything yet. |
| 226 EXPECT_FALSE(sink.Check(server.get(), testing::SSE_READ)); | 226 EXPECT_FALSE(sink.Check(server.get(), testing::SSE_READ)); |
| 227 EXPECT_TRUE(NULL == server->Accept(&accept_addr)); | 227 EXPECT_TRUE(nullptr == server->Accept(&accept_addr)); |
| 228 EXPECT_TRUE(accept_addr.IsNil()); | 228 EXPECT_TRUE(accept_addr.IsNil()); |
| 229 | 229 |
| 230 // Attempt connect to listening socket. | 230 // Attempt connect to listening socket. |
| 231 EXPECT_EQ(0, client->Connect(server->GetLocalAddress())); | 231 EXPECT_EQ(0, client->Connect(server->GetLocalAddress())); |
| 232 EXPECT_FALSE(client->GetLocalAddress().IsNil()); | 232 EXPECT_FALSE(client->GetLocalAddress().IsNil()); |
| 233 EXPECT_NE(server->GetLocalAddress(), client->GetLocalAddress()); | 233 EXPECT_NE(server->GetLocalAddress(), client->GetLocalAddress()); |
| 234 | 234 |
| 235 // Client is connecting, outcome not yet determined. | 235 // Client is connecting, outcome not yet determined. |
| 236 EXPECT_EQ(AsyncSocket::CS_CONNECTING, client->GetState()); | 236 EXPECT_EQ(AsyncSocket::CS_CONNECTING, client->GetState()); |
| 237 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_OPEN)); | 237 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_OPEN)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 EXPECT_EQ(0, client->Connect(bogus_addr)); | 328 EXPECT_EQ(0, client->Connect(bogus_addr)); |
| 329 | 329 |
| 330 // Wait for connection to fail (ECONNREFUSED). | 330 // Wait for connection to fail (ECONNREFUSED). |
| 331 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); | 331 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); |
| 332 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_OPEN)); | 332 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_OPEN)); |
| 333 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_ERROR)); | 333 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_ERROR)); |
| 334 EXPECT_TRUE(client->GetRemoteAddress().IsNil()); | 334 EXPECT_TRUE(client->GetRemoteAddress().IsNil()); |
| 335 | 335 |
| 336 // Should be no pending server connections. | 336 // Should be no pending server connections. |
| 337 EXPECT_FALSE(sink.Check(server.get(), testing::SSE_READ)); | 337 EXPECT_FALSE(sink.Check(server.get(), testing::SSE_READ)); |
| 338 EXPECT_TRUE(NULL == server->Accept(&accept_addr)); | 338 EXPECT_TRUE(nullptr == server->Accept(&accept_addr)); |
| 339 EXPECT_EQ(IPAddress(), accept_addr.ipaddr()); | 339 EXPECT_EQ(IPAddress(), accept_addr.ipaddr()); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void SocketTest::ConnectWithDnsLookupFailInternal(const IPAddress& loopback) { | 342 void SocketTest::ConnectWithDnsLookupFailInternal(const IPAddress& loopback) { |
| 343 testing::StreamSink sink; | 343 testing::StreamSink sink; |
| 344 SocketAddress accept_addr; | 344 SocketAddress accept_addr; |
| 345 | 345 |
| 346 // Create client. | 346 // Create client. |
| 347 std::unique_ptr<AsyncSocket> client( | 347 std::unique_ptr<AsyncSocket> client( |
| 348 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); | 348 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 369 << "seconds."; | 369 << "seconds."; |
| 370 return; | 370 return; |
| 371 } | 371 } |
| 372 | 372 |
| 373 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); | 373 EXPECT_EQ_WAIT(AsyncSocket::CS_CLOSED, client->GetState(), kTimeout); |
| 374 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_OPEN)); | 374 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_OPEN)); |
| 375 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_ERROR)); | 375 EXPECT_TRUE(sink.Check(client.get(), testing::SSE_ERROR)); |
| 376 EXPECT_TRUE(client->GetRemoteAddress().IsNil()); | 376 EXPECT_TRUE(client->GetRemoteAddress().IsNil()); |
| 377 // Should be no pending server connections. | 377 // Should be no pending server connections. |
| 378 EXPECT_FALSE(sink.Check(server.get(), testing::SSE_READ)); | 378 EXPECT_FALSE(sink.Check(server.get(), testing::SSE_READ)); |
| 379 EXPECT_TRUE(NULL == server->Accept(&accept_addr)); | 379 EXPECT_TRUE(nullptr == server->Accept(&accept_addr)); |
| 380 EXPECT_TRUE(accept_addr.IsNil()); | 380 EXPECT_TRUE(accept_addr.IsNil()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void SocketTest::ConnectWithClosedSocketInternal(const IPAddress& loopback) { | 383 void SocketTest::ConnectWithClosedSocketInternal(const IPAddress& loopback) { |
| 384 // Create server and listen. | 384 // Create server and listen. |
| 385 std::unique_ptr<AsyncSocket> server( | 385 std::unique_ptr<AsyncSocket> server( |
| 386 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); | 386 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
| 387 EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0))); | 387 EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0))); |
| 388 EXPECT_EQ(0, server->Listen(5)); | 388 EXPECT_EQ(0, server->Listen(5)); |
| 389 | 389 |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_2); | 1054 socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_2); |
| 1055 | 1055 |
| 1056 int64_t system_time_diff = send_time_2 - send_time_1; | 1056 int64_t system_time_diff = send_time_2 - send_time_1; |
| 1057 int64_t recv_timestamp_diff = recv_timestamp_2 - recv_timestamp_1; | 1057 int64_t recv_timestamp_diff = recv_timestamp_2 - recv_timestamp_1; |
| 1058 // Compare against the system time at the point of sending, because | 1058 // Compare against the system time at the point of sending, because |
| 1059 // SleepMs may not sleep for exactly the requested time. | 1059 // SleepMs may not sleep for exactly the requested time. |
| 1060 EXPECT_NEAR(system_time_diff, recv_timestamp_diff, 10000); | 1060 EXPECT_NEAR(system_time_diff, recv_timestamp_diff, 10000); |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 } // namespace rtc | 1063 } // namespace rtc |
| OLD | NEW |