From fd305c12b3fe8b4d2496f67aed089ff703f19b6d Mon Sep 17 00:00:00 2001 From: hidehiko Date: Wed, 10 Dec 2014 22:01:47 -0800 Subject: [PATCH] Remove timing limitation of SetOption invocation for PPAPI sockets. Currently PPAPI has timing limitation for sockets' SetOption. NODELAY, and BROADCAST need to be before Connect() or Bind(), while RCVBUF_SIZE and SNFBUF_SIZE need to be after it. This CL removes such a limitation. Along with the change, pepper_udp_socket_message_filter starts to use UDPSocket instead of UDPServerSocket, so that the implementation direction gets closer to TCP message filter a little bit. BUG=425563, 420697 TEST=Ran trybots. Review URL: https://codereview.chromium.org/690903002 Cr-Commit-Position: refs/heads/master@{#307867} --- .../pepper/pepper_tcp_socket_message_filter.cc | 112 ++++++++++---- .../pepper/pepper_tcp_socket_message_filter.h | 14 ++ .../pepper/pepper_udp_socket_message_filter.cc | 162 +++++++++++++++------ .../pepper/pepper_udp_socket_message_filter.h | 20 ++- ppapi/api/ppb_tcp_socket.idl | 35 ++++- ppapi/api/ppb_udp_socket.idl | 36 ++++- ppapi/c/ppb_tcp_socket.h | 53 ++++++- ppapi/c/ppb_udp_socket.h | 44 +++++- ppapi/cpp/tcp_socket.cc | 56 ++++++- ppapi/cpp/udp_socket.cc | 37 ++++- .../src/untrusted/pnacl_irt_shim/pnacl_shim.c | 150 +++++++++++++++++++ ppapi/proxy/tcp_socket_private_resource.cc | 4 +- ppapi/proxy/tcp_socket_resource.cc | 13 +- ppapi/proxy/tcp_socket_resource.h | 4 + ppapi/proxy/tcp_socket_resource_base.cc | 5 +- ppapi/proxy/tcp_socket_resource_base.h | 1 + ppapi/proxy/udp_socket_private_resource.cc | 4 +- ppapi/proxy/udp_socket_resource.cc | 13 +- ppapi/proxy/udp_socket_resource.h | 4 + ppapi/proxy/udp_socket_resource_base.cc | 13 +- ppapi/proxy/udp_socket_resource_base.h | 6 + ppapi/tests/test_tcp_socket.cc | 9 +- ppapi/tests/test_udp_socket.cc | 13 +- ppapi/thunk/interfaces_ppb_public_stable.h | 2 + ppapi/thunk/ppb_tcp_socket_api.h | 3 + ppapi/thunk/ppb_tcp_socket_thunk.cc | 34 ++++- ppapi/thunk/ppb_udp_socket_api.h | 3 + ppapi/thunk/ppb_udp_socket_thunk.cc | 45 +++++- tools/metrics/histograms/histograms.xml | 2 + 29 files changed, 757 insertions(+), 140 deletions(-) diff --git a/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.cc b/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.cc index 0e947f4318fc..b1437a4a51ac 100644 --- a/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.cc +++ b/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.cc @@ -64,6 +64,9 @@ PepperTCPSocketMessageFilter::PepperTCPSocketMessageFilter( state_(TCPSocketState::INITIAL), end_of_file_reached_(false), bind_input_addr_(NetAddressPrivateImpl::kInvalidNetAddress), + socket_options_(SOCKET_OPTION_NODELAY), + rcvbuf_size_(0), + sndbuf_size_(0), address_index_(0), socket_(new net::TCPSocket(NULL, net::NetLog::Source())), ssl_context_helper_(host->ssl_context_helper()), @@ -91,6 +94,9 @@ PepperTCPSocketMessageFilter::PepperTCPSocketMessageFilter( state_(TCPSocketState::CONNECTED), end_of_file_reached_(false), bind_input_addr_(NetAddressPrivateImpl::kInvalidNetAddress), + socket_options_(SOCKET_OPTION_NODELAY), + rcvbuf_size_(0), + sndbuf_size_(0), address_index_(0), socket_(socket.Pass()), ssl_context_helper_(host->ssl_context_helper()), @@ -457,35 +463,57 @@ int32_t PepperTCPSocketMessageFilter::OnMsgSetOption( switch (name) { case PP_TCPSOCKET_OPTION_NO_DELAY: { - if (state_.state() != TCPSocketState::CONNECTED) - return PP_ERROR_FAILED; - bool boolean_value = false; if (!value.GetBool(&boolean_value)) return PP_ERROR_BADARGUMENT; - return socket_->SetNoDelay(boolean_value) ? PP_OK : PP_ERROR_FAILED; + + // If the socket is already connected, proxy the value to TCPSocket. + if (state_.state() == TCPSocketState::CONNECTED) + return socket_->SetNoDelay(boolean_value) ? PP_OK : PP_ERROR_FAILED; + + // TCPSocket instance is not yet created. So remember the value here. + if (boolean_value) { + socket_options_ |= SOCKET_OPTION_NODELAY; + } else { + socket_options_ &= ~SOCKET_OPTION_NODELAY; + } + return PP_OK; } - case PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE: - case PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE: { - if (state_.state() != TCPSocketState::CONNECTED) - return PP_ERROR_FAILED; + case PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE: { + int32_t integer_value = 0; + if (!value.GetInt32(&integer_value) || + integer_value <= 0 || + integer_value > TCPSocketResourceBase::kMaxSendBufferSize) + return PP_ERROR_BADARGUMENT; + // If the socket is already connected, proxy the value to TCPSocket. + if (state_.state() == TCPSocketState::CONNECTED) { + return NetErrorToPepperError( + socket_->SetSendBufferSize(integer_value)); + } + + // TCPSocket instance is not yet created. So remember the value here. + socket_options_ |= SOCKET_OPTION_SNDBUF_SIZE; + sndbuf_size_ = integer_value; + return PP_OK; + } + case PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE: { int32_t integer_value = 0; - if (!value.GetInt32(&integer_value) || integer_value <= 0) + if (!value.GetInt32(&integer_value) || + integer_value <= 0 || + integer_value > TCPSocketResourceBase::kMaxReceiveBufferSize) return PP_ERROR_BADARGUMENT; - int net_result = net::ERR_UNEXPECTED; - if (name == PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE) { - if (integer_value > TCPSocketResourceBase::kMaxSendBufferSize) - return PP_ERROR_BADARGUMENT; - net_result = socket_->SetSendBufferSize(integer_value); - } else { - if (integer_value > TCPSocketResourceBase::kMaxReceiveBufferSize) - return PP_ERROR_BADARGUMENT; - net_result = socket_->SetReceiveBufferSize(integer_value); + // If the socket is already connected, proxy the value to TCPSocket. + if (state_.state() == TCPSocketState::CONNECTED) { + return NetErrorToPepperError( + socket_->SetReceiveBufferSize(integer_value)); } - // TODO(wtc): Add error mapping code. - return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED; + + // TCPSocket instance is not yet created. So remember the value here. + socket_options_ |= SOCKET_OPTION_RCVBUF_SIZE; + rcvbuf_size_ = integer_value; + return PP_OK; } default: { NOTREACHED(); @@ -696,17 +724,42 @@ void PepperTCPSocketMessageFilter::StartConnect( DCHECK(state_.IsPending(TCPSocketState::CONNECT)); DCHECK_LT(address_index_, address_list_.size()); - int net_result = net::OK; - if (!socket_->IsValid()) - net_result = socket_->Open(address_list_[address_index_].GetFamily()); + if (!socket_->IsValid()) { + int net_result = socket_->Open(address_list_[address_index_].GetFamily()); + if (net_result != net::OK) { + OnConnectCompleted(context, net_result); + return; + } + } + + socket_->SetDefaultOptionsForClient(); - if (net_result == net::OK) { - net_result = socket_->Connect( - address_list_[address_index_], - base::Bind(&PepperTCPSocketMessageFilter::OnConnectCompleted, - base::Unretained(this), - context)); + if (!(socket_options_ & SOCKET_OPTION_NODELAY)) { + if (!socket_->SetNoDelay(false)) { + OnConnectCompleted(context, net::ERR_FAILED); + return; + } } + if (socket_options_ & SOCKET_OPTION_RCVBUF_SIZE) { + int net_result = socket_->SetReceiveBufferSize(rcvbuf_size_); + if (net_result != net::OK) { + OnConnectCompleted(context, net_result); + return; + } + } + if (socket_options_ & SOCKET_OPTION_SNDBUF_SIZE) { + int net_result = socket_->SetSendBufferSize(sndbuf_size_); + if (net_result != net::OK) { + OnConnectCompleted(context, net_result); + return; + } + } + + int net_result = socket_->Connect( + address_list_[address_index_], + base::Bind(&PepperTCPSocketMessageFilter::OnConnectCompleted, + base::Unretained(this), + context)); if (net_result != net::ERR_IO_PENDING) OnConnectCompleted(context, net_result); } @@ -754,7 +807,6 @@ void PepperTCPSocketMessageFilter::OnConnectCompleted( break; } - socket_->SetDefaultOptionsForClient(); SendConnectReply(context, PP_OK, local_addr, remote_addr); state_.CompletePendingTransition(true); return; diff --git a/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.h b/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.h index 7c9250f48995..d0e672aa7a24 100644 --- a/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.h +++ b/content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.h @@ -63,6 +63,12 @@ class CONTENT_EXPORT PepperTCPSocketMessageFilter static size_t GetNumInstances(); private: + enum SocketOption { + SOCKET_OPTION_NODELAY = 1 << 0, + SOCKET_OPTION_RCVBUF_SIZE = 1 << 1, + SOCKET_OPTION_SNDBUF_SIZE = 1 << 2 + }; + ~PepperTCPSocketMessageFilter() override; // ppapi::host::ResourceMessageFilter overrides. @@ -185,6 +191,14 @@ class CONTENT_EXPORT PepperTCPSocketMessageFilter scoped_ptr resolver_; + // Bitwise-or of SocketOption flags. This stores the state about whether + // each option is set before Connect() is called. + int socket_options_; + + // Locally cached value of buffer size. + int32_t rcvbuf_size_; + int32_t sndbuf_size_; + // |address_list_| may store multiple addresses when // PPB_TCPSocket_Private.Connect() is used, which involves name resolution. // In that case, we will try each address in the list until a connection is diff --git a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc index dd915b85ea37..8213bb4f8e94 100644 --- a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc +++ b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc @@ -16,7 +16,8 @@ #include "ipc/ipc_message_macros.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/udp/udp_server_socket.h" +#include "net/base/rand_callback.h" +#include "net/udp/udp_socket.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_net_address_private.h" #include "ppapi/host/dispatch_host_message.h" @@ -44,8 +45,9 @@ PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter( BrowserPpapiHostImpl* host, PP_Instance instance, bool private_api) - : allow_address_reuse_(false), - allow_broadcast_(false), + : socket_options_(0), + rcvbuf_size_(0), + sndbuf_size_(0), closed_(false), remaining_recv_slots_( ppapi::proxy::UDPSocketResourceBase::kPluginReceiveBufferSlots), @@ -114,10 +116,11 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( return PP_ERROR_FAILED; switch (name) { - case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: - case PP_UDPSOCKET_OPTION_BROADCAST: { + case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: { if (socket_.get()) { - // They only take effect before the socket is bound. + // AllowReuseAddress is only effective before Bind(). + // Note that this limitation originally comes from Windows, but + // PPAPI tries to provide platform independent APIs. return PP_ERROR_FAILED; } @@ -125,38 +128,67 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( if (!value.GetBool(&boolean_value)) return PP_ERROR_BADARGUMENT; - if (name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) - allow_address_reuse_ = boolean_value; - else - allow_broadcast_ = boolean_value; + if (boolean_value) { + socket_options_ |= SOCKET_OPTION_ADDRESS_REUSE; + } else { + socket_options_ &= ~SOCKET_OPTION_ADDRESS_REUSE; + } return PP_OK; } - case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: - case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { - if (!socket_.get()) { - // They only take effect after the socket is bound. - return PP_ERROR_FAILED; + case PP_UDPSOCKET_OPTION_BROADCAST: { + bool boolean_value = false; + if (!value.GetBool(&boolean_value)) + return PP_ERROR_BADARGUMENT; + + // If the socket is already connected, proxy the value to TCPSocket. + if (socket_.get()) + return NetErrorToPepperError(socket_->SetBroadcast(boolean_value)); + + // UDPSocket instance is not yet created, so remember the value here. + if (boolean_value) { + socket_options_ |= SOCKET_OPTION_BROADCAST; + } else { + socket_options_ &= ~SOCKET_OPTION_BROADCAST; } + return PP_OK; + } + case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: { int32_t integer_value = 0; - if (!value.GetInt32(&integer_value) || integer_value <= 0) + if (!value.GetInt32(&integer_value) || + integer_value <= 0 || + integer_value > + ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) return PP_ERROR_BADARGUMENT; - int net_result = net::ERR_UNEXPECTED; - if (name == PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE) { - if (integer_value > - ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) { - return PP_ERROR_BADARGUMENT; - } - net_result = socket_->SetSendBufferSize(integer_value); - } else { - if (integer_value > - ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) { - return PP_ERROR_BADARGUMENT; - } - net_result = socket_->SetReceiveBufferSize(integer_value); + // If the socket is already connected, proxy the value to UDPSocket. + if (socket_.get()) { + return NetErrorToPepperError( + socket_->SetSendBufferSize(integer_value)); } - // TODO(wtc): Add error mapping code. - return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED; + + // UDPSocket instance is not yet created, so remember the value here. + socket_options_ |= SOCKET_OPTION_SNDBUF_SIZE; + sndbuf_size_ = integer_value; + return PP_OK; + } + case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { + int32_t integer_value = 0; + if (!value.GetInt32(&integer_value) || + integer_value <= 0 || + integer_value > + ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) + return PP_ERROR_BADARGUMENT; + + // If the socket is already connected, proxy the value to UDPSocket. + if (socket_.get()) { + return NetErrorToPepperError( + socket_->SetReceiveBufferSize(integer_value)); + } + + // UDPSocket instance is not yet created, so remember the value here. + socket_options_ |= SOCKET_OPTION_RCVBUF_SIZE; + rcvbuf_size_ = integer_value; + return PP_OK; } default: { NOTREACHED(); @@ -253,8 +285,9 @@ void PepperUDPSocketMessageFilter::DoBind( return; } - scoped_ptr socket( - new net::UDPServerSocket(NULL, net::NetLog::Source())); + scoped_ptr socket(new net::UDPSocket( + net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), + NULL, net::NetLog::Source())); net::IPAddressNumber address; uint16 port; @@ -262,24 +295,59 @@ void PepperUDPSocketMessageFilter::DoBind( SendBindError(context, PP_ERROR_ADDRESS_INVALID); return; } + net::IPEndPoint end_point(address, port); + { + int net_result = socket->Open(end_point.GetFamily()); + if (net_result != net::OK) { + SendBindError(context, NetErrorToPepperError(net_result)); + return; + } + } - if (allow_address_reuse_) - socket->AllowAddressReuse(); - if (allow_broadcast_) - socket->AllowBroadcast(); + if (socket_options_ & SOCKET_OPTION_ADDRESS_REUSE) { + int net_result = socket->AllowAddressReuse(); + if (net_result != net::OK) { + SendBindError(context, NetErrorToPepperError(net_result)); + return; + } + } + if (socket_options_ & SOCKET_OPTION_BROADCAST) { + int net_result = socket->SetBroadcast(true); + if (net_result != net::OK) { + SendBindError(context, NetErrorToPepperError(net_result)); + return; + } + } + if (socket_options_ & SOCKET_OPTION_SNDBUF_SIZE) { + int net_result = socket->SetSendBufferSize(sndbuf_size_); + if (net_result != net::OK) { + SendBindError(context, NetErrorToPepperError(net_result)); + return; + } + } + if (socket_options_ & SOCKET_OPTION_RCVBUF_SIZE) { + int net_result = socket->SetReceiveBufferSize(rcvbuf_size_); + if (net_result != net::OK) { + SendBindError(context, NetErrorToPepperError(net_result)); + return; + } + } - int32_t pp_result = - NetErrorToPepperError(socket->Listen(net::IPEndPoint(address, port))); - if (pp_result != PP_OK) { - SendBindError(context, pp_result); - return; + { + int net_result = socket->Bind(end_point); + if (net_result != net::OK) { + SendBindError(context, NetErrorToPepperError(net_result)); + return; + } } net::IPEndPoint bound_address; - pp_result = NetErrorToPepperError(socket->GetLocalAddress(&bound_address)); - if (pp_result != PP_OK) { - SendBindError(context, pp_result); - return; + { + int net_result = socket->GetLocalAddress(&bound_address); + if (net_result != net::OK) { + SendBindError(context, NetErrorToPepperError(net_result)); + return; + } } PP_NetAddress_Private net_address = NetAddressPrivateImpl::kInvalidNetAddress; @@ -289,8 +357,6 @@ void PepperUDPSocketMessageFilter::DoBind( return; } - allow_address_reuse_ = false; - allow_broadcast_ = false; socket_.swap(socket); SendBindReply(context, PP_OK, net_address); diff --git a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h index 1aa2c36cad49..aea6fa4f7462 100644 --- a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h +++ b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h @@ -16,6 +16,7 @@ #include "content/public/common/process_type.h" #include "net/base/completion_callback.h" #include "net/base/ip_endpoint.h" +#include "net/udp/udp_socket.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_stdint.h" #include "ppapi/c/ppb_udp_socket.h" @@ -26,7 +27,6 @@ struct PP_NetAddress_Private; namespace net { class IOBuffer; class IOBufferWithSize; -class UDPServerSocket; } namespace ppapi { @@ -56,6 +56,13 @@ class CONTENT_EXPORT PepperUDPSocketMessageFilter ~PepperUDPSocketMessageFilter() override; private: + enum SocketOption { + SOCKET_OPTION_ADDRESS_REUSE = 1 << 0, + SOCKET_OPTION_BROADCAST = 1 << 1, + SOCKET_OPTION_RCVBUF_SIZE = 1 << 2, + SOCKET_OPTION_SNDBUF_SIZE = 1 << 3 + }; + // ppapi::host::ResourceMessageFilter overrides. scoped_refptr OverrideTaskRunnerForMessage( const IPC::Message& message) override; @@ -103,10 +110,15 @@ class CONTENT_EXPORT PepperUDPSocketMessageFilter void SendSendToError(const ppapi::host::ReplyMessageContext& context, int32_t result); - bool allow_address_reuse_; - bool allow_broadcast_; + // Bitwise-or of SocketOption flags. This stores the state about whether + // each option is set before Bind() is called. + int socket_options_; + + // Locally cached value of buffer size. + int32_t rcvbuf_size_; + int32_t sndbuf_size_; - scoped_ptr socket_; + scoped_ptr socket_; bool closed_; scoped_refptr recvfrom_buffer_; diff --git a/ppapi/api/ppb_tcp_socket.idl b/ppapi/api/ppb_tcp_socket.idl index 543cd3051916..5851f1d3e34d 100644 --- a/ppapi/api/ppb_tcp_socket.idl +++ b/ppapi/api/ppb_tcp_socket.idl @@ -9,7 +9,8 @@ label Chrome { M29 = 1.0, - M31 = 1.1 + M31 = 1.1, + M41 = 1.2 }; /** @@ -20,14 +21,18 @@ enum PP_TCPSocket_Option { /** * Disables coalescing of small writes to make TCP segments, and instead * delivers data immediately. Value's type is PP_VARTYPE_BOOL. - * This option can only be set after a successful Connect() call. + * On version 1.1 or earlier, this option can only be set after a successful + * Connect() call. On version 1.2 or later, there is no such + * limitation. */ PP_TCPSOCKET_OPTION_NO_DELAY = 0, /** * Specifies the total per-socket buffer space reserved for sends. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Connect() call. + * On version 1.1 or earlier, this option can only be set after a successful + * Connect() call. On version 1.2 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -38,7 +43,9 @@ enum PP_TCPSocket_Option { /** * Specifies the total per-socket buffer space reserved for receives. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Connect() call. + * On version 1.1 or earlier, this option can only be set after a successful + * Connect() call. On version 1.2 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -261,4 +268,24 @@ interface PPB_TCPSocket { [in] PP_TCPSocket_Option name, [in] PP_Var value, [in] PP_CompletionCallback callback); + + /** + * Sets a socket option on the TCP socket. + * Please see the PP_TCPSocket_Option description for option + * names, value types and allowed values. + * + * @param[in] tcp_socket A PP_Resource corresponding to a TCP + * socket. + * @param[in] name The option to set. + * @param[in] value The option value to set. + * @param[in] callback A PP_CompletionCallback to be called upon + * completion. + * + * @return An int32_t containing an error code from pp_errors.h. + */ + [version=1.2] + int32_t SetOption([in] PP_Resource tcp_socket, + [in] PP_TCPSocket_Option name, + [in] PP_Var value, + [in] PP_CompletionCallback callback); }; diff --git a/ppapi/api/ppb_udp_socket.idl b/ppapi/api/ppb_udp_socket.idl index e4c87b2a1cd5..8226c00dd5c5 100644 --- a/ppapi/api/ppb_udp_socket.idl +++ b/ppapi/api/ppb_udp_socket.idl @@ -7,10 +7,9 @@ * This file defines the PPB_UDPSocket interface. */ -[generate_thunk] - label Chrome { - M29 = 1.0 + M29 = 1.0, + M41 = 1.1 }; /** @@ -28,14 +27,17 @@ enum PP_UDPSocket_Option { /** * Allows sending and receiving packets to and from broadcast addresses. * Value's type should be PP_VARTYPE_BOOL. - * This option can only be set before calling Bind(). + * On version 1.0, this option can only be set before calling + * Bind(). On version 1.1 or later, there is no such limitation. */ PP_UDPSOCKET_OPTION_BROADCAST = 1, /** * Specifies the total per-socket buffer space reserved for sends. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Bind() call. + * On version 1.0, this option can only be set after a successful + * Bind() call. On version 1.1 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -46,7 +48,9 @@ enum PP_UDPSocket_Option { /** * Specifies the total per-socket buffer space reserved for receives. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Bind() call. + * On version 1.0, this option can only be set after a successful + * Bind() call. On version 1.1 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -193,4 +197,24 @@ interface PPB_UDPSocket { [in] PP_UDPSocket_Option name, [in] PP_Var value, [in] PP_CompletionCallback callback); + + /** + * Sets a socket option on the UDP socket. + * Please see the PP_UDPSocket_Option description for option + * names, value types and allowed values. + * + * @param[in] udp_socket A PP_Resource corresponding to a UDP + * socket. + * @param[in] name The option to set. + * @param[in] value The option value to set. + * @param[in] callback A PP_CompletionCallback to be called upon + * completion. + * + * @return An int32_t containing an error code from pp_errors.h. + */ + [version=1.1] + int32_t SetOption([in] PP_Resource udp_socket, + [in] PP_UDPSocket_Option name, + [in] PP_Var value, + [in] PP_CompletionCallback callback); }; diff --git a/ppapi/c/ppb_tcp_socket.h b/ppapi/c/ppb_tcp_socket.h index a6fe111f71ef..64faa362be1c 100644 --- a/ppapi/c/ppb_tcp_socket.h +++ b/ppapi/c/ppb_tcp_socket.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From ppb_tcp_socket.idl modified Fri Sep 20 09:58:19 2013. */ +/* From ppb_tcp_socket.idl modified Mon Dec 8 16:50:44 2014. */ #ifndef PPAPI_C_PPB_TCP_SOCKET_H_ #define PPAPI_C_PPB_TCP_SOCKET_H_ @@ -18,7 +18,8 @@ #define PPB_TCPSOCKET_INTERFACE_1_0 "PPB_TCPSocket;1.0" #define PPB_TCPSOCKET_INTERFACE_1_1 "PPB_TCPSocket;1.1" -#define PPB_TCPSOCKET_INTERFACE PPB_TCPSOCKET_INTERFACE_1_1 +#define PPB_TCPSOCKET_INTERFACE_1_2 "PPB_TCPSocket;1.2" +#define PPB_TCPSOCKET_INTERFACE PPB_TCPSOCKET_INTERFACE_1_2 /** * @file @@ -37,13 +38,17 @@ typedef enum { /** * Disables coalescing of small writes to make TCP segments, and instead * delivers data immediately. Value's type is PP_VARTYPE_BOOL. - * This option can only be set after a successful Connect() call. + * On version 1.1 or earlier, this option can only be set after a successful + * Connect() call. On version 1.2 or later, there is no such + * limitation. */ PP_TCPSOCKET_OPTION_NO_DELAY = 0, /** * Specifies the total per-socket buffer space reserved for sends. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Connect() call. + * On version 1.1 or earlier, this option can only be set after a successful + * Connect() call. On version 1.2 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -53,7 +58,9 @@ typedef enum { /** * Specifies the total per-socket buffer space reserved for receives. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Connect() call. + * On version 1.1 or earlier, this option can only be set after a successful + * Connect() call. On version 1.2 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -79,7 +86,7 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option, 4); * For more details about network communication permissions, please see: * http://developer.chrome.com/apps/app_network.html */ -struct PPB_TCPSocket_1_1 { +struct PPB_TCPSocket_1_2 { /** * Creates a TCP socket resource. * @@ -273,7 +280,7 @@ struct PPB_TCPSocket_1_1 { struct PP_CompletionCallback callback); }; -typedef struct PPB_TCPSocket_1_1 PPB_TCPSocket; +typedef struct PPB_TCPSocket_1_2 PPB_TCPSocket; struct PPB_TCPSocket_1_0 { PP_Resource (*Create)(PP_Instance instance); @@ -297,6 +304,38 @@ struct PPB_TCPSocket_1_0 { struct PP_Var value, struct PP_CompletionCallback callback); }; + +struct PPB_TCPSocket_1_1 { + PP_Resource (*Create)(PP_Instance instance); + PP_Bool (*IsTCPSocket)(PP_Resource resource); + int32_t (*Bind)(PP_Resource tcp_socket, + PP_Resource addr, + struct PP_CompletionCallback callback); + int32_t (*Connect)(PP_Resource tcp_socket, + PP_Resource addr, + struct PP_CompletionCallback callback); + PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); + PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket); + int32_t (*Read)(PP_Resource tcp_socket, + char* buffer, + int32_t bytes_to_read, + struct PP_CompletionCallback callback); + int32_t (*Write)(PP_Resource tcp_socket, + const char* buffer, + int32_t bytes_to_write, + struct PP_CompletionCallback callback); + int32_t (*Listen)(PP_Resource tcp_socket, + int32_t backlog, + struct PP_CompletionCallback callback); + int32_t (*Accept)(PP_Resource tcp_socket, + PP_Resource* accepted_tcp_socket, + struct PP_CompletionCallback callback); + void (*Close)(PP_Resource tcp_socket); + int32_t (*SetOption)(PP_Resource tcp_socket, + PP_TCPSocket_Option name, + struct PP_Var value, + struct PP_CompletionCallback callback); +}; /** * @} */ diff --git a/ppapi/c/ppb_udp_socket.h b/ppapi/c/ppb_udp_socket.h index 5551c3388f47..aa3fa744143f 100644 --- a/ppapi/c/ppb_udp_socket.h +++ b/ppapi/c/ppb_udp_socket.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From ppb_udp_socket.idl modified Sat Jun 22 10:56:26 2013. */ +/* From ppb_udp_socket.idl modified Wed Dec 10 04:11:03 2014. */ #ifndef PPAPI_C_PPB_UDP_SOCKET_H_ #define PPAPI_C_PPB_UDP_SOCKET_H_ @@ -17,7 +17,8 @@ #include "ppapi/c/pp_var.h" #define PPB_UDPSOCKET_INTERFACE_1_0 "PPB_UDPSocket;1.0" -#define PPB_UDPSOCKET_INTERFACE PPB_UDPSOCKET_INTERFACE_1_0 +#define PPB_UDPSOCKET_INTERFACE_1_1 "PPB_UDPSocket;1.1" +#define PPB_UDPSOCKET_INTERFACE PPB_UDPSOCKET_INTERFACE_1_1 /** * @file @@ -42,13 +43,16 @@ typedef enum { /** * Allows sending and receiving packets to and from broadcast addresses. * Value's type should be PP_VARTYPE_BOOL. - * This option can only be set before calling Bind(). + * On version 1.0, this option can only be set before calling + * Bind(). On version 1.1 or later, there is no such limitation. */ PP_UDPSOCKET_OPTION_BROADCAST = 1, /** * Specifies the total per-socket buffer space reserved for sends. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Bind() call. + * On version 1.0, this option can only be set after a successful + * Bind() call. On version 1.1 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -58,7 +62,9 @@ typedef enum { /** * Specifies the total per-socket buffer space reserved for receives. Value's * type should be PP_VARTYPE_INT32. - * This option can only be set after a successful Bind() call. + * On version 1.0, this option can only be set after a successful + * Bind() call. On version 1.1 or later, there is no such + * limitation. * * Note: This is only treated as a hint for the browser to set the buffer * size. Even if SetOption() succeeds, the browser doesn't @@ -84,7 +90,7 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_UDPSocket_Option, 4); * For more details about network communication permissions, please see: * http://developer.chrome.com/apps/app_network.html */ -struct PPB_UDPSocket_1_0 { +struct PPB_UDPSocket_1_1 { /** * Creates a UDP socket resource. * @@ -208,7 +214,31 @@ struct PPB_UDPSocket_1_0 { struct PP_CompletionCallback callback); }; -typedef struct PPB_UDPSocket_1_0 PPB_UDPSocket; +typedef struct PPB_UDPSocket_1_1 PPB_UDPSocket; + +struct PPB_UDPSocket_1_0 { + PP_Resource (*Create)(PP_Instance instance); + PP_Bool (*IsUDPSocket)(PP_Resource resource); + int32_t (*Bind)(PP_Resource udp_socket, + PP_Resource addr, + struct PP_CompletionCallback callback); + PP_Resource (*GetBoundAddress)(PP_Resource udp_socket); + int32_t (*RecvFrom)(PP_Resource udp_socket, + char* buffer, + int32_t num_bytes, + PP_Resource* addr, + struct PP_CompletionCallback callback); + int32_t (*SendTo)(PP_Resource udp_socket, + const char* buffer, + int32_t num_bytes, + PP_Resource addr, + struct PP_CompletionCallback callback); + void (*Close)(PP_Resource udp_socket); + int32_t (*SetOption)(PP_Resource udp_socket, + PP_UDPSocket_Option name, + struct PP_Var value, + struct PP_CompletionCallback callback); +}; /** * @} */ diff --git a/ppapi/cpp/tcp_socket.cc b/ppapi/cpp/tcp_socket.cc index ab08ff3626c6..900d2ad4959e 100644 --- a/ppapi/cpp/tcp_socket.cc +++ b/ppapi/cpp/tcp_socket.cc @@ -21,13 +21,20 @@ template <> const char* interface_name() { return PPB_TCPSOCKET_INTERFACE_1_1; } +template <> const char* interface_name() { + return PPB_TCPSOCKET_INTERFACE_1_2; +} + } // namespace TCPSocket::TCPSocket() { } TCPSocket::TCPSocket(const InstanceHandle& instance) { - if (has_interface()) { + if (has_interface()) { + PassRefFromConstructor(get_interface()->Create( + instance.pp_instance())); + } else if (has_interface()) { PassRefFromConstructor(get_interface()->Create( instance.pp_instance())); } else if (has_interface()) { @@ -53,12 +60,17 @@ TCPSocket& TCPSocket::operator=(const TCPSocket& other) { // static bool TCPSocket::IsAvailable() { - return has_interface() || + return has_interface() || + has_interface() || has_interface(); } int32_t TCPSocket::Bind(const NetAddress& addr, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->Bind( + pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->Bind( pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); @@ -68,6 +80,10 @@ int32_t TCPSocket::Bind(const NetAddress& addr, int32_t TCPSocket::Connect(const NetAddress& addr, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->Connect( + pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->Connect( pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); @@ -80,6 +96,11 @@ int32_t TCPSocket::Connect(const NetAddress& addr, } NetAddress TCPSocket::GetLocalAddress() const { + if (has_interface()) { + return NetAddress( + PASS_REF, + get_interface()->GetLocalAddress(pp_resource())); + } if (has_interface()) { return NetAddress( PASS_REF, @@ -94,6 +115,11 @@ NetAddress TCPSocket::GetLocalAddress() const { } NetAddress TCPSocket::GetRemoteAddress() const { + if (has_interface()) { + return NetAddress( + PASS_REF, + get_interface()->GetRemoteAddress(pp_resource())); + } if (has_interface()) { return NetAddress( PASS_REF, @@ -110,6 +136,11 @@ NetAddress TCPSocket::GetRemoteAddress() const { int32_t TCPSocket::Read(char* buffer, int32_t bytes_to_read, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->Read( + pp_resource(), buffer, bytes_to_read, + callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->Read( pp_resource(), buffer, bytes_to_read, @@ -126,6 +157,11 @@ int32_t TCPSocket::Read(char* buffer, int32_t TCPSocket::Write(const char* buffer, int32_t bytes_to_write, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->Write( + pp_resource(), buffer, bytes_to_write, + callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->Write( pp_resource(), buffer, bytes_to_write, @@ -141,6 +177,10 @@ int32_t TCPSocket::Write(const char* buffer, int32_t TCPSocket::Listen(int32_t backlog, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->Listen( + pp_resource(), backlog, callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->Listen( pp_resource(), backlog, callback.pp_completion_callback()); @@ -150,6 +190,10 @@ int32_t TCPSocket::Listen(int32_t backlog, int32_t TCPSocket::Accept( const CompletionCallbackWithOutput& callback) { + if (has_interface()) { + return get_interface()->Accept( + pp_resource(), callback.output(), callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->Accept( pp_resource(), callback.output(), callback.pp_completion_callback()); @@ -158,7 +202,9 @@ int32_t TCPSocket::Accept( } void TCPSocket::Close() { - if (has_interface()) { + if (has_interface()) { + get_interface()->Close(pp_resource()); + } else if (has_interface()) { get_interface()->Close(pp_resource()); } else if (has_interface()) { get_interface()->Close(pp_resource()); @@ -168,6 +214,10 @@ void TCPSocket::Close() { int32_t TCPSocket::SetOption(PP_TCPSocket_Option name, const Var& value, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->SetOption( + pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->SetOption( pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); diff --git a/ppapi/cpp/udp_socket.cc b/ppapi/cpp/udp_socket.cc index bb4b1c895b05..2f8c505df589 100644 --- a/ppapi/cpp/udp_socket.cc +++ b/ppapi/cpp/udp_socket.cc @@ -18,13 +18,20 @@ template <> const char* interface_name() { return PPB_UDPSOCKET_INTERFACE_1_0; } +template <> const char* interface_name() { + return PPB_UDPSOCKET_INTERFACE_1_1; +} + } // namespace UDPSocket::UDPSocket() { } UDPSocket::UDPSocket(const InstanceHandle& instance) { - if (has_interface()) { + if (has_interface()) { + PassRefFromConstructor(get_interface()->Create( + instance.pp_instance())); + } else if (has_interface()) { PassRefFromConstructor(get_interface()->Create( instance.pp_instance())); } @@ -47,11 +54,16 @@ UDPSocket& UDPSocket::operator=(const UDPSocket& other) { // static bool UDPSocket::IsAvailable() { - return has_interface(); + return has_interface() || + has_interface(); } int32_t UDPSocket::Bind(const NetAddress& addr, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->Bind( + pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->Bind( pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); @@ -60,6 +72,11 @@ int32_t UDPSocket::Bind(const NetAddress& addr, } NetAddress UDPSocket::GetBoundAddress() { + if (has_interface()) { + return NetAddress( + PASS_REF, + get_interface()->GetBoundAddress(pp_resource())); + } if (has_interface()) { return NetAddress( PASS_REF, @@ -72,6 +89,11 @@ int32_t UDPSocket::RecvFrom( char* buffer, int32_t num_bytes, const CompletionCallbackWithOutput& callback) { + if (has_interface()) { + return get_interface()->RecvFrom( + pp_resource(), buffer, num_bytes, callback.output(), + callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->RecvFrom( pp_resource(), buffer, num_bytes, callback.output(), @@ -84,6 +106,11 @@ int32_t UDPSocket::SendTo(const char* buffer, int32_t num_bytes, const NetAddress& addr, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->SendTo( + pp_resource(), buffer, num_bytes, addr.pp_resource(), + callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->SendTo( pp_resource(), buffer, num_bytes, addr.pp_resource(), @@ -93,6 +120,8 @@ int32_t UDPSocket::SendTo(const char* buffer, } void UDPSocket::Close() { + if (has_interface()) + return get_interface()->Close(pp_resource()); if (has_interface()) return get_interface()->Close(pp_resource()); } @@ -100,6 +129,10 @@ void UDPSocket::Close() { int32_t UDPSocket::SetOption(PP_UDPSocket_Option name, const Var& value, const CompletionCallback& callback) { + if (has_interface()) { + return get_interface()->SetOption( + pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); + } if (has_interface()) { return get_interface()->SetOption( pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 82e09e803700..f2cd8ca827f7 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -132,8 +132,10 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_NetworkMonitor_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_NetworkProxy_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TCPSocket_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TCPSocket_1_1; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TCPSocket_1_2; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TextInputController_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_1_0; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_1_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLLoader_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLRequestInfo_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLResponseInfo_1_0; @@ -1605,6 +1607,70 @@ static int32_t Pnacl_M31_PPB_TCPSocket_SetOption(PP_Resource tcp_socket, PP_TCPS /* End wrapper methods for PPB_TCPSocket_1_1 */ +/* Begin wrapper methods for PPB_TCPSocket_1_2 */ + +static PP_Resource Pnacl_M41_PPB_TCPSocket_Create(PP_Instance instance) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->Create(instance); +} + +static PP_Bool Pnacl_M41_PPB_TCPSocket_IsTCPSocket(PP_Resource resource) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->IsTCPSocket(resource); +} + +static int32_t Pnacl_M41_PPB_TCPSocket_Bind(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback* callback) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->Bind(tcp_socket, addr, *callback); +} + +static int32_t Pnacl_M41_PPB_TCPSocket_Connect(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback* callback) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->Connect(tcp_socket, addr, *callback); +} + +static PP_Resource Pnacl_M41_PPB_TCPSocket_GetLocalAddress(PP_Resource tcp_socket) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->GetLocalAddress(tcp_socket); +} + +static PP_Resource Pnacl_M41_PPB_TCPSocket_GetRemoteAddress(PP_Resource tcp_socket) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->GetRemoteAddress(tcp_socket); +} + +static int32_t Pnacl_M41_PPB_TCPSocket_Read(PP_Resource tcp_socket, char* buffer, int32_t bytes_to_read, struct PP_CompletionCallback* callback) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->Read(tcp_socket, buffer, bytes_to_read, *callback); +} + +static int32_t Pnacl_M41_PPB_TCPSocket_Write(PP_Resource tcp_socket, const char* buffer, int32_t bytes_to_write, struct PP_CompletionCallback* callback) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->Write(tcp_socket, buffer, bytes_to_write, *callback); +} + +static int32_t Pnacl_M41_PPB_TCPSocket_Listen(PP_Resource tcp_socket, int32_t backlog, struct PP_CompletionCallback* callback) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->Listen(tcp_socket, backlog, *callback); +} + +static int32_t Pnacl_M41_PPB_TCPSocket_Accept(PP_Resource tcp_socket, PP_Resource* accepted_tcp_socket, struct PP_CompletionCallback* callback) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->Accept(tcp_socket, accepted_tcp_socket, *callback); +} + +static void Pnacl_M41_PPB_TCPSocket_Close(PP_Resource tcp_socket) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + iface->Close(tcp_socket); +} + +static int32_t Pnacl_M41_PPB_TCPSocket_SetOption(PP_Resource tcp_socket, PP_TCPSocket_Option name, struct PP_Var* value, struct PP_CompletionCallback* callback) { + const struct PPB_TCPSocket_1_2 *iface = Pnacl_WrapperInfo_PPB_TCPSocket_1_2.real_iface; + return iface->SetOption(tcp_socket, name, *value, *callback); +} + +/* End wrapper methods for PPB_TCPSocket_1_2 */ + /* Begin wrapper methods for PPB_TextInputController_1_0 */ static void Pnacl_M30_PPB_TextInputController_SetTextInputType(PP_Instance instance, PP_TextInput_Type type) { @@ -1673,6 +1739,50 @@ static int32_t Pnacl_M29_PPB_UDPSocket_SetOption(PP_Resource udp_socket, PP_UDPS /* End wrapper methods for PPB_UDPSocket_1_0 */ +/* Begin wrapper methods for PPB_UDPSocket_1_1 */ + +static PP_Resource Pnacl_M41_PPB_UDPSocket_Create(PP_Instance instance) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + return iface->Create(instance); +} + +static PP_Bool Pnacl_M41_PPB_UDPSocket_IsUDPSocket(PP_Resource resource) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + return iface->IsUDPSocket(resource); +} + +static int32_t Pnacl_M41_PPB_UDPSocket_Bind(PP_Resource udp_socket, PP_Resource addr, struct PP_CompletionCallback* callback) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + return iface->Bind(udp_socket, addr, *callback); +} + +static PP_Resource Pnacl_M41_PPB_UDPSocket_GetBoundAddress(PP_Resource udp_socket) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + return iface->GetBoundAddress(udp_socket); +} + +static int32_t Pnacl_M41_PPB_UDPSocket_RecvFrom(PP_Resource udp_socket, char* buffer, int32_t num_bytes, PP_Resource* addr, struct PP_CompletionCallback* callback) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + return iface->RecvFrom(udp_socket, buffer, num_bytes, addr, *callback); +} + +static int32_t Pnacl_M41_PPB_UDPSocket_SendTo(PP_Resource udp_socket, const char* buffer, int32_t num_bytes, PP_Resource addr, struct PP_CompletionCallback* callback) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + return iface->SendTo(udp_socket, buffer, num_bytes, addr, *callback); +} + +static void Pnacl_M41_PPB_UDPSocket_Close(PP_Resource udp_socket) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + iface->Close(udp_socket); +} + +static int32_t Pnacl_M41_PPB_UDPSocket_SetOption(PP_Resource udp_socket, PP_UDPSocket_Option name, struct PP_Var* value, struct PP_CompletionCallback* callback) { + const struct PPB_UDPSocket_1_1 *iface = Pnacl_WrapperInfo_PPB_UDPSocket_1_1.real_iface; + return iface->SetOption(udp_socket, name, *value, *callback); +} + +/* End wrapper methods for PPB_UDPSocket_1_1 */ + /* Begin wrapper methods for PPB_URLLoader_1_0 */ static PP_Resource Pnacl_M14_PPB_URLLoader_Create(PP_Instance instance) { @@ -4951,6 +5061,21 @@ static const struct PPB_TCPSocket_1_1 Pnacl_Wrappers_PPB_TCPSocket_1_1 = { .SetOption = (int32_t (*)(PP_Resource tcp_socket, PP_TCPSocket_Option name, struct PP_Var value, struct PP_CompletionCallback callback))&Pnacl_M31_PPB_TCPSocket_SetOption }; +static const struct PPB_TCPSocket_1_2 Pnacl_Wrappers_PPB_TCPSocket_1_2 = { + .Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M41_PPB_TCPSocket_Create, + .IsTCPSocket = (PP_Bool (*)(PP_Resource resource))&Pnacl_M41_PPB_TCPSocket_IsTCPSocket, + .Bind = (int32_t (*)(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_TCPSocket_Bind, + .Connect = (int32_t (*)(PP_Resource tcp_socket, PP_Resource addr, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_TCPSocket_Connect, + .GetLocalAddress = (PP_Resource (*)(PP_Resource tcp_socket))&Pnacl_M41_PPB_TCPSocket_GetLocalAddress, + .GetRemoteAddress = (PP_Resource (*)(PP_Resource tcp_socket))&Pnacl_M41_PPB_TCPSocket_GetRemoteAddress, + .Read = (int32_t (*)(PP_Resource tcp_socket, char* buffer, int32_t bytes_to_read, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_TCPSocket_Read, + .Write = (int32_t (*)(PP_Resource tcp_socket, const char* buffer, int32_t bytes_to_write, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_TCPSocket_Write, + .Listen = (int32_t (*)(PP_Resource tcp_socket, int32_t backlog, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_TCPSocket_Listen, + .Accept = (int32_t (*)(PP_Resource tcp_socket, PP_Resource* accepted_tcp_socket, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_TCPSocket_Accept, + .Close = (void (*)(PP_Resource tcp_socket))&Pnacl_M41_PPB_TCPSocket_Close, + .SetOption = (int32_t (*)(PP_Resource tcp_socket, PP_TCPSocket_Option name, struct PP_Var value, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_TCPSocket_SetOption +}; + static const struct PPB_TextInputController_1_0 Pnacl_Wrappers_PPB_TextInputController_1_0 = { .SetTextInputType = (void (*)(PP_Instance instance, PP_TextInput_Type type))&Pnacl_M30_PPB_TextInputController_SetTextInputType, .UpdateCaretPosition = (void (*)(PP_Instance instance, const struct PP_Rect* caret))&Pnacl_M30_PPB_TextInputController_UpdateCaretPosition, @@ -4969,6 +5094,17 @@ static const struct PPB_UDPSocket_1_0 Pnacl_Wrappers_PPB_UDPSocket_1_0 = { .SetOption = (int32_t (*)(PP_Resource udp_socket, PP_UDPSocket_Option name, struct PP_Var value, struct PP_CompletionCallback callback))&Pnacl_M29_PPB_UDPSocket_SetOption }; +static const struct PPB_UDPSocket_1_1 Pnacl_Wrappers_PPB_UDPSocket_1_1 = { + .Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M41_PPB_UDPSocket_Create, + .IsUDPSocket = (PP_Bool (*)(PP_Resource resource))&Pnacl_M41_PPB_UDPSocket_IsUDPSocket, + .Bind = (int32_t (*)(PP_Resource udp_socket, PP_Resource addr, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_UDPSocket_Bind, + .GetBoundAddress = (PP_Resource (*)(PP_Resource udp_socket))&Pnacl_M41_PPB_UDPSocket_GetBoundAddress, + .RecvFrom = (int32_t (*)(PP_Resource udp_socket, char* buffer, int32_t num_bytes, PP_Resource* addr, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_UDPSocket_RecvFrom, + .SendTo = (int32_t (*)(PP_Resource udp_socket, const char* buffer, int32_t num_bytes, PP_Resource addr, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_UDPSocket_SendTo, + .Close = (void (*)(PP_Resource udp_socket))&Pnacl_M41_PPB_UDPSocket_Close, + .SetOption = (int32_t (*)(PP_Resource udp_socket, PP_UDPSocket_Option name, struct PP_Var value, struct PP_CompletionCallback callback))&Pnacl_M41_PPB_UDPSocket_SetOption +}; + static const struct PPB_URLLoader_1_0 Pnacl_Wrappers_PPB_URLLoader_1_0 = { .Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M14_PPB_URLLoader_Create, .IsURLLoader = (PP_Bool (*)(PP_Resource resource))&Pnacl_M14_PPB_URLLoader_IsURLLoader, @@ -6000,6 +6136,12 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TCPSocket_1_1 = { .real_iface = NULL }; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TCPSocket_1_2 = { + .iface_macro = PPB_TCPSOCKET_INTERFACE_1_2, + .wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_TCPSocket_1_2, + .real_iface = NULL +}; + static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TextInputController_1_0 = { .iface_macro = PPB_TEXTINPUTCONTROLLER_INTERFACE_1_0, .wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_TextInputController_1_0, @@ -6012,6 +6154,12 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_1_0 = { .real_iface = NULL }; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_1_1 = { + .iface_macro = PPB_UDPSOCKET_INTERFACE_1_1, + .wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_UDPSocket_1_1, + .real_iface = NULL +}; + static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLLoader_1_0 = { .iface_macro = PPB_URLLOADER_INTERFACE_1_0, .wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_URLLoader_1_0, @@ -6481,8 +6629,10 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = { &Pnacl_WrapperInfo_PPB_NetworkProxy_1_0, &Pnacl_WrapperInfo_PPB_TCPSocket_1_0, &Pnacl_WrapperInfo_PPB_TCPSocket_1_1, + &Pnacl_WrapperInfo_PPB_TCPSocket_1_2, &Pnacl_WrapperInfo_PPB_TextInputController_1_0, &Pnacl_WrapperInfo_PPB_UDPSocket_1_0, + &Pnacl_WrapperInfo_PPB_UDPSocket_1_1, &Pnacl_WrapperInfo_PPB_URLLoader_1_0, &Pnacl_WrapperInfo_PPB_URLRequestInfo_1_0, &Pnacl_WrapperInfo_PPB_URLResponseInfo_1_0, diff --git a/ppapi/proxy/tcp_socket_private_resource.cc b/ppapi/proxy/tcp_socket_private_resource.cc index 76ed4b9e1e29..454c3faf1a37 100644 --- a/ppapi/proxy/tcp_socket_private_resource.cc +++ b/ppapi/proxy/tcp_socket_private_resource.cc @@ -101,7 +101,9 @@ int32_t TCPSocketPrivateResource::SetOption( case PP_TCPSOCKETOPTION_PRIVATE_INVALID: return PP_ERROR_BADARGUMENT; case PP_TCPSOCKETOPTION_PRIVATE_NO_DELAY: - return SetOptionImpl(PP_TCPSOCKET_OPTION_NO_DELAY, value, callback); + return SetOptionImpl(PP_TCPSOCKET_OPTION_NO_DELAY, value, + true, // Check connect() state. + callback); default: NOTREACHED(); return PP_ERROR_BADARGUMENT; diff --git a/ppapi/proxy/tcp_socket_resource.cc b/ppapi/proxy/tcp_socket_resource.cc index f8f8f68f2613..5466d0d23ab5 100644 --- a/ppapi/proxy/tcp_socket_resource.cc +++ b/ppapi/proxy/tcp_socket_resource.cc @@ -115,10 +115,21 @@ void TCPSocketResource::Close() { CloseImpl(); } +int32_t TCPSocketResource::SetOption1_1( + PP_TCPSocket_Option name, + const PP_Var& value, + scoped_refptr callback) { + return SetOptionImpl(name, value, + true, // Check connect() state. + callback); +} + int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name, const PP_Var& value, scoped_refptr callback) { - return SetOptionImpl(name, value, callback); + return SetOptionImpl(name, value, + false, // Do not check connect() state. + callback); } PP_Resource TCPSocketResource::CreateAcceptedSocket( diff --git a/ppapi/proxy/tcp_socket_resource.h b/ppapi/proxy/tcp_socket_resource.h index 6a8e9fff0f4e..6ac0929818f2 100644 --- a/ppapi/proxy/tcp_socket_resource.h +++ b/ppapi/proxy/tcp_socket_resource.h @@ -47,6 +47,10 @@ class PPAPI_PROXY_EXPORT TCPSocketResource : public thunk::PPB_TCPSocket_API, virtual int32_t Accept(PP_Resource* accepted_tcp_socket, scoped_refptr callback) override; virtual void Close() override; + virtual int32_t SetOption1_1( + PP_TCPSocket_Option name, + const PP_Var& value, + scoped_refptr callback) override; virtual int32_t SetOption(PP_TCPSocket_Option name, const PP_Var& value, scoped_refptr callback) override; diff --git a/ppapi/proxy/tcp_socket_resource_base.cc b/ppapi/proxy/tcp_socket_resource_base.cc index 39c9fa311d68..fb4db5bee64a 100644 --- a/ppapi/proxy/tcp_socket_resource_base.cc +++ b/ppapi/proxy/tcp_socket_resource_base.cc @@ -318,11 +318,12 @@ void TCPSocketResourceBase::CloseImpl() { int32_t TCPSocketResourceBase::SetOptionImpl( PP_TCPSocket_Option name, const PP_Var& value, + bool check_connect_state, scoped_refptr callback) { SocketOptionData option_data; switch (name) { case PP_TCPSOCKET_OPTION_NO_DELAY: { - if (!state_.IsConnected()) + if (check_connect_state && !state_.IsConnected()) return PP_ERROR_FAILED; if (value.type != PP_VARTYPE_BOOL) @@ -332,7 +333,7 @@ int32_t TCPSocketResourceBase::SetOptionImpl( } case PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE: case PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE: { - if (!state_.IsConnected()) + if (check_connect_state && !state_.IsConnected()) return PP_ERROR_FAILED; if (value.type != PP_VARTYPE_INT32) diff --git a/ppapi/proxy/tcp_socket_resource_base.h b/ppapi/proxy/tcp_socket_resource_base.h index 8835ab974b16..3274fb9518e9 100644 --- a/ppapi/proxy/tcp_socket_resource_base.h +++ b/ppapi/proxy/tcp_socket_resource_base.h @@ -95,6 +95,7 @@ class PPAPI_PROXY_EXPORT TCPSocketResourceBase : public PluginResource { void CloseImpl(); int32_t SetOptionImpl(PP_TCPSocket_Option name, const PP_Var& value, + bool check_connect_state, scoped_refptr callback); void PostAbortIfNecessary(scoped_refptr* callback); diff --git a/ppapi/proxy/udp_socket_private_resource.cc b/ppapi/proxy/udp_socket_private_resource.cc index af43c10fb05e..60afc6f3593f 100644 --- a/ppapi/proxy/udp_socket_private_resource.cc +++ b/ppapi/proxy/udp_socket_private_resource.cc @@ -41,7 +41,9 @@ int32_t UDPSocketPrivateResource::SetSocketFeature( NOTREACHED(); return PP_ERROR_BADARGUMENT; } - int32_t result = SetOptionImpl(public_name, value, NULL); + int32_t result = SetOptionImpl(public_name, value, + true, // Check bind() state. + NULL); return result == PP_OK_COMPLETIONPENDING ? PP_OK : result; } diff --git a/ppapi/proxy/udp_socket_resource.cc b/ppapi/proxy/udp_socket_resource.cc index 9ce7c91f1307..d815b9fa62f5 100644 --- a/ppapi/proxy/udp_socket_resource.cc +++ b/ppapi/proxy/udp_socket_resource.cc @@ -75,11 +75,22 @@ void UDPSocketResource::Close() { CloseImpl(); } +int32_t UDPSocketResource::SetOption1_0( + PP_UDPSocket_Option name, + const PP_Var& value, + scoped_refptr callback) { + return SetOptionImpl(name, value, + true, // Check bind() state. + callback); +} + int32_t UDPSocketResource::SetOption( PP_UDPSocket_Option name, const PP_Var& value, scoped_refptr callback) { - return SetOptionImpl(name, value, callback); + return SetOptionImpl(name, value, + false, // Check bind() state. + callback); } } // namespace proxy diff --git a/ppapi/proxy/udp_socket_resource.h b/ppapi/proxy/udp_socket_resource.h index e0d099afef23..81aad2621030 100644 --- a/ppapi/proxy/udp_socket_resource.h +++ b/ppapi/proxy/udp_socket_resource.h @@ -36,6 +36,10 @@ class PPAPI_PROXY_EXPORT UDPSocketResource : public UDPSocketResourceBase, PP_Resource addr, scoped_refptr callback) override; virtual void Close() override; + virtual int32_t SetOption1_0( + PP_UDPSocket_Option name, + const PP_Var& value, + scoped_refptr callback) override; virtual int32_t SetOption(PP_UDPSocket_Option name, const PP_Var& value, scoped_refptr callback) override; diff --git a/ppapi/proxy/udp_socket_resource_base.cc b/ppapi/proxy/udp_socket_resource_base.cc index 521a6e2f4e28..8ed6d0299ed6 100644 --- a/ppapi/proxy/udp_socket_resource_base.cc +++ b/ppapi/proxy/udp_socket_resource_base.cc @@ -34,6 +34,7 @@ UDPSocketResourceBase::UDPSocketResourceBase(Connection connection, bool private_api) : PluginResource(connection, instance), private_api_(private_api), + bind_called_(false), bound_(false), closed_(false), read_buffer_(NULL), @@ -61,6 +62,7 @@ UDPSocketResourceBase::~UDPSocketResourceBase() { int32_t UDPSocketResourceBase::SetOptionImpl( PP_UDPSocket_Option name, const PP_Var& value, + bool check_bind_state, scoped_refptr callback) { if (closed_) return PP_ERROR_FAILED; @@ -69,8 +71,14 @@ int32_t UDPSocketResourceBase::SetOptionImpl( switch (name) { case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: case PP_UDPSOCKET_OPTION_BROADCAST: { - if (bound_) + if ((check_bind_state || name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) && + bind_called_) { + // SetOption should fail in this case in order to give predictable + // behavior while binding. Note that we use |bind_called_| rather + // than |bound_| since the latter is only set on successful completion + // of Bind(). return PP_ERROR_FAILED; + } if (value.type != PP_VARTYPE_BOOL) return PP_ERROR_BADARGUMENT; option_data.SetBool(PP_ToBool(value.value.as_bool)); @@ -78,7 +86,7 @@ int32_t UDPSocketResourceBase::SetOptionImpl( } case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { - if (!bound_) + if (check_bind_state && !bound_) return PP_ERROR_FAILED; if (value.type != PP_VARTYPE_INT32) return PP_ERROR_BADARGUMENT; @@ -111,6 +119,7 @@ int32_t UDPSocketResourceBase::BindImpl( if (TrackedCallback::IsPending(bind_callback_)) return PP_ERROR_INPROGRESS; + bind_called_ = true; bind_callback_ = callback; // Send the request, the browser will call us back via BindReply. diff --git a/ppapi/proxy/udp_socket_resource_base.h b/ppapi/proxy/udp_socket_resource_base.h index 5400f6be9955..d21579b3cfc0 100644 --- a/ppapi/proxy/udp_socket_resource_base.h +++ b/ppapi/proxy/udp_socket_resource_base.h @@ -54,6 +54,7 @@ class PPAPI_PROXY_EXPORT UDPSocketResourceBase: public PluginResource { int32_t SetOptionImpl(PP_UDPSocket_Option name, const PP_Var& value, + bool check_bind_state, scoped_refptr callback); int32_t BindImpl(const PP_NetAddress_Private* addr, scoped_refptr callback); @@ -106,6 +107,11 @@ class PPAPI_PROXY_EXPORT UDPSocketResourceBase: public PluginResource { PP_Resource* output_addr); bool private_api_; + + // |bind_called_| is true after Bind() is called, while |bound_| is true, + // after Bind() succeeds. Bind() is an asynchronous method, so the timing + // on which of these is set is slightly different. + bool bind_called_; bool bound_; bool closed_; diff --git a/ppapi/tests/test_tcp_socket.cc b/ppapi/tests/test_tcp_socket.cc index 604487c5b951..a3164deb6b6c 100644 --- a/ppapi/tests/test_tcp_socket.cc +++ b/ppapi/tests/test_tcp_socket.cc @@ -140,7 +140,7 @@ std::string TestTCPSocket::TestSetOption() { TestCompletionCallback cb_2(instance_->pp_instance(), callback_type()); TestCompletionCallback cb_3(instance_->pp_instance(), callback_type()); - // These options cannot be set before the socket is connected. + // These options can be set even before the socket is connected. int32_t result_1 = socket.SetOption(PP_TCPSOCKET_OPTION_NO_DELAY, true, cb_1.GetCallback()); int32_t result_2 = socket.SetOption(PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE, @@ -150,15 +150,15 @@ std::string TestTCPSocket::TestSetOption() { cb_1.WaitForResult(result_1); CHECK_CALLBACK_BEHAVIOR(cb_1); - ASSERT_EQ(PP_ERROR_FAILED, cb_1.result()); + ASSERT_EQ(PP_OK, cb_1.result()); cb_2.WaitForResult(result_2); CHECK_CALLBACK_BEHAVIOR(cb_2); - ASSERT_EQ(PP_ERROR_FAILED, cb_2.result()); + ASSERT_EQ(PP_OK, cb_2.result()); cb_3.WaitForResult(result_3); CHECK_CALLBACK_BEHAVIOR(cb_3); - ASSERT_EQ(PP_ERROR_FAILED, cb_3.result()); + ASSERT_EQ(PP_OK, cb_3.result()); cb_1.WaitForResult(socket.Connect(addr_, cb_1.GetCallback())); CHECK_CALLBACK_BEHAVIOR(cb_1); @@ -458,4 +458,3 @@ std::string TestTCPSocket::StartListen(pp::TCPSocket* socket, int32_t backlog) { PASS(); } - diff --git a/ppapi/tests/test_udp_socket.cc b/ppapi/tests/test_udp_socket.cc index e0b76f47728b..8972e4e94385 100644 --- a/ppapi/tests/test_udp_socket.cc +++ b/ppapi/tests/test_udp_socket.cc @@ -272,36 +272,35 @@ std::string TestUDPSocket::TestSetOption() { CHECK_CALLBACK_BEHAVIOR(callback); ASSERT_EQ(PP_OK, callback.result()); - // SEND_BUFFER_SIZE and RECV_BUFFER_SIZE shouldn't be set before the socket is - // bound. callback.WaitForResult(socket.SetOption( PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE, pp::Var(4096), callback.GetCallback())); CHECK_CALLBACK_BEHAVIOR(callback); - ASSERT_EQ(PP_ERROR_FAILED, callback.result()); + ASSERT_EQ(PP_OK, callback.result()); callback.WaitForResult(socket.SetOption( PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE, pp::Var(512), callback.GetCallback())); CHECK_CALLBACK_BEHAVIOR(callback); - ASSERT_EQ(PP_ERROR_FAILED, callback.result()); + ASSERT_EQ(PP_OK, callback.result()); pp::NetAddress address; ASSERT_SUBTEST_SUCCESS(LookupPortAndBindUDPSocket(&socket, &address)); - // ADDRESS_REUSE and BROADCAST won't take effect after the socket is bound. + // ADDRESS_REUSE won't take effect after the socket is bound. callback.WaitForResult(socket.SetOption( PP_UDPSOCKET_OPTION_ADDRESS_REUSE, pp::Var(true), callback.GetCallback())); CHECK_CALLBACK_BEHAVIOR(callback); ASSERT_EQ(PP_ERROR_FAILED, callback.result()); + // BROADCAST, SEND_BUFFER_SIZE and RECV_BUFFER_SIZE can be set after the + // socket is bound. callback.WaitForResult(socket.SetOption( PP_UDPSOCKET_OPTION_BROADCAST, pp::Var(true), callback.GetCallback())); CHECK_CALLBACK_BEHAVIOR(callback); - ASSERT_EQ(PP_ERROR_FAILED, callback.result()); + ASSERT_EQ(PP_OK, callback.result()); - // SEND_BUFFER_SIZE and RECV_BUFFER_SIZE can be set after the socket is bound. callback.WaitForResult(socket.SetOption( PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE, pp::Var(2048), callback.GetCallback())); diff --git a/ppapi/thunk/interfaces_ppb_public_stable.h b/ppapi/thunk/interfaces_ppb_public_stable.h index a95d50576fc4..0f430c7c2d89 100644 --- a/ppapi/thunk/interfaces_ppb_public_stable.h +++ b/ppapi/thunk/interfaces_ppb_public_stable.h @@ -86,9 +86,11 @@ PROXIED_IFACE(PPB_NETWORKMONITOR_INTERFACE_1_0, PPB_NetworkMonitor_1_0) PROXIED_IFACE(PPB_NETWORKPROXY_INTERFACE_1_0, PPB_NetworkProxy_1_0) PROXIED_IFACE(PPB_TCPSOCKET_INTERFACE_1_0, PPB_TCPSocket_1_0) PROXIED_IFACE(PPB_TCPSOCKET_INTERFACE_1_1, PPB_TCPSocket_1_1) +PROXIED_IFACE(PPB_TCPSOCKET_INTERFACE_1_2, PPB_TCPSocket_1_2) PROXIED_IFACE(PPB_TEXTINPUTCONTROLLER_INTERFACE_1_0, PPB_TextInputController_1_0) PROXIED_IFACE(PPB_UDPSOCKET_INTERFACE_1_0, PPB_UDPSocket_1_0) +PROXIED_IFACE(PPB_UDPSOCKET_INTERFACE_1_1, PPB_UDPSocket_1_1) PROXIED_IFACE(PPB_URLLOADER_INTERFACE_1_0, PPB_URLLoader_1_0) PROXIED_IFACE(PPB_URLREQUESTINFO_INTERFACE_1_0, PPB_URLRequestInfo_1_0) PROXIED_IFACE(PPB_URLRESPONSEINFO_INTERFACE_1_0, PPB_URLResponseInfo_1_0) diff --git a/ppapi/thunk/ppb_tcp_socket_api.h b/ppapi/thunk/ppb_tcp_socket_api.h index beed0c6317a8..a3cefed2e3f2 100644 --- a/ppapi/thunk/ppb_tcp_socket_api.h +++ b/ppapi/thunk/ppb_tcp_socket_api.h @@ -36,6 +36,9 @@ class PPAPI_THUNK_EXPORT PPB_TCPSocket_API { virtual int32_t Accept(PP_Resource* accepted_tcp_socket, scoped_refptr callback) = 0; virtual void Close() = 0; + virtual int32_t SetOption1_1(PP_TCPSocket_Option name, + const PP_Var& value, + scoped_refptr callback) = 0; virtual int32_t SetOption(PP_TCPSocket_Option name, const PP_Var& value, scoped_refptr callback) = 0; diff --git a/ppapi/thunk/ppb_tcp_socket_thunk.cc b/ppapi/thunk/ppb_tcp_socket_thunk.cc index 42ae702e5e39..c73e593f5203 100644 --- a/ppapi/thunk/ppb_tcp_socket_thunk.cc +++ b/ppapi/thunk/ppb_tcp_socket_thunk.cc @@ -132,6 +132,19 @@ void Close(PP_Resource tcp_socket) { enter.object()->Close(); } +int32_t SetOption1_1(PP_Resource tcp_socket, + PP_TCPSocket_Option name, + struct PP_Var value, + struct PP_CompletionCallback callback) { + VLOG(4) << "PPB_TCPSocket::SetOption1_1()"; + EnterResource enter(tcp_socket, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult(enter.object()->SetOption1_1(name, + value, + enter.callback())); +} + int32_t SetOption(PP_Resource tcp_socket, PP_TCPSocket_Option name, struct PP_Var value, @@ -154,7 +167,7 @@ const PPB_TCPSocket_1_0 g_ppb_tcpsocket_thunk_1_0 = { &Read, &Write, &Close, - &SetOption + &SetOption1_1 }; const PPB_TCPSocket_1_1 g_ppb_tcpsocket_thunk_1_1 = { @@ -169,6 +182,21 @@ const PPB_TCPSocket_1_1 g_ppb_tcpsocket_thunk_1_1 = { &Listen, &Accept, &Close, + &SetOption1_1 +}; + +const PPB_TCPSocket_1_2 g_ppb_tcpsocket_thunk_1_2 = { + &Create, + &IsTCPSocket, + &Bind, + &Connect, + &GetLocalAddress, + &GetRemoteAddress, + &Read, + &Write, + &Listen, + &Accept, + &Close, &SetOption }; @@ -182,5 +210,9 @@ const PPB_TCPSocket_1_1* GetPPB_TCPSocket_1_1_Thunk() { return &g_ppb_tcpsocket_thunk_1_1; } +const PPB_TCPSocket_1_2* GetPPB_TCPSocket_1_2_Thunk() { + return &g_ppb_tcpsocket_thunk_1_2; +} + } // namespace thunk } // namespace ppapi diff --git a/ppapi/thunk/ppb_udp_socket_api.h b/ppapi/thunk/ppb_udp_socket_api.h index adc2799116f2..3a03ea76c828 100644 --- a/ppapi/thunk/ppb_udp_socket_api.h +++ b/ppapi/thunk/ppb_udp_socket_api.h @@ -31,6 +31,9 @@ class PPAPI_THUNK_EXPORT PPB_UDPSocket_API { PP_Resource addr, scoped_refptr callback) = 0; virtual void Close() = 0; + virtual int32_t SetOption1_0(PP_UDPSocket_Option name, + const PP_Var& value, + scoped_refptr callback) = 0; virtual int32_t SetOption(PP_UDPSocket_Option name, const PP_Var& value, scoped_refptr callback) = 0; diff --git a/ppapi/thunk/ppb_udp_socket_thunk.cc b/ppapi/thunk/ppb_udp_socket_thunk.cc index 7391526f682b..7eca736923ff 100644 --- a/ppapi/thunk/ppb_udp_socket_thunk.cc +++ b/ppapi/thunk/ppb_udp_socket_thunk.cc @@ -83,6 +83,18 @@ void Close(PP_Resource udp_socket) { enter.object()->Close(); } +int32_t SetOption1_0(PP_Resource udp_socket, + PP_UDPSocket_Option name, + struct PP_Var value, + struct PP_CompletionCallback callback) { + VLOG(4) << "PPB_UDPSocket::SetOption1_0()"; + EnterResource enter(udp_socket, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult( + enter.object()->SetOption1_0(name, value, enter.callback())); +} + int32_t SetOption(PP_Resource udp_socket, PP_UDPSocket_Option name, struct PP_Var value, @@ -95,14 +107,27 @@ int32_t SetOption(PP_Resource udp_socket, enter.object()->SetOption(name, value, enter.callback())); } -const PPB_UDPSocket_1_0 g_ppb_udpsocket_thunk_1_0 = {&Create, - &IsUDPSocket, - &Bind, - &GetBoundAddress, - &RecvFrom, - &SendTo, - &Close, - &SetOption}; +const PPB_UDPSocket_1_0 g_ppb_udpsocket_thunk_1_0 = { + &Create, + &IsUDPSocket, + &Bind, + &GetBoundAddress, + &RecvFrom, + &SendTo, + &Close, + &SetOption1_0 +}; + +const PPB_UDPSocket_1_1 g_ppb_udpsocket_thunk_1_1 = { + &Create, + &IsUDPSocket, + &Bind, + &GetBoundAddress, + &RecvFrom, + &SendTo, + &Close, + &SetOption +}; } // namespace @@ -110,5 +135,9 @@ PPAPI_THUNK_EXPORT const PPB_UDPSocket_1_0* GetPPB_UDPSocket_1_0_Thunk() { return &g_ppb_udpsocket_thunk_1_0; } +PPAPI_THUNK_EXPORT const PPB_UDPSocket_1_1* GetPPB_UDPSocket_1_1_Thunk() { + return &g_ppb_udpsocket_thunk_1_1; +} + } // namespace thunk } // namespace ppapi diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 1ad6483d2359..abb7569d5420 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -52517,6 +52517,7 @@ To add a new entry, add it with any value and run test to compute valid value. + @@ -52559,6 +52560,7 @@ To add a new entry, add it with any value and run test to compute valid value. + -- 2.11.4.GIT