OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/cast/test/utility/net_utility.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "net/base/net_errors.h" | |
9 #include "net/udp/udp_socket.h" | |
10 | |
11 namespace media { | |
12 namespace cast { | |
13 namespace test { | |
14 | |
15 // TODO(hubbe): Move to /net/. | |
16 net::IPEndPoint GetFreeLocalPort() { | |
17 // Determine a unused UDP port for the in-process receiver to listen on. | |
miu
2014/05/15 02:48:48
nit: IMHO, these 3 lines of comments would be more
hubbe
2014/05/16 01:04:45
Done.
| |
18 // Method: Bind a UDP socket on port 0, and then check which port the | |
19 // operating system assigned to it. | |
20 net::IPAddressNumber localhost; | |
21 localhost.push_back(127); | |
22 localhost.push_back(0); | |
23 localhost.push_back(0); | |
24 localhost.push_back(1); | |
25 scoped_ptr<net::UDPSocket> receive_socket( | |
26 new net::UDPSocket(net::DatagramSocket::DEFAULT_BIND, | |
27 net::RandIntCallback(), | |
28 NULL, | |
29 net::NetLog::Source())); | |
30 receive_socket->AllowAddressReuse(); | |
31 CHECK_EQ(net::OK, receive_socket->Bind(net::IPEndPoint(localhost, 0))); | |
32 net::IPEndPoint endpoint; | |
33 CHECK_EQ(net::OK, receive_socket->GetLocalAddress(&endpoint)); | |
34 return endpoint; | |
35 } | |
36 | |
37 } // namespace test | |
38 } // namespace cast | |
39 } // namespace media | |
OLD | NEW |