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

Unified Diff: extensions/browser/api/socket/udp_socket.cc

Issue 2378763003: Add ability to reuse address in chrome.sockets.udp
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/socket/udp_socket.cc
diff --git a/extensions/browser/api/socket/udp_socket.cc b/extensions/browser/api/socket/udp_socket.cc
index e65957493849ae6d1b85eb500974e712870ecfe6..b4cc0e664ccfb253c8d948da5c301a55ca723cc9 100644
--- a/extensions/browser/api/socket/udp_socket.cc
+++ b/extensions/browser/api/socket/udp_socket.cc
@@ -74,6 +74,10 @@ int UDPSocket::Bind(const std::string& address, uint16_t port) {
if (result != net::OK)
return result;
+ if (IsReusable()) {
+ socket_.AllowAddressReuse();
+ }
+
result = socket_.Bind(ip_end_point);
if (result != net::OK)
socket_.Close();
@@ -248,6 +252,11 @@ void UDPSocket::OnSendToComplete(int result) {
bool UDPSocket::IsBound() { return socket_.is_connected(); }
+bool UDPSocket::IsReusable() {
+ // Only ResumableUDPSocket can be reusable
+ return false;
+}
+
int UDPSocket::JoinGroup(const std::string& address) {
net::IPAddress ip;
if (!ip.AssignFromIPLiteral(address))
@@ -305,8 +314,13 @@ ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id)
: UDPSocket(owner_extension_id),
persistent_(false),
buffer_size_(0),
- paused_(false) {}
+ paused_(false),
+ allow_address_reuse_(false) {}
bool ResumableUDPSocket::IsPersistent() const { return persistent(); }
+bool ResumableUDPSocket::IsReusable() {
+ return allow_address_reuse();
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698