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

Unified Diff: chrome/browser/extensions/api/socket/socket_api.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, 7 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: chrome/browser/extensions/api/socket/socket_api.cc
diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
index 49699d26b932aafe61c2bec7ef0062f6bbd045b7..0dc43ec9b6299e3c9c872776a9454d24cef84d9e 100644
--- a/chrome/browser/extensions/api/socket/socket_api.cc
+++ b/chrome/browser/extensions/api/socket/socket_api.cc
@@ -44,6 +44,9 @@ const char kTCPSocketBindError[] =
"TCP socket does not support bind. For TCP server please use listen.";
const char kMulticastSocketTypeError[] =
"Only UDP socket supports multicast.";
+const char kAddressReuseSocketTypeError[] =
+ "There is no need to call AllowReuseAddress on TCP sockets, as TCP sockets"
+ " support address reuse by default.";
const char kWildcardAddress[] = "*";
const int kWildcardPort = 0;
@@ -742,7 +745,6 @@ void SocketJoinGroupFunction::Work() {
SetResult(Value::CreateIntegerValue(result));
}
-
SocketLeaveGroupFunction::SocketLeaveGroupFunction()
: params_(NULL) {}
@@ -899,4 +901,36 @@ void SocketGetJoinedGroupsFunction::Work() {
SetResult(values);
}
+SocketAllowAddressReuseFunction::SocketAllowAddressReuseFunction()
+ : params_(NULL) {}
+
+SocketAllowAddressReuseFunction::~SocketAllowAddressReuseFunction() {}
+
+bool SocketAllowAddressReuseFunction::Prepare() {
+ params_ = api::socket::AllowAddressReuse::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params_.get());
+ return true;
+}
+
+void SocketAllowAddressReuseFunction::Work() {
+ int result = -1;
+ Socket* socket = GetSocket(params_->socket_id);
+ if (!socket) {
+ error_ = kSocketNotFoundError;
+ SetResult(Value::CreateIntegerValue(result));
+ return;
+ }
+
+ if (socket->GetSocketType() != Socket::TYPE_UDP) {
+ error_ = kAddressReuseSocketTypeError;
+ SetResult(Value::CreateIntegerValue(result));
+ return;
+ }
+
+ result = static_cast<UDPSocket*>(socket)->AllowAddressReuse();
+ if (result != 0)
+ error_ = net::ErrorToString(result);
+ SetResult(Value::CreateIntegerValue(result));
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/socket/socket_api.h ('k') | chrome/browser/extensions/api/socket/udp_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698