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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 void UDPSocketTest::ConnectTest(bool use_nonblocking_io) { | 163 void UDPSocketTest::ConnectTest(bool use_nonblocking_io) { |
164 const uint16_t kPort = 9999; | 164 const uint16_t kPort = 9999; |
165 std::string simple_message("hello world!"); | 165 std::string simple_message("hello world!"); |
166 | 166 |
167 // Setup the server to listen. | 167 // Setup the server to listen. |
168 IPEndPoint bind_address; | 168 IPEndPoint bind_address; |
169 CreateUDPAddress("127.0.0.1", kPort, &bind_address); | 169 CreateUDPAddress("127.0.0.1", kPort, &bind_address); |
170 TestNetLog server_log; | 170 TestNetLog server_log; |
171 std::unique_ptr<UDPServerSocket> server( | 171 std::unique_ptr<UDPServerSocket> server( |
172 new UDPServerSocket(&server_log, NetLog::Source())); | 172 new UDPServerSocket(&server_log, NetLog::Source())); |
173 #if defined(OS_WIN) | |
174 if (use_nonblocking_io) | 173 if (use_nonblocking_io) |
175 server->UseNonBlockingIO(); | 174 server->UseNonBlockingIO(); |
176 #endif | |
177 server->AllowAddressReuse(); | 175 server->AllowAddressReuse(); |
178 int rv = server->Listen(bind_address); | 176 int rv = server->Listen(bind_address); |
179 ASSERT_THAT(rv, IsOk()); | 177 ASSERT_THAT(rv, IsOk()); |
180 | 178 |
181 // Setup the client. | 179 // Setup the client. |
182 IPEndPoint server_address; | 180 IPEndPoint server_address; |
183 CreateUDPAddress("127.0.0.1", kPort, &server_address); | 181 CreateUDPAddress("127.0.0.1", kPort, &server_address); |
184 TestNetLog client_log; | 182 TestNetLog client_log; |
185 std::unique_ptr<UDPClientSocket> client( | 183 std::unique_ptr<UDPClientSocket> client( |
186 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), | 184 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), |
187 &client_log, NetLog::Source())); | 185 &client_log, NetLog::Source())); |
188 #if defined(OS_WIN) | |
189 if (use_nonblocking_io) | 186 if (use_nonblocking_io) |
190 client->UseNonBlockingIO(); | 187 client->UseNonBlockingIO(); |
191 #endif | |
192 | 188 |
193 rv = client->Connect(server_address); | 189 rv = client->Connect(server_address); |
194 EXPECT_THAT(rv, IsOk()); | 190 EXPECT_THAT(rv, IsOk()); |
195 | 191 |
196 // Client sends to the server. | 192 // Client sends to the server. |
197 rv = WriteSocket(client.get(), simple_message); | 193 rv = WriteSocket(client.get(), simple_message); |
198 EXPECT_EQ(simple_message.length(), static_cast<size_t>(rv)); | 194 EXPECT_EQ(simple_message.length(), static_cast<size_t>(rv)); |
199 | 195 |
200 // Server waits for message. | 196 // Server waits for message. |
201 std::string str = RecvFromSocket(server.get()); | 197 std::string str = RecvFromSocket(server.get()); |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; | 855 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; |
860 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_NO_CHANGE), IsOk()); | 856 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_NO_CHANGE), IsOk()); |
861 g_expected_dscp = DSCP_DEFAULT; | 857 g_expected_dscp = DSCP_DEFAULT; |
862 g_expected_traffic_type = QOSTrafficTypeBestEffort; | 858 g_expected_traffic_type = QOSTrafficTypeBestEffort; |
863 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_DEFAULT), IsOk()); | 859 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_DEFAULT), IsOk()); |
864 client.Close(); | 860 client.Close(); |
865 } | 861 } |
866 #endif | 862 #endif |
867 | 863 |
868 } // namespace net | 864 } // namespace net |
OLD | NEW |