1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/proxy/udp_socket_resource.h"
7 #include "ppapi/shared_impl/tracked_callback.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_net_address_api.h"
10 #include "ppapi/thunk/resource_creation_api.h"
17 typedef thunk::EnterResourceNoLock
<thunk::PPB_NetAddress_API
>
18 EnterNetAddressNoLock
;
22 UDPSocketResource::UDPSocketResource(Connection connection
,
24 : UDPSocketResourceBase(connection
, instance
, false) {
27 UDPSocketResource::~UDPSocketResource() {
30 thunk::PPB_UDPSocket_API
* UDPSocketResource::AsPPB_UDPSocket_API() {
34 int32_t UDPSocketResource::Bind(PP_Resource addr
,
35 scoped_refptr
<TrackedCallback
> callback
) {
36 EnterNetAddressNoLock
enter(addr
, true);
38 return PP_ERROR_BADARGUMENT
;
40 return BindImpl(&enter
.object()->GetNetAddressPrivate(), callback
);
43 PP_Resource
UDPSocketResource::GetBoundAddress() {
44 PP_NetAddress_Private addr_private
;
45 if (!GetBoundAddressImpl(&addr_private
))
48 thunk::EnterResourceCreationNoLock
enter(pp_instance());
51 return enter
.functions()->CreateNetAddressFromNetAddressPrivate(
52 pp_instance(), addr_private
);
55 int32_t UDPSocketResource::RecvFrom(char* buffer
,
58 scoped_refptr
<TrackedCallback
> callback
) {
59 return RecvFromImpl(buffer
, num_bytes
, addr
, callback
);
62 int32_t UDPSocketResource::SendTo(const char* buffer
,
65 scoped_refptr
<TrackedCallback
> callback
) {
66 EnterNetAddressNoLock
enter(addr
, true);
68 return PP_ERROR_BADARGUMENT
;
70 return SendToImpl(buffer
, num_bytes
, &enter
.object()->GetNetAddressPrivate(),
74 void UDPSocketResource::Close() {
78 int32_t UDPSocketResource::SetOption1_0(
79 PP_UDPSocket_Option name
,
81 scoped_refptr
<TrackedCallback
> callback
) {
82 if (name
> PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE
)
83 return PP_ERROR_BADARGUMENT
;
85 return SetOptionImpl(name
, value
,
86 true, // Check bind() state.
90 int32_t UDPSocketResource::SetOption1_1(
91 PP_UDPSocket_Option name
,
93 scoped_refptr
<TrackedCallback
> callback
) {
94 if (name
> PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE
)
95 return PP_ERROR_BADARGUMENT
;
97 return SetOptionImpl(name
, value
,
98 false, // Check bind() state.
102 int32_t UDPSocketResource::SetOption(
103 PP_UDPSocket_Option name
,
105 scoped_refptr
<TrackedCallback
> callback
) {
106 return SetOptionImpl(name
, value
,
107 false, // Check bind() state.
111 int32_t UDPSocketResource::JoinGroup(
113 scoped_refptr
<TrackedCallback
> callback
) {
114 EnterNetAddressNoLock
enter(group
, true);
116 return PP_ERROR_BADRESOURCE
;
118 return JoinGroupImpl(&enter
.object()->GetNetAddressPrivate(),
122 int32_t UDPSocketResource::LeaveGroup(
124 scoped_refptr
<TrackedCallback
> callback
) {
125 EnterNetAddressNoLock
enter(group
, true);
127 return PP_ERROR_BADRESOURCE
;
129 return LeaveGroupImpl(&enter
.object()->GetNetAddressPrivate(),