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

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

Issue 18683002: Test that server socket cannot reuse port (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_server_socket.h" 5 #include "net/socket/tcp_server_socket.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 ASSERT_TRUE(read_result >= 0); 239 ASSERT_TRUE(read_result >= 0);
240 ASSERT_TRUE(bytes_read + read_result <= message.size()); 240 ASSERT_TRUE(bytes_read + read_result <= message.size());
241 memmove(&buffer[bytes_read], read_buffer->data(), read_result); 241 memmove(&buffer[bytes_read], read_buffer->data(), read_result);
242 bytes_read += read_result; 242 bytes_read += read_result;
243 } 243 }
244 244
245 std::string received_message(buffer.begin(), buffer.end()); 245 std::string received_message(buffer.begin(), buffer.end());
246 ASSERT_EQ(message, received_message); 246 ASSERT_EQ(message, received_message);
247 } 247 }
248 248
249 TEST_F(TCPServerSocketTest, Rebind) {
250 IPEndPoint address;
251 // Bind to a random, unused port.
252 ParseAddress("127.0.0.1", 0, &address);
253
254 scoped_ptr<TCPServerSocket> socket(
255 new TCPServerSocket(NULL, NetLog::Source()));
256 ASSERT_EQ(OK, socket->Listen(address, kListenBacklog));
257
258 // Retrieve the real endpoint bound.
259 ASSERT_EQ(OK, socket->GetLocalAddress(&address));
260
261 scoped_ptr<TCPServerSocket> conflict_socket(
262 new TCPServerSocket(NULL, NetLog::Source()));
263 ASSERT_NE(OK, conflict_socket->Listen(address, kListenBacklog));
264
265 // Unbind.
266 socket.reset(NULL);
267
268 ASSERT_EQ(OK, conflict_socket->Listen(address, kListenBacklog));
269 }
270
249 } // namespace 271 } // namespace
250 272
251 } // namespace net 273 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698