diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-21 23:37:12 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-21 23:37:12 +0000 |
commit | 669b2839b2a307ab08bcbc217efdb8a9f146c7c1 (patch) | |
tree | 601f882f71731c441eecb5f8b97f6bd0b6e8e78b | |
parent | 6681478ec237fa2b66b122a98f8630cefab22abc (diff) | |
download | chromium_src-669b2839b2a307ab08bcbc217efdb8a9f146c7c1.zip chromium_src-669b2839b2a307ab08bcbc217efdb8a9f146c7c1.tar.gz chromium_src-669b2839b2a307ab08bcbc217efdb8a9f146c7c1.tar.bz2 |
GetBoundAddress will return the address that Bind actually bound to. If there has not been a successful call to Bind, this method will return an error.
BUG=no bug
TEST=udp tests
Review URL: https://chromiumcodereview.appspot.com/9212047
Patch from Mike Tilburg <mtilburg@adobe.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122910 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 338 insertions, 48 deletions
diff --git a/content/browser/renderer_host/pepper_message_filter.cc b/content/browser/renderer_host/pepper_message_filter.cc index 5d18560..b1a04c6 100644 --- a/content/browser/renderer_host/pepper_message_filter.cc +++ b/content/browser/renderer_host/pepper_message_filter.cc @@ -508,7 +508,7 @@ void PepperMessageFilter::DoUDPBind(bool allowed, if (routing_id == iter->second->routing_id() && allowed) iter->second->Bind(addr); else - iter->second->SendBindACK(false); + iter->second->SendBindACKError(); } void PepperMessageFilter::OnUDPRecvFrom(uint32 socket_id, int32_t num_bytes) { diff --git a/content/browser/renderer_host/pepper_udp_socket.cc b/content/browser/renderer_host/pepper_udp_socket.cc index 33f2c7f..836398d 100644 --- a/content/browser/renderer_host/pepper_udp_socket.cc +++ b/content/browser/renderer_host/pepper_udp_socket.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -43,13 +43,19 @@ void PepperUDPSocket::Bind(const PP_NetAddress_Private& addr) { net::IPEndPoint address; if (!socket_.get() || !NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address)) { - SendBindACK(false); + SendBindACKError(); return; } int result = socket_->Listen(address); - SendBindACK(result == net::OK); + if (result == net::OK && + socket_->GetLocalAddress(&bound_address_) != net::OK) { + SendBindACKError(); + return; + } + + OnBindCompleted(result); } void PepperUDPSocket::RecvFrom(int32_t num_bytes) { @@ -105,9 +111,22 @@ void PepperUDPSocket::SendSendToACKError() { routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); } -void PepperUDPSocket::SendBindACK(bool result) { +void PepperUDPSocket::SendBindACKError() { + PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( - routing_id_, plugin_dispatcher_id_, socket_id_, result)); + routing_id_, plugin_dispatcher_id_, socket_id_, false, addr)); +} + +void PepperUDPSocket::OnBindCompleted(int result) { + PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; + if (result < 0 || + !NetAddressPrivateImpl::IPEndPointToNetAddress(bound_address_, + &addr)) { + SendBindACKError(); + } else { + manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( + routing_id_, plugin_dispatcher_id_, socket_id_, true, addr)); + } } void PepperUDPSocket::OnRecvFromCompleted(int result) { diff --git a/content/browser/renderer_host/pepper_udp_socket.h b/content/browser/renderer_host/pepper_udp_socket.h index 23aad4a..a90e99f 100644 --- a/content/browser/renderer_host/pepper_udp_socket.h +++ b/content/browser/renderer_host/pepper_udp_socket.h @@ -38,13 +38,13 @@ class PepperUDPSocket { void Bind(const PP_NetAddress_Private& addr); void RecvFrom(int32_t num_bytes); void SendTo(const std::string& data, const PP_NetAddress_Private& addr); - - void SendBindACK(bool result); + void SendBindACKError(); private: void SendRecvFromACKError(); void SendSendToACKError(); + void OnBindCompleted(int result); void OnRecvFromCompleted(int result); void OnSendToCompleted(int result); @@ -59,6 +59,7 @@ class PepperUDPSocket { scoped_refptr<net::IOBuffer> sendto_buffer_; net::IPEndPoint recvfrom_address_; + net::IPEndPoint bound_address_; DISALLOW_COPY_AND_ASSIGN(PepperUDPSocket); }; diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc index 47eda0c..ff8e372 100644 --- a/content/renderer/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper_plugin_delegate_impl.cc @@ -2153,13 +2153,15 @@ void PepperPluginDelegateImpl::OnTCPSocketWriteACK(uint32 plugin_dispatcher_id, socket->OnWriteCompleted(succeeded, bytes_written); } -void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - bool succeeded) { +void PepperPluginDelegateImpl::OnUDPSocketBindACK( + uint32 plugin_dispatcher_id, + uint32 socket_id, + bool succeeded, + const PP_NetAddress_Private& addr) { webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = udp_sockets_.Lookup(socket_id); if (socket) - socket->OnBindCompleted(succeeded); + socket->OnBindCompleted(succeeded, addr); } void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK( diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h index 4e27538..527787a 100644 --- a/content/renderer/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper_plugin_delegate_impl.h @@ -416,7 +416,8 @@ class PepperPluginDelegateImpl int32_t bytes_written); void OnUDPSocketBindACK(uint32 plugin_dispatcher_id, uint32 socket_id, - bool succeeded); + bool succeeded, + const PP_NetAddress_Private& addr); void OnUDPSocketSendToACK(uint32 plugin_dispatcher_id, uint32 socket_id, bool succeeded, diff --git a/ppapi/api/private/ppb_udp_socket_private.idl b/ppapi/api/private/ppb_udp_socket_private.idl index 4babbb4..083c33d 100644 --- a/ppapi/api/private/ppb_udp_socket_private.idl +++ b/ppapi/api/private/ppb_udp_socket_private.idl @@ -8,7 +8,8 @@ */ label Chrome { - M17 = 0.2 + M17 = 0.2, + M19 = 0.3 }; interface PPB_UDPSocket_Private { @@ -27,6 +28,14 @@ interface PPB_UDPSocket_Private { [in] PP_NetAddress_Private addr, [in] PP_CompletionCallback callback); + /* Returns the address that the socket has bound to. A successful + * call to Bind must be called first. Returns PP_FALSE if Bind + * fails, or if Close has been called. + */ + [version=0.3] + PP_Bool GetBoundAddress([in] PP_Resource udp_socket, + [out] PP_NetAddress_Private addr); + /* Performs a non-blocking recvfrom call on socket. * Bind must be called first. |callback| is invoked when recvfrom * reads data. You must call GetRecvFromAddress to recover the diff --git a/ppapi/c/private/ppb_udp_socket_private.h b/ppapi/c/private/ppb_udp_socket_private.h index 78722e0..047be46 100644 --- a/ppapi/c/private/ppb_udp_socket_private.h +++ b/ppapi/c/private/ppb_udp_socket_private.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From private/ppb_udp_socket_private.idl modified Wed Nov 16 15:27:20 2011. */ +/* From private/ppb_udp_socket_private.idl modified Wed Feb 8 18:02:19 2012. */ #ifndef PPAPI_C_PRIVATE_PPB_UDP_SOCKET_PRIVATE_H_ #define PPAPI_C_PRIVATE_PPB_UDP_SOCKET_PRIVATE_H_ @@ -17,7 +17,8 @@ #include "ppapi/c/private/ppb_net_address_private.h" #define PPB_UDPSOCKET_PRIVATE_INTERFACE_0_2 "PPB_UDPSocket_Private;0.2" -#define PPB_UDPSOCKET_PRIVATE_INTERFACE PPB_UDPSOCKET_PRIVATE_INTERFACE_0_2 +#define PPB_UDPSOCKET_PRIVATE_INTERFACE_0_3 "PPB_UDPSocket_Private;0.3" +#define PPB_UDPSOCKET_PRIVATE_INTERFACE PPB_UDPSOCKET_PRIVATE_INTERFACE_0_3 /** * @file @@ -29,7 +30,7 @@ * @addtogroup Interfaces * @{ */ -struct PPB_UDPSocket_Private_0_2 { +struct PPB_UDPSocket_Private_0_3 { /** * Creates a UDP socket resource. */ @@ -42,6 +43,12 @@ struct PPB_UDPSocket_Private_0_2 { int32_t (*Bind)(PP_Resource udp_socket, const struct PP_NetAddress_Private* addr, struct PP_CompletionCallback callback); + /* Returns the address that the socket has bound to. A successful + * call to Bind must be called first. Returns PP_FALSE if Bind + * fails, or if Close has been called. + */ + PP_Bool (*GetBoundAddress)(PP_Resource udp_socket, + struct PP_NetAddress_Private* addr); /* Performs a non-blocking recvfrom call on socket. * Bind must be called first. |callback| is invoked when recvfrom * reads data. You must call GetRecvFromAddress to recover the @@ -69,7 +76,27 @@ struct PPB_UDPSocket_Private_0_2 { void (*Close)(PP_Resource udp_socket); }; -typedef struct PPB_UDPSocket_Private_0_2 PPB_UDPSocket_Private; +typedef struct PPB_UDPSocket_Private_0_3 PPB_UDPSocket_Private; + +struct PPB_UDPSocket_Private_0_2 { + PP_Resource (*Create)(PP_Instance instance_id); + PP_Bool (*IsUDPSocket)(PP_Resource resource_id); + int32_t (*Bind)(PP_Resource udp_socket, + const struct PP_NetAddress_Private* addr, + struct PP_CompletionCallback callback); + int32_t (*RecvFrom)(PP_Resource udp_socket, + char* buffer, + int32_t num_bytes, + struct PP_CompletionCallback callback); + PP_Bool (*GetRecvFromAddress)(PP_Resource udp_socket, + struct PP_NetAddress_Private* addr); + int32_t (*SendTo)(PP_Resource udp_socket, + const char* buffer, + int32_t num_bytes, + const struct PP_NetAddress_Private* addr, + struct PP_CompletionCallback callback); + void (*Close)(PP_Resource udp_socket); +}; /** * @} */ diff --git a/ppapi/cpp/private/udp_socket_private.cc b/ppapi/cpp/private/udp_socket_private.cc index 8bd49f2..68d372f 100644 --- a/ppapi/cpp/private/udp_socket_private.cc +++ b/ppapi/cpp/private/udp_socket_private.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -36,6 +36,15 @@ int32_t UDPSocketPrivate::Bind(const PP_NetAddress_Private* addr, pp_resource(), addr, callback.pp_completion_callback()); } +bool UDPSocketPrivate::GetBoundAddress(PP_NetAddress_Private* addr) { + if (!has_interface<PPB_UDPSocket_Private>()) + return false; + + PP_Bool result = get_interface<PPB_UDPSocket_Private>()->GetBoundAddress( + pp_resource(), addr); + return PP_ToBool(result); +} + int32_t UDPSocketPrivate::RecvFrom(char* buffer, int32_t num_bytes, const CompletionCallback& callback) { @@ -65,5 +74,10 @@ int32_t UDPSocketPrivate::SendTo(const char* buffer, callback.pp_completion_callback()); } +void UDPSocketPrivate::Close() { + if (!has_interface<PPB_UDPSocket_Private>()) + return; + return get_interface<PPB_UDPSocket_Private>()->Close(pp_resource()); +} } // namespace pp diff --git a/ppapi/cpp/private/udp_socket_private.h b/ppapi/cpp/private/udp_socket_private.h index 85bfb53..abe434b 100644 --- a/ppapi/cpp/private/udp_socket_private.h +++ b/ppapi/cpp/private/udp_socket_private.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -20,6 +20,7 @@ class UDPSocketPrivate : public Resource { int32_t Bind(const PP_NetAddress_Private* addr, const CompletionCallback& callback); + bool GetBoundAddress(PP_NetAddress_Private* addr); int32_t RecvFrom(char* buffer, int32_t num_bytes, const CompletionCallback& callback); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_udp_socket_private_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_udp_socket_private_rpc_server.cc index ccb46a2..11bd80c 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_udp_socket_private_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_udp_socket_private_rpc_server.cc @@ -87,6 +87,31 @@ void PpbUDPSocketPrivateRpcServer::PPB_UDPSocket_Private_Bind( rpc->result = NACL_SRPC_RESULT_OK; } +void PpbUDPSocketPrivateRpcServer::PPB_UDPSocket_Private_GetBoundAddress( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // input + PP_Resource udp_socket, + // output + nacl_abi_size_t* addr_bytes, char* addr, + int32_t* success) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + if (*addr_bytes != + static_cast<nacl_abi_size_t>(sizeof(PP_NetAddress_Private))) + return; + + PP_Bool pp_success = + PPBUDPSocketPrivateInterface()->GetBoundAddress( + udp_socket, + reinterpret_cast<PP_NetAddress_Private*>(addr)); + *success = PP_ToBool(pp_success); + DebugPrintf("PPB_UDPSocket_Private::GetBoundAddress: " + "success=%"NACL_PRId32"\n", *success); + rpc->result = NACL_SRPC_RESULT_OK; +} + void PpbUDPSocketPrivateRpcServer::PPB_UDPSocket_Private_RecvFrom( NaClSrpcRpc* rpc, NaClSrpcClosure* done, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc index 1643c4d4..fb3cb04 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc @@ -98,8 +98,10 @@ InterfaceMapElement interface_map[] = { true }, { PPB_TESTING_DEV_INTERFACE_0_9, PluginTesting::GetInterface(), true }, { PPB_TESTING_DEV_INTERFACE, PluginTesting::GetInterface(), true }, - { PPB_UDPSOCKET_PRIVATE_INTERFACE, PluginUDPSocketPrivate::GetInterface(), - true }, + { PPB_UDPSOCKET_PRIVATE_INTERFACE_0_2, + PluginUDPSocketPrivate::GetInterface0_2(), true }, + { PPB_UDPSOCKET_PRIVATE_INTERFACE_0_3, + PluginUDPSocketPrivate::GetInterface0_3(), true }, { PPB_URLLOADER_INTERFACE, PluginURLLoader::GetInterface(), true }, { PPB_URLREQUESTINFO_INTERFACE, PluginURLRequestInfo::GetInterface(), true }, { PPB_URLRESPONSEINFO_INTERFACE, PluginURLResponseInfo::GetInterface(), diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.cc index fa2ccc2..d690d5d 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.cc @@ -86,6 +86,30 @@ int32_t Bind(PP_Resource udp_socket, const struct PP_NetAddress_Private* addr, return MayForceCallback(callback, pp_error); } +PP_Bool GetBoundAddress(PP_Resource udp_socket, + struct PP_NetAddress_Private* addr) { + DebugPrintf("PPB_UDPSocket_Private::GetBoundAddress: " + "udp_socket="NACL_PRId32"\n", udp_socket); + + nacl_abi_size_t addr_bytes = + static_cast<nacl_abi_size_t>(sizeof(PP_NetAddress_Private)); + int32_t success; + NaClSrpcError srpc_result = + PpbUDPSocketPrivateRpcClient::PPB_UDPSocket_Private_GetBoundAddress( + GetMainSrpcChannel(), + udp_socket, + &addr_bytes, + reinterpret_cast<char*>(addr), + &success); + + DebugPrintf("PPB_UDPSocket_Private::GetBoundAddress: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result == NACL_SRPC_RESULT_OK && success) + return PP_TRUE; + return PP_FALSE; +} + int32_t RecvFrom(PP_Resource udp_socket, char* buffer, int32_t num_bytes, struct PP_CompletionCallback callback) { DebugPrintf("PPB_UDPSocket_Private::RecvFrom: udp_socket=%"NACL_PRId32", " @@ -196,15 +220,29 @@ void Close(PP_Resource udp_socket) { } // namespace -const PPB_UDPSocket_Private* PluginUDPSocketPrivate::GetInterface() { - static const PPB_UDPSocket_Private udpsocket_private_interface = { +const PPB_UDPSocket_Private_0_2* PluginUDPSocketPrivate::GetInterface0_2() { + static const PPB_UDPSocket_Private_0_2 udpsocket_private_interface = { + Create, + IsUDPSocket, + Bind, + RecvFrom, + GetRecvFromAddress, + SendTo, + Close + }; + return &udpsocket_private_interface; +} + +const PPB_UDPSocket_Private_0_3* PluginUDPSocketPrivate::GetInterface0_3() { + static const PPB_UDPSocket_Private_0_3 udpsocket_private_interface = { Create, IsUDPSocket, Bind, + GetBoundAddress, RecvFrom, GetRecvFromAddress, SendTo, - Close, + Close }; return &udpsocket_private_interface; } diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.h index efd5d16..7e87382 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -13,7 +13,8 @@ namespace ppapi_proxy { // Implements the untrusted side of the PPB_UDPSocket_Private interface. class PluginUDPSocketPrivate { public: - static const PPB_UDPSocket_Private* GetInterface(); + static const PPB_UDPSocket_Private_0_2* GetInterface0_2(); + static const PPB_UDPSocket_Private_0_3* GetInterface0_3(); private: NACL_DISALLOW_COPY_AND_ASSIGN(PluginUDPSocketPrivate); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc index 3b72662..6c5f0f1 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc @@ -2849,6 +2849,25 @@ NaClSrpcError PpbUDPSocketPrivateRpcClient::PPB_UDPSocket_Private_Bind( return retval; } +NaClSrpcError PpbUDPSocketPrivateRpcClient::PPB_UDPSocket_Private_GetBoundAddress( + NaClSrpcChannel* channel, + PP_Resource udp_socket, + nacl_abi_size_t* addr_bytes, char* addr, + int32_t* success) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_UDPSocket_Private_GetBoundAddress:i:Ci", + udp_socket, + addr_bytes, addr, + success + ); + return retval; +} + NaClSrpcError PpbUDPSocketPrivateRpcClient::PPB_UDPSocket_Private_RecvFrom( NaClSrpcChannel* channel, PP_Resource udp_socket, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc index 3e2a497..7f15d5e 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc @@ -2293,6 +2293,21 @@ static void PPB_UDPSocket_Private_BindDispatcher( ); } +static void PPB_UDPSocket_Private_GetBoundAddressDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbUDPSocketPrivateRpcServer::PPB_UDPSocket_Private_GetBoundAddress( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.count), outputs[0]->arrays.carr, + &(outputs[1]->u.ival) + ); +} + static void PPB_UDPSocket_Private_RecvFromDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, @@ -3091,6 +3106,7 @@ NaClSrpcHandlerDesc PpbRpcs::srpc_methods[] = { { "PPB_UDPSocket_Private_Create:i:i", PPB_UDPSocket_Private_CreateDispatcher }, { "PPB_UDPSocket_Private_IsUDPSocket:i:i", PPB_UDPSocket_Private_IsUDPSocketDispatcher }, { "PPB_UDPSocket_Private_Bind:iCi:i", PPB_UDPSocket_Private_BindDispatcher }, + { "PPB_UDPSocket_Private_GetBoundAddress:i:Ci", PPB_UDPSocket_Private_GetBoundAddressDispatcher }, { "PPB_UDPSocket_Private_RecvFrom:iii:Ci", PPB_UDPSocket_Private_RecvFromDispatcher }, { "PPB_UDPSocket_Private_GetRecvFromAddress:i:Ci", PPB_UDPSocket_Private_GetRecvFromAddressDispatcher }, { "PPB_UDPSocket_Private_SendTo:iCiCi:i", PPB_UDPSocket_Private_SendToDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_udp_socket_private.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_udp_socket_private.srpc index 7268093..3e5a27b 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_udp_socket_private.srpc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_udp_socket_private.srpc @@ -1,4 +1,4 @@ -# Copyright (c) 2011 The Native Client Authors. All rights reserved. +# Copyright (c) 2012 The Native Client Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # @@ -28,6 +28,13 @@ 'outputs': [['pp_error', 'int32_t'], ] }, + {'name': 'PPB_UDPSocket_Private_GetBoundAddress', + 'inputs': [['udp_socket', 'PP_Resource'], # PP_Resource + ], + 'outputs': [['addr', 'char[]'], # PP_NetAddress_Private* + ['success', 'int32_t'], # PP_Bool + ] + }, {'name': 'PPB_UDPSocket_Private_RecvFrom', 'inputs': [['udp_socket', 'PP_Resource'], # PP_Resource ['num_bytes', 'int32_t'], diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h index 3d25c00..a2508b6 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h @@ -1140,6 +1140,12 @@ class PpbUDPSocketPrivateRpcServer { nacl_abi_size_t addr_bytes, char* addr, int32_t callback_id, int32_t* pp_error); + static void PPB_UDPSocket_Private_GetBoundAddress( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Resource udp_socket, + nacl_abi_size_t* addr_bytes, char* addr, + int32_t* success); static void PPB_UDPSocket_Private_RecvFrom( NaClSrpcRpc* rpc, NaClSrpcClosure* done, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h index e61f756..194ec6f 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h @@ -991,6 +991,11 @@ class PpbUDPSocketPrivateRpcClient { nacl_abi_size_t addr_bytes, char* addr, int32_t callback_id, int32_t* pp_error); + static NaClSrpcError PPB_UDPSocket_Private_GetBoundAddress( + NaClSrpcChannel* channel, + PP_Resource udp_socket, + nacl_abi_size_t* addr_bytes, char* addr, + int32_t* success); static NaClSrpcError PPB_UDPSocket_Private_RecvFrom( NaClSrpcChannel* channel, PP_Resource udp_socket, diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index e6ecff9..dceb91d 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -315,10 +315,11 @@ IPC_MESSAGE_ROUTED4(PpapiMsg_PPBTCPSocket_WriteACK, int32_t /* bytes_written */) // PPB_UDPSocket_Private -IPC_MESSAGE_ROUTED3(PpapiMsg_PPBUDPSocket_BindACK, +IPC_MESSAGE_ROUTED4(PpapiMsg_PPBUDPSocket_BindACK, uint32 /* plugin_dispatcher_id */, uint32 /* socket_id */, - bool /* succeeded */) + bool /* succeeded */, + PP_NetAddress_Private /* bound_addr */) IPC_MESSAGE_ROUTED5(PpapiMsg_PPBUDPSocket_RecvFromACK, uint32 /* plugin_dispatcher_id */, uint32 /* socket_id */, diff --git a/ppapi/proxy/ppb_udp_socket_private_proxy.cc b/ppapi/proxy/ppb_udp_socket_private_proxy.cc index 2d9d29f..1e3a002 100644 --- a/ppapi/proxy/ppb_udp_socket_private_proxy.cc +++ b/ppapi/proxy/ppb_udp_socket_private_proxy.cc @@ -126,7 +126,8 @@ bool PPB_UDPSocket_Private_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_UDPSocket_Private_Proxy::OnMsgBindACK( uint32 /* plugin_dispatcher_id */, uint32 socket_id, - bool succeeded) { + bool succeeded, + const PP_NetAddress_Private& bound_addr) { if (!g_id_to_socket) { NOTREACHED(); return; @@ -134,7 +135,7 @@ void PPB_UDPSocket_Private_Proxy::OnMsgBindACK( IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); if (iter == g_id_to_socket->end()) return; - iter->second->OnBindCompleted(succeeded); + iter->second->OnBindCompleted(succeeded, bound_addr); } void PPB_UDPSocket_Private_Proxy::OnMsgRecvFromACK( diff --git a/ppapi/proxy/ppb_udp_socket_private_proxy.h b/ppapi/proxy/ppb_udp_socket_private_proxy.h index c6c9e68..4677b4e 100644 --- a/ppapi/proxy/ppb_udp_socket_private_proxy.h +++ b/ppapi/proxy/ppb_udp_socket_private_proxy.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -32,7 +32,8 @@ class PPB_UDPSocket_Private_Proxy : public InterfaceProxy { // Browser->plugin message handlers. void OnMsgBindACK(uint32 plugin_dispatcher_id, uint32 socket_id, - bool succeeded); + bool succeeded, + const PP_NetAddress_Private& bound_addr); void OnMsgRecvFromACK(uint32 plugin_dispatcher_id, uint32 socket_id, bool succeeded, diff --git a/ppapi/shared_impl/private/udp_socket_private_impl.cc b/ppapi/shared_impl/private/udp_socket_private_impl.cc index d596b02..3879b68 100644 --- a/ppapi/shared_impl/private/udp_socket_private_impl.cc +++ b/ppapi/shared_impl/private/udp_socket_private_impl.cc @@ -58,6 +58,14 @@ int32_t UDPSocketPrivateImpl::Bind(const PP_NetAddress_Private* addr, return PP_OK_COMPLETIONPENDING; } +PP_Bool UDPSocketPrivateImpl::GetBoundAddress(PP_NetAddress_Private* addr) { + if (!addr || !bound_ || closed_) + return PP_FALSE; + + *addr = bound_addr_; + return PP_TRUE; +} + int32_t UDPSocketPrivateImpl::RecvFrom(char* buffer, int32_t num_bytes, PP_CompletionCallback callback) { @@ -122,7 +130,9 @@ void UDPSocketPrivateImpl::Close() { PostAbortIfNecessary(&sendto_callback_); } -void UDPSocketPrivateImpl::OnBindCompleted(bool succeeded) { +void UDPSocketPrivateImpl::OnBindCompleted( + bool succeeded, + const PP_NetAddress_Private& addr) { if (!TrackedCallback::IsPending(bind_callback_)) { NOTREACHED(); return; @@ -131,8 +141,10 @@ void UDPSocketPrivateImpl::OnBindCompleted(bool succeeded) { if (succeeded) bound_ = true; + bound_addr_ = addr; + TrackedCallback::ClearAndRun(&bind_callback_, - succeeded ? PP_OK : PP_ERROR_FAILED); + succeeded ? PP_OK : PP_ERROR_FAILED); } void UDPSocketPrivateImpl::OnRecvFromCompleted( @@ -180,6 +192,9 @@ void UDPSocketPrivateImpl::Init(uint32 socket_id) { recvfrom_addr_.size = 0; memset(recvfrom_addr_.data, 0, arraysize(recvfrom_addr_.data) * sizeof(*recvfrom_addr_.data)); + bound_addr_.size = 0; + memset(bound_addr_.data, 0, + arraysize(bound_addr_.data) * sizeof(*bound_addr_.data)); } void UDPSocketPrivateImpl::PostAbortIfNecessary( diff --git a/ppapi/shared_impl/private/udp_socket_private_impl.h b/ppapi/shared_impl/private/udp_socket_private_impl.h index 01242c1..bb8a80e 100644 --- a/ppapi/shared_impl/private/udp_socket_private_impl.h +++ b/ppapi/shared_impl/private/udp_socket_private_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -42,6 +42,7 @@ class PPAPI_SHARED_EXPORT UDPSocketPrivateImpl // PPB_UDPSocket_Private_API implementation. virtual int32_t Bind(const PP_NetAddress_Private* addr, PP_CompletionCallback callback) OVERRIDE; + virtual PP_Bool GetBoundAddress(PP_NetAddress_Private* addr) OVERRIDE; virtual int32_t RecvFrom(char* buffer, int32_t num_bytes, PP_CompletionCallback callback) OVERRIDE; @@ -53,7 +54,8 @@ class PPAPI_SHARED_EXPORT UDPSocketPrivateImpl virtual void Close() OVERRIDE; // Notifications from the proxy. - void OnBindCompleted(bool succeeded); + void OnBindCompleted(bool succeeded, + const PP_NetAddress_Private& bound_addr); void OnRecvFromCompleted(bool succeeded, const std::string& data, const PP_NetAddress_Private& addr); @@ -84,6 +86,7 @@ class PPAPI_SHARED_EXPORT UDPSocketPrivateImpl int32_t bytes_to_read_; PP_NetAddress_Private recvfrom_addr_; + PP_NetAddress_Private bound_addr_; DISALLOW_COPY_AND_ASSIGN(UDPSocketPrivateImpl); }; diff --git a/ppapi/tests/test_udp_socket_private_shared.cc b/ppapi/tests/test_udp_socket_private_shared.cc index 2de64778..a0cef72 100644 --- a/ppapi/tests/test_udp_socket_private_shared.cc +++ b/ppapi/tests/test_udp_socket_private_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -44,6 +44,7 @@ bool TestUDPSocketPrivateShared::Init() { void TestUDPSocketPrivateShared::RunTests(const std::string& filter) { RUN_TEST(Create, filter); RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter); + RUN_TEST_FORCEASYNC_AND_NOT(ConnectFailure, filter); } void TestUDPSocketPrivateShared::QuitMessageLoop() { @@ -75,7 +76,7 @@ std::string TestUDPSocketPrivateShared::GenerateNetAddress( } std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket( - const PP_NetAddress_Private *address, + PP_NetAddress_Private *address, PP_Resource *socket) { *socket = udp_socket_private_interface_->Create(instance_->pp_instance()); if (0 == *socket) @@ -95,6 +96,36 @@ std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket( if (rv != PP_OK) return ReportError("PPB_UDPSocket_Private::Bind", rv); + if (!udp_socket_private_interface_->GetBoundAddress(*socket, address)) + return "PPB_UDPSocket_Private::GetBoundAddress: Failed"; + + PASS(); +} + +std::string TestUDPSocketPrivateShared::BindUDPSocketFailure( + PP_NetAddress_Private *address, + PP_Resource *socket) { + *socket = udp_socket_private_interface_->Create(instance_->pp_instance()); + if (0 == *socket) + return "PPB_UDPSocket_Private::Create failed"; + if (!udp_socket_private_interface_->IsUDPSocket(*socket)) + return "PPB_UDPSocket_Private::IsUDPSocket failed"; + + TestCompletionCallback callback(instance_->pp_instance(), force_async_); + int32_t rv = udp_socket_private_interface_->Bind( + *socket, address, + static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); + + if (force_async_ && rv != PP_OK_COMPLETIONPENDING) + return ReportError("PPB_UDPSocket_Private::Bind force_async", rv); + if (rv == PP_OK_COMPLETIONPENDING) + rv = callback.WaitForResult(); + if (rv == PP_OK) + return ReportError("PPB_UDPSocket_Private::Bind", rv); + + if (udp_socket_private_interface_->GetBoundAddress(*socket, address)) + return "PPB_UDPSocket_Private::GetBoundAddress: Failed"; + PASS(); } @@ -125,15 +156,15 @@ std::string TestUDPSocketPrivateShared::TestConnect() { if (!error_message.empty()) return error_message; error_message = GenerateNetAddress(&tcp_socket_client, &client_address); - if (error_message.empty()) + if (!error_message.empty()) return error_message; PP_Resource socket_server, socket_client; error_message = CreateAndBindUDPSocket(&server_address, &socket_server); - if (error_message.empty()) + if (!error_message.empty()) return error_message; error_message = CreateAndBindUDPSocket(&client_address, &socket_client); - if (error_message.empty()) + if (!error_message.empty()) return error_message; static const char* const kMessage = @@ -178,5 +209,21 @@ std::string TestUDPSocketPrivateShared::TestConnect() { tcp_socket_private_interface_->Disconnect(tcp_socket_server); tcp_socket_private_interface_->Disconnect(tcp_socket_client); + if (udp_socket_private_interface_->GetBoundAddress( + socket_server, &server_address)) + return "PPB_UDPSocket_Private::GetBoundAddress: expected Failure"; + + PASS(); +} + +std::string TestUDPSocketPrivateShared::TestConnectFailure() { + std::string error_message; + PP_NetAddress_Private invalid_address = { 0 }; + PP_Resource socket; + + error_message = BindUDPSocketFailure(&invalid_address, &socket); + if (!error_message.empty()) + return error_message; + PASS(); } diff --git a/ppapi/tests/test_udp_socket_private_shared.h b/ppapi/tests/test_udp_socket_private_shared.h index 25b4afa..2f74965 100644 --- a/ppapi/tests/test_udp_socket_private_shared.h +++ b/ppapi/tests/test_udp_socket_private_shared.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -26,11 +26,14 @@ class TestUDPSocketPrivateShared : public TestCase { // structure filled with local IP and some free port. std::string GenerateNetAddress(PP_Resource* socket, PP_NetAddress_Private* address); - std::string CreateAndBindUDPSocket(const PP_NetAddress_Private *address, + std::string CreateAndBindUDPSocket(PP_NetAddress_Private *address, PP_Resource *socket); + std::string BindUDPSocketFailure(PP_NetAddress_Private *address, + PP_Resource *socket); std::string TestCreate(); std::string TestConnect(); + std::string TestConnectFailure(); const PPB_TCPSocket_Private* tcp_socket_private_interface_; const PPB_UDPSocket_Private* udp_socket_private_interface_; diff --git a/ppapi/thunk/interfaces_ppb_private.h b/ppapi/thunk/interfaces_ppb_private.h index 12cc2fd..1b43ebe 100644 --- a/ppapi/thunk/interfaces_ppb_private.h +++ b/ppapi/thunk/interfaces_ppb_private.h @@ -32,6 +32,8 @@ PROXIED_IFACE(PPB_TCPSocket_Private, PPB_TCPSOCKET_PRIVATE_INTERFACE_0_3, PPB_TCPSocket_Private_0_3) PROXIED_IFACE(PPB_UDPSocket_Private, PPB_UDPSOCKET_PRIVATE_INTERFACE_0_2, PPB_UDPSocket_Private_0_2) +PROXIED_IFACE(PPB_UDPSocket_Private, PPB_UDPSOCKET_PRIVATE_INTERFACE_0_3, + PPB_UDPSocket_Private_0_3) // Hack to keep font working. The Font 0.6 API is binary compatible with // BrowserFont 1.0, so just map the string to the same thing. diff --git a/ppapi/thunk/ppb_udp_socket_private_api.h b/ppapi/thunk/ppb_udp_socket_private_api.h index b8a3436..ee5ac8e 100644 --- a/ppapi/thunk/ppb_udp_socket_private_api.h +++ b/ppapi/thunk/ppb_udp_socket_private_api.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -17,6 +17,7 @@ class PPAPI_THUNK_EXPORT PPB_UDPSocket_Private_API { virtual int32_t Bind(const PP_NetAddress_Private* addr, PP_CompletionCallback callback) = 0; + virtual PP_Bool GetBoundAddress(PP_NetAddress_Private* addr) = 0; virtual int32_t RecvFrom(char* buffer, int32_t num_bytes, PP_CompletionCallback callback) = 0; diff --git a/ppapi/thunk/ppb_udp_socket_private_thunk.cc b/ppapi/thunk/ppb_udp_socket_private_thunk.cc index 9ee8b9d..4f12a3f 100644 --- a/ppapi/thunk/ppb_udp_socket_private_thunk.cc +++ b/ppapi/thunk/ppb_udp_socket_private_thunk.cc @@ -38,6 +38,14 @@ int32_t Bind(PP_Resource udp_socket, return enter.SetResult(enter.object()->Bind(addr, callback)); } +PP_Bool GetBoundAddress(PP_Resource udp_socket, + PP_NetAddress_Private* addr) { + EnterUDP enter(udp_socket, true); + if (enter.failed()) + return PP_FALSE; + return enter.object()->GetBoundAddress(addr); +} + int32_t RecvFrom(PP_Resource udp_socket, char* buffer, int32_t num_bytes, @@ -74,10 +82,21 @@ void Close(PP_Resource udp_socket) { enter.object()->Close(); } -const PPB_UDPSocket_Private g_ppb_udp_socket_thunk = { +const PPB_UDPSocket_Private_0_2 g_ppb_udp_socket_thunk_0_2 = { + &Create, + &IsUDPSocket, + &Bind, + &RecvFrom, + &GetRecvFromAddress, + &SendTo, + &Close +}; + +const PPB_UDPSocket_Private_0_3 g_ppb_udp_socket_thunk_0_3 = { &Create, &IsUDPSocket, &Bind, + &GetBoundAddress, &RecvFrom, &GetRecvFromAddress, &SendTo, @@ -87,7 +106,11 @@ const PPB_UDPSocket_Private g_ppb_udp_socket_thunk = { } // namespace const PPB_UDPSocket_Private_0_2* GetPPB_UDPSocket_Private_0_2_Thunk() { - return &g_ppb_udp_socket_thunk; + return &g_ppb_udp_socket_thunk_0_2; +} + +const PPB_UDPSocket_Private_0_3* GetPPB_UDPSocket_Private_0_3_Thunk() { + return &g_ppb_udp_socket_thunk_0_3; } } // namespace thunk |