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

Side by Side Diff: net/socket/tcp_socket_unittest.cc

Issue 2815993002: Adds a method to TCPServerSocket to adopt a socket. (Closed)
Patch Set: Fixed (I hope) Windows compile failure. Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_socket.h" 5 #include "net/socket/tcp_socket.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/files/file_util.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "net/base/address_list.h" 17 #include "net/base/address_list.h"
17 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
18 #include "net/base/ip_endpoint.h" 19 #include "net/base/ip_endpoint.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "net/base/sockaddr_storage.h" 21 #include "net/base/sockaddr_storage.h"
21 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
22 #include "net/log/net_log_source.h" 23 #include "net/log/net_log_source.h"
23 #include "net/socket/socket_performance_watcher.h" 24 #include "net/socket/socket_performance_watcher.h"
25 #if defined(OS_POSIX)
26 #include "net/socket/socket_posix.h"
27 #endif
24 #include "net/socket/tcp_client_socket.h" 28 #include "net/socket/tcp_client_socket.h"
25 #include "net/test/gtest_util.h" 29 #include "net/test/gtest_util.h"
26 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
28 #include "testing/platform_test.h" 32 #include "testing/platform_test.h"
29 33
30 using net::test::IsOk; 34 using net::test::IsOk;
31 35
32 namespace net { 36 namespace net {
33 37
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 223
220 EXPECT_THAT(connect_callback.WaitForResult(), IsOk()); 224 EXPECT_THAT(connect_callback.WaitForResult(), IsOk());
221 } 225 }
222 226
223 // Test Accept() callback. 227 // Test Accept() callback.
224 TEST_F(TCPSocketTest, AcceptAsync) { 228 TEST_F(TCPSocketTest, AcceptAsync) {
225 ASSERT_NO_FATAL_FAILURE(SetUpListenIPv4()); 229 ASSERT_NO_FATAL_FAILURE(SetUpListenIPv4());
226 TestAcceptAsync(); 230 TestAcceptAsync();
227 } 231 }
228 232
233 #if defined(OS_POSIX)
234 // Test AdoptConnectedSocket() for TCPSocketPosix
235 TEST_F(TCPSocketTest, AdoptConnectedSocket) {
236 SocketDescriptor socket_fd =
237 CreatePlatformSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
238 ASSERT_GE(socket_fd, 0);
239 ASSERT_TRUE(base::SetNonBlocking(socket_fd));
240 IPEndPoint address(IPAddress::IPv4Localhost(), 0);
241 SockaddrStorage storage;
242 ASSERT_TRUE(address.ToSockAddr(storage.addr, &storage.addr_len));
243 ASSERT_GE(bind(socket_fd, storage.addr, storage.addr_len), 0);
244 ASSERT_GE(listen(socket_fd, kListenBacklog), 0);
245
246 ASSERT_THAT(socket_.AdoptConnectedSocket(socket_fd, IPEndPoint()), IsOk());
247 ASSERT_THAT(socket_.GetLocalAddress(&local_address_), IsOk());
248
249 TestAcceptAsync();
250 }
251 #endif
252
229 #if defined(OS_WIN) 253 #if defined(OS_WIN)
230 // Test Accept() for AdoptListenSocket. 254 // Test Accept() for AdoptListenSocket.
231 TEST_F(TCPSocketTest, AcceptForAdoptedListenSocket) { 255 TEST_F(TCPSocketTest, AcceptForAdoptedListenSocket) {
232 // Create a socket to be used with AdoptListenSocket. 256 // Create a socket to be used with AdoptListenSocket.
233 SOCKET existing_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 257 SOCKET existing_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
234 ASSERT_THAT(socket_.AdoptListenSocket(existing_socket), IsOk()); 258 ASSERT_THAT(socket_.AdoptListenSocket(existing_socket), IsOk());
235 259
236 IPEndPoint address(IPAddress::IPv4Localhost(), 0); 260 IPEndPoint address(IPAddress::IPv4Localhost(), 0);
237 SockaddrStorage storage; 261 SockaddrStorage storage;
238 ASSERT_TRUE(address.ToSockAddr(storage.addr, &storage.addr_len)); 262 ASSERT_TRUE(address.ToSockAddr(storage.addr, &storage.addr_len));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 414
391 // One notification should be received when the socket connects. One 415 // One notification should be received when the socket connects. One
392 // additional notification should be received for each message read. 416 // additional notification should be received for each message read.
393 TEST_F(TCPSocketTest, SPWNoAdvance) { 417 TEST_F(TCPSocketTest, SPWNoAdvance) {
394 TestSPWNotifications(true, 2u, 0u, 3u); 418 TestSPWNotifications(true, 2u, 0u, 3u);
395 } 419 }
396 #endif // defined(TCP_INFO) || defined(OS_LINUX) 420 #endif // defined(TCP_INFO) || defined(OS_LINUX)
397 421
398 } // namespace 422 } // namespace
399 } // namespace net 423 } // namespace net
OLDNEW
« net/socket/tcp_server_socket.cc ('K') | « net/socket/tcp_server_socket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698