| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_socket.h" | 5 #include "net/socket/tcp_socket.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 ASSERT_TRUE(read_result >= 0); | 278 ASSERT_TRUE(read_result >= 0); |
| 279 ASSERT_TRUE(bytes_read + read_result <= message.size()); | 279 ASSERT_TRUE(bytes_read + read_result <= message.size()); |
| 280 memmove(&buffer[bytes_read], read_buffer->data(), read_result); | 280 memmove(&buffer[bytes_read], read_buffer->data(), read_result); |
| 281 bytes_read += read_result; | 281 bytes_read += read_result; |
| 282 } | 282 } |
| 283 | 283 |
| 284 std::string received_message(buffer.begin(), buffer.end()); | 284 std::string received_message(buffer.begin(), buffer.end()); |
| 285 ASSERT_EQ(message, received_message); | 285 ASSERT_EQ(message, received_message); |
| 286 } | 286 } |
| 287 | 287 |
| 288 TEST_F(TCPSocketTest, ErrorOOBForTCPUrgentData) { |
| 289 ASSERT_NO_FATAL_FAILURE(SetUpListenIPv4()); |
| 290 |
| 291 TestCompletionCallback connect_callback; |
| 292 TCPSocket connecting_socket(NULL, NetLog::Source()); |
| 293 int result = connecting_socket.Open(ADDRESS_FAMILY_IPV4); |
| 294 ASSERT_EQ(OK, result); |
| 295 connecting_socket.Connect(local_address_, connect_callback.callback()); |
| 296 |
| 297 TestCompletionCallback accept_callback; |
| 298 scoped_ptr<TCPSocket> accepted_socket; |
| 299 IPEndPoint accepted_address; |
| 300 result = socket_.Accept(&accepted_socket, &accepted_address, |
| 301 accept_callback.callback()); |
| 302 ASSERT_EQ(OK, accept_callback.GetResult(result)); |
| 303 |
| 304 ASSERT_TRUE(accepted_socket.get()); |
| 305 |
| 306 // Both sockets should be on the loopback network interface. |
| 307 EXPECT_EQ(accepted_address.address(), local_address_.address()); |
| 308 |
| 309 EXPECT_EQ(OK, connect_callback.WaitForResult()); |
| 310 |
| 311 // Send the TCP urgent data, which is a single byte of OOB data. |
| 312 char byte = '@'; |
| 313 ssize_t sent = send(accepted_socket->socket(), &byte, sizeof(byte), MSG_OOB); |
| 314 ASSERT_EQ(1, sent); |
| 315 |
| 316 // Read the urgent data. |
| 317 scoped_refptr<IOBufferWithSize> buffer(new IOBufferWithSize(8)); |
| 318 TestCompletionCallback read_callback; |
| 319 result = connecting_socket.Read(buffer.get(), buffer->size(), |
| 320 read_callback.callback()); |
| 321 EXPECT_EQ(ERR_OOB_DATA, result); |
| 322 EXPECT_EQ(byte, buffer->data()[0]); |
| 323 } |
| 324 |
| 288 } // namespace | 325 } // namespace |
| 289 } // namespace net | 326 } // namespace net |
| OLD | NEW |