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. 4 5 #include "ppapi/proxy/udp_socket_private_resource.h" 6 7 #include "base/logging.h" 8 #include "ppapi/c/ppb_udp_socket.h" 9 #include "ppapi/shared_impl/tracked_callback.h" 10 11 namespace ppapi { 12 namespace proxy { 13 14 UDPSocketPrivateResource::UDPSocketPrivateResource(Connection connection, 15 PP_Instance instance) 16 : UDPSocketResourceBase(connection, instance, true) { 17 } 18 19 UDPSocketPrivateResource::~UDPSocketPrivateResource() { 20 } 21 22 thunk::PPB_UDPSocket_Private_API* 23 UDPSocketPrivateResource::AsPPB_UDPSocket_Private_API() { 24 return this; 25 } 26 27 int32_t UDPSocketPrivateResource::SetSocketFeature( 28 PP_UDPSocketFeature_Private name, 29 PP_Var value) { 30 PP_UDPSocket_Option public_name = PP_UDPSOCKET_OPTION_ADDRESS_REUSE; 31 switch (name) { 32 case PP_UDPSOCKETFEATURE_PRIVATE_ADDRESS_REUSE: 33 // |public_name| has been initialized above. 34 break; 35 case PP_UDPSOCKETFEATURE_PRIVATE_BROADCAST: 36 public_name = PP_UDPSOCKET_OPTION_BROADCAST; 37 break; 38 case PP_UDPSOCKETFEATURE_PRIVATE_COUNT: 39 return PP_ERROR_BADARGUMENT; 40 default: 41 NOTREACHED(); 42 return PP_ERROR_BADARGUMENT; 43 } 44 int32_t result = SetOptionImpl(public_name, value, NULL); 45 return result == PP_OK_COMPLETIONPENDING ? PP_OK : result; 46 } 47 48 int32_t UDPSocketPrivateResource::Bind( 49 const PP_NetAddress_Private* addr, 50 scoped_refptr<TrackedCallback> callback) { 51 return BindImpl(addr, callback); 52 } 53 54 PP_Bool UDPSocketPrivateResource::GetBoundAddress(PP_NetAddress_Private* addr) { 55 return GetBoundAddressImpl(addr); 56 } 57 58 int32_t UDPSocketPrivateResource::RecvFrom( 59 char* buffer, 60 int32_t num_bytes, 61 scoped_refptr<TrackedCallback> callback) { 62 return RecvFromImpl(buffer, num_bytes, NULL, callback); 63 } 64 65 PP_Bool UDPSocketPrivateResource::GetRecvFromAddress( 66 PP_NetAddress_Private* addr) { 67 return GetRecvFromAddressImpl(addr); 68 } 69 70 int32_t UDPSocketPrivateResource::SendTo( 71 const char* buffer, 72 int32_t num_bytes, 73 const PP_NetAddress_Private* addr, 74 scoped_refptr<TrackedCallback> callback) { 75 return SendToImpl(buffer, num_bytes, addr, callback); 76 } 77 78 void UDPSocketPrivateResource::Close() { 79 CloseImpl(); 80 } 81 82 } // namespace proxy 83 } // namespace ppapi 84