| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |