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

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

Issue 2378763003: Add ability to reuse address in chrome.sockets.udp
Patch Set: Respond to code reviews, clean up tests Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "extensions/browser/api/socket/udp_socket.h" 5 #include "extensions/browser/api/socket/udp_socket.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 15 matching lines...) Expand all
26 BrowserContextKeyedAPIFactory<ApiResourceManager<ResumableUDPSocket> >* 26 BrowserContextKeyedAPIFactory<ApiResourceManager<ResumableUDPSocket> >*
27 ApiResourceManager<ResumableUDPSocket>::GetFactoryInstance() { 27 ApiResourceManager<ResumableUDPSocket>::GetFactoryInstance() {
28 return g_factory.Pointer(); 28 return g_factory.Pointer();
29 } 29 }
30 30
31 UDPSocket::UDPSocket(const std::string& owner_extension_id) 31 UDPSocket::UDPSocket(const std::string& owner_extension_id)
32 : Socket(owner_extension_id), 32 : Socket(owner_extension_id),
33 socket_(net::DatagramSocket::DEFAULT_BIND, 33 socket_(net::DatagramSocket::DEFAULT_BIND,
34 net::RandIntCallback(), 34 net::RandIntCallback(),
35 NULL, 35 NULL,
36 net::NetLog::Source()) {} 36 net::NetLog::Source()),
37 allow_address_reuse_(false) {}
37 38
38 UDPSocket::~UDPSocket() { Disconnect(); } 39 UDPSocket::~UDPSocket() { Disconnect(); }
39 40
40 void UDPSocket::Connect(const net::AddressList& address, 41 void UDPSocket::Connect(const net::AddressList& address,
41 const CompletionCallback& callback) { 42 const CompletionCallback& callback) {
42 int result = net::ERR_CONNECTION_FAILED; 43 int result = net::ERR_CONNECTION_FAILED;
43 do { 44 do {
44 if (is_connected_) 45 if (is_connected_)
45 break; 46 break;
46 47
(...skipping 20 matching lines...) Expand all
67 return net::ERR_CONNECTION_FAILED; 68 return net::ERR_CONNECTION_FAILED;
68 69
69 net::IPEndPoint ip_end_point; 70 net::IPEndPoint ip_end_point;
70 if (!StringAndPortToIPEndPoint(address, port, &ip_end_point)) 71 if (!StringAndPortToIPEndPoint(address, port, &ip_end_point))
71 return net::ERR_INVALID_ARGUMENT; 72 return net::ERR_INVALID_ARGUMENT;
72 73
73 int result = socket_.Open(ip_end_point.GetFamily()); 74 int result = socket_.Open(ip_end_point.GetFamily());
74 if (result != net::OK) 75 if (result != net::OK)
75 return result; 76 return result;
76 77
78 if (allow_address_reuse()) {
79 socket_.AllowAddressReuse();
80 }
81
77 result = socket_.Bind(ip_end_point); 82 result = socket_.Bind(ip_end_point);
78 if (result != net::OK) 83 if (result != net::OK)
79 socket_.Close(); 84 socket_.Close();
80 return result; 85 return result;
81 } 86 }
82 87
83 void UDPSocket::Disconnect() { 88 void UDPSocket::Disconnect() {
84 is_connected_ = false; 89 is_connected_ = false;
85 socket_.Close(); 90 socket_.Close();
86 read_callback_.Reset(); 91 read_callback_.Reset();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 308
304 ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id) 309 ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id)
305 : UDPSocket(owner_extension_id), 310 : UDPSocket(owner_extension_id),
306 persistent_(false), 311 persistent_(false),
307 buffer_size_(0), 312 buffer_size_(0),
308 paused_(false) {} 313 paused_(false) {}
309 314
310 bool ResumableUDPSocket::IsPersistent() const { return persistent(); } 315 bool ResumableUDPSocket::IsPersistent() const { return persistent(); }
311 316
312 } // namespace extensions 317 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/socket/udp_socket.h ('k') | extensions/browser/api/sockets_udp/sockets_udp_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698