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

Unified 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 side-by-side diff with in-line comments
Download patch
« net/socket/tcp_server_socket.cc ('K') | « net/socket/tcp_server_socket.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_socket_unittest.cc
diff --git a/net/socket/tcp_socket_unittest.cc b/net/socket/tcp_socket_unittest.cc
index d9da13c660cc5f7910de744af5932ff324f575d0..27b8169736448d8412a6db6fefc92d0991a6bcc7 100644
--- a/net/socket/tcp_socket_unittest.cc
+++ b/net/socket/tcp_socket_unittest.cc
@@ -11,6 +11,7 @@
#include <string>
#include <vector>
+#include "base/files/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "net/base/address_list.h"
@@ -21,6 +22,9 @@
#include "net/base/test_completion_callback.h"
#include "net/log/net_log_source.h"
#include "net/socket/socket_performance_watcher.h"
+#if defined(OS_POSIX)
+#include "net/socket/socket_posix.h"
+#endif
#include "net/socket/tcp_client_socket.h"
#include "net/test/gtest_util.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -226,6 +230,26 @@ TEST_F(TCPSocketTest, AcceptAsync) {
TestAcceptAsync();
}
+#if defined(OS_POSIX)
+// Test AdoptConnectedSocket() for TCPSocketPosix
+TEST_F(TCPSocketTest, AdoptConnectedSocket) {
+ SocketDescriptor socket_fd =
+ CreatePlatformSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ ASSERT_GE(socket_fd, 0);
+ ASSERT_TRUE(base::SetNonBlocking(socket_fd));
+ IPEndPoint address(IPAddress::IPv4Localhost(), 0);
+ SockaddrStorage storage;
+ ASSERT_TRUE(address.ToSockAddr(storage.addr, &storage.addr_len));
+ ASSERT_GE(bind(socket_fd, storage.addr, storage.addr_len), 0);
+ ASSERT_GE(listen(socket_fd, kListenBacklog), 0);
+
+ ASSERT_THAT(socket_.AdoptConnectedSocket(socket_fd, IPEndPoint()), IsOk());
+ ASSERT_THAT(socket_.GetLocalAddress(&local_address_), IsOk());
+
+ TestAcceptAsync();
+}
+#endif
+
#if defined(OS_WIN)
// Test Accept() for AdoptListenSocket.
TEST_F(TCPSocketTest, AcceptForAdoptedListenSocket) {
« 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