1 // Copyright (c) 2012 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_private_resource.h"
7 #include "base/logging.h"
8 #include "ppapi/c/ppb_udp_socket.h"
9 #include "ppapi/shared_impl/tracked_callback.h"
14 UDPSocketPrivateResource::UDPSocketPrivateResource(Connection connection
,
16 : UDPSocketResourceBase(connection
, instance
, true) {
19 UDPSocketPrivateResource::~UDPSocketPrivateResource() {
22 thunk::PPB_UDPSocket_Private_API
*
23 UDPSocketPrivateResource::AsPPB_UDPSocket_Private_API() {
27 int32_t UDPSocketPrivateResource::SetSocketFeature(
28 PP_UDPSocketFeature_Private name
,
30 PP_UDPSocket_Option public_name
= PP_UDPSOCKET_OPTION_ADDRESS_REUSE
;
32 case PP_UDPSOCKETFEATURE_PRIVATE_ADDRESS_REUSE
:
33 // |public_name| has been initialized above.
35 case PP_UDPSOCKETFEATURE_PRIVATE_BROADCAST
:
36 public_name
= PP_UDPSOCKET_OPTION_BROADCAST
;
38 case PP_UDPSOCKETFEATURE_PRIVATE_COUNT
:
39 return PP_ERROR_BADARGUMENT
;
42 return PP_ERROR_BADARGUMENT
;
44 int32_t result
= SetOptionImpl(public_name
, value
,
45 true, // Check bind() state.
47 return result
== PP_OK_COMPLETIONPENDING
? PP_OK
: result
;
50 int32_t UDPSocketPrivateResource::Bind(
51 const PP_NetAddress_Private
* addr
,
52 scoped_refptr
<TrackedCallback
> callback
) {
53 return BindImpl(addr
, callback
);
56 PP_Bool
UDPSocketPrivateResource::GetBoundAddress(PP_NetAddress_Private
* addr
) {
57 return GetBoundAddressImpl(addr
);
60 int32_t UDPSocketPrivateResource::RecvFrom(
63 scoped_refptr
<TrackedCallback
> callback
) {
64 return RecvFromImpl(buffer
, num_bytes
, NULL
, callback
);
67 PP_Bool
UDPSocketPrivateResource::GetRecvFromAddress(
68 PP_NetAddress_Private
* addr
) {
69 return GetRecvFromAddressImpl(addr
);
72 int32_t UDPSocketPrivateResource::SendTo(
75 const PP_NetAddress_Private
* addr
,
76 scoped_refptr
<TrackedCallback
> callback
) {
77 return SendToImpl(buffer
, num_bytes
, addr
, callback
);
80 void UDPSocketPrivateResource::Close() {