Chromium Code Reviews| 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 | |
| 252 // Bind to an random, unused port. | |
|
wtc
2013/07/26 21:24:21
an => a
Bei Zhang
2013/08/01 20:14:40
Done.
| |
| 253 ParseAddress("127.0.0.1", 0, &address); | |
| 254 | |
| 255 scoped_ptr<TCPServerSocket> socket( | |
| 256 new TCPServerSocket(NULL, NetLog::Source())); | |
| 257 ASSERT_EQ(OK, socket->Listen(address, kListenBacklog)); | |
| 258 | |
| 259 // Retrieve the real endpoint bound. | |
| 260 socket->GetLocalAddress(&address); | |
|
wtc
2013/07/26 21:24:21
Check the return value:
ASSERT_EQ(OK, socket->G
Bei Zhang
2013/08/01 20:14:40
Done.
| |
| 261 | |
| 262 scoped_ptr<TCPServerSocket> conflict_socket( | |
| 263 new TCPServerSocket(NULL, NetLog::Source())); | |
| 264 ASSERT_NE(OK, conflict_socket->Listen(address, kListenBacklog)); | |
| 265 | |
| 266 // Unbind | |
|
wtc
2013/07/26 21:24:21
Nit: add a period (.).
Bei Zhang
2013/08/01 20:14:40
Done.
| |
| 267 socket.reset(NULL); | |
| 268 | |
| 269 ASSERT_EQ(OK, conflict_socket->Listen(address, kListenBacklog)); | |
| 270 } | |
| 271 | |
| 249 } // namespace | 272 } // namespace |
| 250 | 273 |
| 251 } // namespace net | 274 } // namespace net |
| OLD | NEW |