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 "ppapi/tests/test_utils.h" | 5 #include "ppapi/tests/test_utils.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #if defined(_MSC_VER) | 10 #if defined(_MSC_VER) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 *addr = pp::NetAddress(instance_handle, ipv6_addr); | 173 *addr = pp::NetAddress(instance_handle, ipv6_addr); |
174 return true; | 174 return true; |
175 } | 175 } |
176 default: { | 176 default: { |
177 return false; | 177 return false; |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
| 182 bool ReplacePort(PP_Instance instance, |
| 183 const pp::NetAddress& input_addr, |
| 184 uint16_t port, |
| 185 pp::NetAddress* output_addr) { |
| 186 switch (input_addr.GetFamily()) { |
| 187 case PP_NETADDRESS_FAMILY_IPV4: { |
| 188 PP_NetAddress_IPv4 ipv4_addr; |
| 189 if (!input_addr.DescribeAsIPv4Address(&ipv4_addr)) |
| 190 return false; |
| 191 ipv4_addr.port = ConvertToNetEndian16(port); |
| 192 *output_addr = pp::NetAddress(pp::InstanceHandle(instance), ipv4_addr); |
| 193 return true; |
| 194 } |
| 195 case PP_NETADDRESS_FAMILY_IPV6: { |
| 196 PP_NetAddress_IPv6 ipv6_addr; |
| 197 if (!input_addr.DescribeAsIPv6Address(&ipv6_addr)) |
| 198 return false; |
| 199 ipv6_addr.port = ConvertToNetEndian16(port); |
| 200 *output_addr = pp::NetAddress(pp::InstanceHandle(instance), ipv6_addr); |
| 201 return true; |
| 202 } |
| 203 default: { |
| 204 return false; |
| 205 } |
| 206 } |
| 207 } |
| 208 |
| 209 uint16_t GetPort(const pp::NetAddress& addr) { |
| 210 switch (addr.GetFamily()) { |
| 211 case PP_NETADDRESS_FAMILY_IPV4: { |
| 212 PP_NetAddress_IPv4 ipv4_addr; |
| 213 if (!addr.DescribeAsIPv4Address(&ipv4_addr)) |
| 214 return 0; |
| 215 return ConvertFromNetEndian16(ipv4_addr.port); |
| 216 } |
| 217 case PP_NETADDRESS_FAMILY_IPV6: { |
| 218 PP_NetAddress_IPv6 ipv6_addr; |
| 219 if (!addr.DescribeAsIPv6Address(&ipv6_addr)) |
| 220 return 0; |
| 221 return ConvertFromNetEndian16(ipv6_addr.port); |
| 222 } |
| 223 default: { |
| 224 return 0; |
| 225 } |
| 226 } |
| 227 } |
| 228 |
182 void NestedEvent::Wait() { | 229 void NestedEvent::Wait() { |
183 PP_DCHECK(pp::Module::Get()->core()->IsMainThread()); | 230 PP_DCHECK(pp::Module::Get()->core()->IsMainThread()); |
184 // Don't allow nesting more than once; it doesn't work with the code as-is, | 231 // Don't allow nesting more than once; it doesn't work with the code as-is, |
185 // and probably is a bad idea most of the time anyway. | 232 // and probably is a bad idea most of the time anyway. |
186 PP_DCHECK(!waiting_); | 233 PP_DCHECK(!waiting_); |
187 if (signalled_) | 234 if (signalled_) |
188 return; | 235 return; |
189 waiting_ = true; | 236 waiting_ = true; |
190 while (!signalled_) | 237 while (!signalled_) |
191 GetTestingInterface()->RunMessageLoop(instance_); | 238 GetTestingInterface()->RunMessageLoop(instance_); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 pp::MessageLoop loop(pp::MessageLoop::GetCurrent()); | 416 pp::MessageLoop loop(pp::MessageLoop::GetCurrent()); |
370 // If we don't have a message loop, we're probably running in process, where | 417 // If we don't have a message loop, we're probably running in process, where |
371 // PPB_MessageLoop is not supported. Just use the Testing message loop. | 418 // PPB_MessageLoop is not supported. Just use the Testing message loop. |
372 if (loop.is_null() || loop == pp::MessageLoop::GetForMainThread()) { | 419 if (loop.is_null() || loop == pp::MessageLoop::GetForMainThread()) { |
373 GetTestingInterface()->QuitMessageLoop(instance_); | 420 GetTestingInterface()->QuitMessageLoop(instance_); |
374 } else { | 421 } else { |
375 const bool should_quit = false; | 422 const bool should_quit = false; |
376 loop.PostQuit(should_quit); | 423 loop.PostQuit(should_quit); |
377 } | 424 } |
378 } | 425 } |
OLD | NEW |