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

Side by Side Diff: chrome/browser/extensions/api/socket/udp_socket.cc

Issue 15039012: Add the ability to use AllowAddressReuse for UDP sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master Created 7 years, 6 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
OLDNEW
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 "chrome/browser/extensions/api/socket/udp_socket.h" 5 #include "chrome/browser/extensions/api/socket/udp_socket.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "chrome/browser/extensions/api/api_resource.h" 9 #include "chrome/browser/extensions/api/api_resource.h"
10 #include "net/base/ip_endpoint.h" 10 #include "net/base/ip_endpoint.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 normalized_address); 236 normalized_address);
237 if (find_result != multicast_groups_.end()) 237 if (find_result != multicast_groups_.end())
238 return net::ERR_ADDRESS_INVALID; 238 return net::ERR_ADDRESS_INVALID;
239 239
240 int rv = socket_.JoinGroup(ip); 240 int rv = socket_.JoinGroup(ip);
241 if (rv == 0) 241 if (rv == 0)
242 multicast_groups_.push_back(normalized_address); 242 multicast_groups_.push_back(normalized_address);
243 return rv; 243 return rv;
244 } 244 }
245 245
246 int UDPSocket::AllowAddressReuse() {
247 if (socket_.is_connected()) {
248 return net::ERR_UNEXPECTED;
249 }
250 socket_.AllowAddressReuse();
251 return 0;
252 }
253
246 int UDPSocket::LeaveGroup(const std::string& address) { 254 int UDPSocket::LeaveGroup(const std::string& address) {
247 net::IPAddressNumber ip; 255 net::IPAddressNumber ip;
248 if (!net::ParseIPLiteralToNumber(address, &ip)) 256 if (!net::ParseIPLiteralToNumber(address, &ip))
249 return net::ERR_ADDRESS_INVALID; 257 return net::ERR_ADDRESS_INVALID;
250 258
251 std::string normalized_address = net::IPAddressToString(ip); 259 std::string normalized_address = net::IPAddressToString(ip);
252 std::vector<std::string>::iterator find_result = 260 std::vector<std::string>::iterator find_result =
253 std::find(multicast_groups_.begin(), 261 std::find(multicast_groups_.begin(),
254 multicast_groups_.end(), 262 multicast_groups_.end(),
255 normalized_address); 263 normalized_address);
(...skipping 12 matching lines...) Expand all
268 276
269 int UDPSocket::SetMulticastLoopbackMode(bool loopback) { 277 int UDPSocket::SetMulticastLoopbackMode(bool loopback) {
270 return socket_.SetMulticastLoopbackMode(loopback); 278 return socket_.SetMulticastLoopbackMode(loopback);
271 } 279 }
272 280
273 const std::vector<std::string>& UDPSocket::GetJoinedGroups() const { 281 const std::vector<std::string>& UDPSocket::GetJoinedGroups() const {
274 return multicast_groups_; 282 return multicast_groups_;
275 } 283 }
276 284
277 } // namespace extensions 285 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/socket/udp_socket.h ('k') | chrome/browser/extensions/extension_function_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698