Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: net/udp/udp_client_socket.cc

Issue 1416213003: Add DatagramClientSocket::BindToDefaultNetwork(),GetBoundNetwork() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/udp/udp_client_socket.h ('k') | net/udp/udp_socket_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_client_socket.h" 5 #include "net/udp/udp_client_socket.h"
6 6
7 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
8 #include "net/log/net_log.h" 8 #include "net/log/net_log.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 UDPClientSocket::UDPClientSocket(DatagramSocket::BindType bind_type, 12 UDPClientSocket::UDPClientSocket(DatagramSocket::BindType bind_type,
13 const RandIntCallback& rand_int_cb, 13 const RandIntCallback& rand_int_cb,
14 net::NetLog* net_log, 14 net::NetLog* net_log,
15 const net::NetLog::Source& source) 15 const net::NetLog::Source& source)
16 : socket_(bind_type, rand_int_cb, net_log, source) { 16 : socket_(bind_type, rand_int_cb, net_log, source),
17 } 17 network_(NetworkChangeNotifier::kInvalidNetworkHandle) {}
18 18
19 UDPClientSocket::~UDPClientSocket() { 19 UDPClientSocket::~UDPClientSocket() {
20 } 20 }
21 21
22 int UDPClientSocket::BindToNetwork( 22 int UDPClientSocket::BindToNetwork(
23 NetworkChangeNotifier::NetworkHandle network) { 23 NetworkChangeNotifier::NetworkHandle network) {
24 return socket_.BindToNetwork(network); 24 int rv = socket_.BindToNetwork(network);
25 if (rv == OK)
26 network_ = network;
27 return rv;
28 }
29
30 int UDPClientSocket::BindToDefaultNetwork() {
31 int rv;
32 for (int attempt = 0; attempt < 5; attempt++) {
33 NetworkChangeNotifier::NetworkHandle network;
34 rv = NetworkChangeNotifier::GetDefaultNetwork(&network);
35 if (rv != OK)
36 return rv;
37 if (network == NetworkChangeNotifier::kInvalidNetworkHandle)
38 return ERR_INTERNET_DISCONNECTED;
39 rv = BindToNetwork(network);
40 // |network| may have disconnected between the time we query
41 // GetDefaultNetwork() and when we call BindToNetwork(). Loop if this is the
42 // case (|rv| will be ERR_NETWORK_CHANGED).
43 if (rv != ERR_NETWORK_CHANGED)
44 return rv;
45 }
46 return rv;
47 }
48
49 NetworkChangeNotifier::NetworkHandle UDPClientSocket::GetBoundNetwork() {
50 return network_;
25 } 51 }
26 52
27 int UDPClientSocket::Connect(const IPEndPoint& address) { 53 int UDPClientSocket::Connect(const IPEndPoint& address) {
28 int rv = socket_.Open(address.GetFamily()); 54 int rv = socket_.Open(address.GetFamily());
29 if (rv != OK) 55 if (rv != OK)
30 return rv; 56 return rv;
31 return socket_.Connect(address); 57 return socket_.Connect(address);
32 } 58 }
33 59
34 int UDPClientSocket::Read(IOBuffer* buf, 60 int UDPClientSocket::Read(IOBuffer* buf,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return socket_.NetLog(); 93 return socket_.NetLog();
68 } 94 }
69 95
70 #if defined(OS_WIN) 96 #if defined(OS_WIN)
71 void UDPClientSocket::UseNonBlockingIO() { 97 void UDPClientSocket::UseNonBlockingIO() {
72 socket_.UseNonBlockingIO(); 98 socket_.UseNonBlockingIO();
73 } 99 }
74 #endif 100 #endif
75 101
76 } // namespace net 102 } // namespace net
OLDNEW
« no previous file with comments | « net/udp/udp_client_socket.h ('k') | net/udp/udp_socket_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698