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/udp/udp_socket.h" | 5 #include "net/udp/udp_socket.h" |
6 | 6 |
7 #include "net/udp/udp_client_socket.h" | 7 #include "net/udp/udp_client_socket.h" |
8 #include "net/udp/udp_server_socket.h" | 8 #include "net/udp/udp_server_socket.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 CreateUDPAddress("127.0.0.1", 0, &bind_address); | 570 CreateUDPAddress("127.0.0.1", 0, &bind_address); |
571 UDPServerSocket server(NULL, NetLog::Source()); | 571 UDPServerSocket server(NULL, NetLog::Source()); |
572 int rv = server.Listen(bind_address); | 572 int rv = server.Listen(bind_address); |
573 EXPECT_THAT(rv, IsOk()); | 573 EXPECT_THAT(rv, IsOk()); |
574 | 574 |
575 IPEndPoint peer_address; | 575 IPEndPoint peer_address; |
576 rv = server.GetPeerAddress(&peer_address); | 576 rv = server.GetPeerAddress(&peer_address); |
577 EXPECT_EQ(rv, ERR_SOCKET_NOT_CONNECTED); | 577 EXPECT_EQ(rv, ERR_SOCKET_NOT_CONNECTED); |
578 } | 578 } |
579 | 579 |
| 580 TEST_F(UDPSocketTest, ClientSetDoNotFragment) { |
| 581 for (std::string ip : {"127.0.0.1", "::1"}) { |
| 582 LOG(INFO) << "ip: " << ip; |
| 583 UDPClientSocket client(DatagramSocket::DEFAULT_BIND, RandIntCallback(), |
| 584 nullptr, NetLog::Source()); |
| 585 IPAddress ip_address; |
| 586 EXPECT_TRUE(ip_address.AssignFromIPLiteral(ip)); |
| 587 IPEndPoint remote_address(ip_address, 80); |
| 588 int rv = client.Connect(remote_address); |
| 589 // May fail on IPv6 is IPv6 is not configured. |
| 590 if (ip_address.IsIPv6() && rv == ERR_ADDRESS_UNREACHABLE) |
| 591 return; |
| 592 EXPECT_THAT(rv, IsOk()); |
| 593 |
| 594 #if defined(OS_MACOSX) |
| 595 EXPECT_EQ(ERR_NOT_IMPLEMENTED, client.SetDoNotFragment()); |
| 596 #else |
| 597 rv = client.SetDoNotFragment(); |
| 598 EXPECT_THAT(rv, IsOk()); |
| 599 #endif |
| 600 } |
| 601 } |
| 602 |
| 603 TEST_F(UDPSocketTest, ServerSetDoNotFragment) { |
| 604 for (std::string ip : {"127.0.0.1", "::1"}) { |
| 605 LOG(INFO) << "ip: " << ip; |
| 606 IPEndPoint bind_address; |
| 607 CreateUDPAddress(ip, 0, &bind_address); |
| 608 UDPServerSocket server(nullptr, NetLog::Source()); |
| 609 int rv = server.Listen(bind_address); |
| 610 // May fail on IPv6 is IPv6 is not configure |
| 611 if (bind_address.address().IsIPv6() && rv == ERR_ADDRESS_INVALID) |
| 612 return; |
| 613 EXPECT_THAT(rv, IsOk()); |
| 614 |
| 615 #if defined(OS_MACOSX) |
| 616 EXPECT_EQ(ERR_NOT_IMPLEMENTED, server.SetDoNotFragment()); |
| 617 #else |
| 618 rv = server.SetDoNotFragment(); |
| 619 EXPECT_THAT(rv, IsOk()); |
| 620 #endif |
| 621 } |
| 622 } |
| 623 |
580 // Close the socket while read is pending. | 624 // Close the socket while read is pending. |
581 TEST_F(UDPSocketTest, CloseWithPendingRead) { | 625 TEST_F(UDPSocketTest, CloseWithPendingRead) { |
582 IPEndPoint bind_address; | 626 IPEndPoint bind_address; |
583 CreateUDPAddress("127.0.0.1", 0, &bind_address); | 627 CreateUDPAddress("127.0.0.1", 0, &bind_address); |
584 UDPServerSocket server(NULL, NetLog::Source()); | 628 UDPServerSocket server(NULL, NetLog::Source()); |
585 int rv = server.Listen(bind_address); | 629 int rv = server.Listen(bind_address); |
586 EXPECT_THAT(rv, IsOk()); | 630 EXPECT_THAT(rv, IsOk()); |
587 | 631 |
588 TestCompletionCallback callback; | 632 TestCompletionCallback callback; |
589 IPEndPoint from; | 633 IPEndPoint from; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; | 899 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; |
856 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_NO_CHANGE), IsOk()); | 900 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_NO_CHANGE), IsOk()); |
857 g_expected_dscp = DSCP_DEFAULT; | 901 g_expected_dscp = DSCP_DEFAULT; |
858 g_expected_traffic_type = QOSTrafficTypeBestEffort; | 902 g_expected_traffic_type = QOSTrafficTypeBestEffort; |
859 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_DEFAULT), IsOk()); | 903 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_DEFAULT), IsOk()); |
860 client.Close(); | 904 client.Close(); |
861 } | 905 } |
862 #endif | 906 #endif |
863 | 907 |
864 } // namespace net | 908 } // namespace net |
OLD | NEW |