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

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

Issue 509133002: Raw SocketDescriptor variant of UnixDomainServerSocket::Accept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits; waiting on mmenke for broader comments. Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/unix_domain_client_socket_posix.h" 5 #include "net/socket/unix_domain_client_socket_posix.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/posix/eintr_wrapper.h"
13 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
15 #include "net/base/test_completion_callback.h" 16 #include "net/base/test_completion_callback.h"
16 #include "net/socket/unix_domain_server_socket_posix.h" 17 #include "net/socket/unix_domain_server_socket_posix.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace net { 20 namespace net {
20 namespace { 21 namespace {
21 22
22 const char kSocketFilename[] = "socket_for_testing"; 23 const char kSocketFilename[] = "socket_for_testing";
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 EXPECT_EQ(OK, ConnectSynchronously(&client_socket)); 142 EXPECT_EQ(OK, ConnectSynchronously(&client_socket));
142 EXPECT_TRUE(client_socket.IsConnected()); 143 EXPECT_TRUE(client_socket.IsConnected());
143 // Server has not yet been notified of the connection. 144 // Server has not yet been notified of the connection.
144 EXPECT_FALSE(accepted_socket); 145 EXPECT_FALSE(accepted_socket);
145 146
146 EXPECT_EQ(OK, accept_callback.WaitForResult()); 147 EXPECT_EQ(OK, accept_callback.WaitForResult());
147 EXPECT_TRUE(accepted_socket); 148 EXPECT_TRUE(accepted_socket);
148 EXPECT_TRUE(accepted_socket->IsConnected()); 149 EXPECT_TRUE(accepted_socket->IsConnected());
149 } 150 }
150 151
152 TEST_F(UnixDomainClientSocketTest, ConnectWithSocketDescriptor) {
153 const bool kUseAbstractNamespace = false;
154
155 UnixDomainServerSocket server_socket(CreateAuthCallback(true),
156 kUseAbstractNamespace);
157 EXPECT_EQ(OK, server_socket.ListenWithAddressAndPort(socket_path_, 0, 1));
158
159 SocketDescriptor accepted_socket_fd = kInvalidSocket;
160 TestCompletionCallback accept_callback;
161 EXPECT_EQ(ERR_IO_PENDING,
162 server_socket.AcceptSocketDescriptor(&accepted_socket_fd,
163 accept_callback.callback()));
164 EXPECT_EQ(kInvalidSocket, accepted_socket_fd);
165
166 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace);
167 EXPECT_FALSE(client_socket.IsConnected());
168
169 EXPECT_EQ(OK, ConnectSynchronously(&client_socket));
170 EXPECT_TRUE(client_socket.IsConnected());
171 // Server has not yet been notified of the connection.
172 EXPECT_EQ(kInvalidSocket, accepted_socket_fd);
173
174 EXPECT_EQ(OK, accept_callback.WaitForResult());
175 EXPECT_NE(kInvalidSocket, accepted_socket_fd);
176
177 SocketDescriptor client_socket_fd = client_socket.ReleaseSocketDescriptor();
mmenke 2014/09/03 14:56:46 Can we wrap this in a UnixDomainClientSocket (And
Chris Masone 2014/09/03 15:03:40 TclClientSocketLibEvent? This is the wrong kind of
Chris Masone 2014/09/03 15:57:12 Ok, I've done a read() and made sure I got ERR_IO_
178 EXPECT_NE(kInvalidSocket, client_socket_fd);
179
180 EXPECT_EQ(0, IGNORE_EINTR(close(accepted_socket_fd)));
181 EXPECT_EQ(0, IGNORE_EINTR(close(client_socket_fd)));
182 }
183
151 TEST_F(UnixDomainClientSocketTest, ConnectWithAbstractNamespace) { 184 TEST_F(UnixDomainClientSocketTest, ConnectWithAbstractNamespace) {
152 const bool kUseAbstractNamespace = true; 185 const bool kUseAbstractNamespace = true;
153 186
154 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace); 187 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace);
155 EXPECT_FALSE(client_socket.IsConnected()); 188 EXPECT_FALSE(client_socket.IsConnected());
156 189
157 #if defined(OS_ANDROID) || defined(OS_LINUX) 190 #if defined(OS_ANDROID) || defined(OS_LINUX)
158 UnixDomainServerSocket server_socket(CreateAuthCallback(true), 191 UnixDomainServerSocket server_socket(CreateAuthCallback(true),
159 kUseAbstractNamespace); 192 kUseAbstractNamespace);
160 EXPECT_EQ(OK, server_socket.ListenWithAddressAndPort(socket_path_, 0, 1)); 193 EXPECT_EQ(OK, server_socket.ListenWithAddressAndPort(socket_path_, 0, 1));
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 accepted_socket.get(), read_buffer.get(), kReadBufferSize, 0)); 420 accepted_socket.get(), read_buffer.get(), kReadBufferSize, 0));
388 421
389 // Disconnect from server side after read-write. 422 // Disconnect from server side after read-write.
390 accepted_socket->Disconnect(); 423 accepted_socket->Disconnect();
391 EXPECT_FALSE(accepted_socket->IsConnected()); 424 EXPECT_FALSE(accepted_socket->IsConnected());
392 EXPECT_FALSE(client_socket.IsConnected()); 425 EXPECT_FALSE(client_socket.IsConnected());
393 } 426 }
394 427
395 } // namespace 428 } // namespace
396 } // namespace net 429 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698