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

Unified Diff: ppapi/proxy/udp_socket_resource.cc

Issue 16282005: Introduce PPB_UDPSocket_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/udp_socket_resource.cc
diff --git a/ppapi/proxy/udp_socket_resource.cc b/ppapi/proxy/udp_socket_resource.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f37ae0e73c4b928b9c9b3da093d9fb1716270105
--- /dev/null
+++ b/ppapi/proxy/udp_socket_resource.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/udp_socket_resource.h"
+
+#include "ppapi/shared_impl/tracked_callback.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_net_address_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
+
+namespace ppapi {
+namespace proxy {
+
+namespace {
+
+typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API>
+ EnterNetAddressNoLock;
+
+} // namespace
+
+UDPSocketResource::UDPSocketResource(Connection connection,
+ PP_Instance instance)
+ : UDPSocketShared(connection, instance) {
+}
+
+UDPSocketResource::~UDPSocketResource() {
+}
+
+thunk::PPB_UDPSocket_API* UDPSocketResource::AsPPB_UDPSocket_API() {
+ return this;
+}
+
+int32_t UDPSocketResource::Bind(PP_Resource addr,
+ scoped_refptr<TrackedCallback> callback) {
+ EnterNetAddressNoLock enter(addr, true);
+ if (enter.failed())
+ return PP_ERROR_BADARGUMENT;
+
+ return BindImpl(&enter.object()->GetNetAddressPrivate(), callback);
+}
+
+PP_Resource UDPSocketResource::GetBoundAddress() {
+ PP_NetAddress_Private addr_private;
+ if (!GetBoundAddressImpl(&addr_private))
+ return 0;
+
+ thunk::EnterResourceCreationNoLock enter(pp_instance());
+ if (enter.failed())
+ return 0;
+ return enter.functions()->CreateNetAddressFromNetAddressPrivate(
+ pp_instance(), addr_private);
+}
+
+int32_t UDPSocketResource::RecvFrom(char* buffer,
+ int32_t num_bytes,
+ PP_Resource* addr,
+ scoped_refptr<TrackedCallback> callback) {
+ return RecvFromImpl(buffer, num_bytes, addr, callback);
+}
+
+int32_t UDPSocketResource::SendTo(const char* buffer,
+ int32_t num_bytes,
+ PP_Resource addr,
+ scoped_refptr<TrackedCallback> callback) {
+ EnterNetAddressNoLock enter(addr, true);
+ if (enter.failed())
+ return PP_ERROR_BADARGUMENT;
+
+ return SendToImpl(buffer, num_bytes, &enter.object()->GetNetAddressPrivate(),
+ callback);
+}
+
+void UDPSocketResource::Close() {
+ CloseImpl();
+}
+
+int32_t UDPSocketResource::SetOption(
+ PP_UDPSocket_Option_Dev name,
+ const PP_Var& value,
+ scoped_refptr<TrackedCallback> /* callback */) {
+ // TODO(yzshen): Add support for other options.
+ PP_UDPSocketFeature_Private feature;
+ switch (name) {
+ case PP_UDPSOCKET_OPTION_ADDRESS_REUSE:
+ feature = PP_UDPSOCKETFEATURE_ADDRESS_REUSE;
+ break;
+ case PP_UDPSOCKET_OPTION_BROADCAST:
+ feature = PP_UDPSOCKETFEATURE_BROADCAST;
+ break;
+ default:
+ return PP_ERROR_NOTSUPPORTED;
+ }
+
+ return SetSocketFeatureImpl(feature, value);
+}
+
+} // namespace proxy
+} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698