diff options
author | eduardo.lima <eduardo.lima@intel.com> | 2015-03-13 08:40:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-13 15:41:01 +0000 |
commit | 8171d46410b1ea937b0ae59577b9b36ed151149a (patch) | |
tree | 24bb98ab89f255ac337f9d584de264f931570bf3 /ppapi/cpp/udp_socket.cc | |
parent | fe37dca5b311cf194493669f26ddee27d60cc667 (diff) | |
download | chromium_src-8171d46410b1ea937b0ae59577b9b36ed151149a.zip chromium_src-8171d46410b1ea937b0ae59577b9b36ed151149a.tar.gz chromium_src-8171d46410b1ea937b0ae59577b9b36ed151149a.tar.bz2 |
Add support for multicast in PPB_UDPSocket API
This change introduces two new values to be used with SetOption(), to
set up the behavior of the multicast packets:
- PP_UDPSOCKET_OPTION_MULTICAST_LOOP (Boolean)
Whether packets sent from the host to the multicast group will be
looped back to the host or not.
- PP_UDPSOCKET_OPTION_MULTICAST_TTL (Integer)
Sets time-to-live of multicast packets sent to the multicast group.
It also introduces two new functions JoinGroup() and LeaveGroup(), both
of them expecting the address of the multicast group as specified by
the PPB_NetAddress API. These two functions should only be called after
the socket is bound.
This CL adds specific test cases to browser_tests in order to exercise
the different versions of the SetOption function. For this reason, the
PPAPI UDPSocket tests were split into multiple tests, instead of a
single one that enclosed all of them. This way we get clearer
information about the results of each test.
BUG=430939
TEST=browser_tests
NOPRESUBMIT=true
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
Review URL: https://codereview.chromium.org/704133005
Cr-Commit-Position: refs/heads/master@{#320504}
Diffstat (limited to 'ppapi/cpp/udp_socket.cc')
-rw-r--r-- | ppapi/cpp/udp_socket.cc | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/ppapi/cpp/udp_socket.cc b/ppapi/cpp/udp_socket.cc index 2f8c505..19d2894 100644 --- a/ppapi/cpp/udp_socket.cc +++ b/ppapi/cpp/udp_socket.cc @@ -22,13 +22,20 @@ template <> const char* interface_name<PPB_UDPSocket_1_1>() { return PPB_UDPSOCKET_INTERFACE_1_1; } +template <> const char* interface_name<PPB_UDPSocket_1_2>() { + return PPB_UDPSOCKET_INTERFACE_1_2; +} + } // namespace UDPSocket::UDPSocket() { } UDPSocket::UDPSocket(const InstanceHandle& instance) { - if (has_interface<PPB_UDPSocket_1_1>()) { + if (has_interface<PPB_UDPSocket_1_2>()) { + PassRefFromConstructor(get_interface<PPB_UDPSocket_1_2>()->Create( + instance.pp_instance())); + } else if (has_interface<PPB_UDPSocket_1_1>()) { PassRefFromConstructor(get_interface<PPB_UDPSocket_1_1>()->Create( instance.pp_instance())); } else if (has_interface<PPB_UDPSocket_1_0>()) { @@ -54,12 +61,17 @@ UDPSocket& UDPSocket::operator=(const UDPSocket& other) { // static bool UDPSocket::IsAvailable() { - return has_interface<PPB_UDPSocket_1_1>() || + return has_interface<PPB_UDPSocket_1_2>() || + has_interface<PPB_UDPSocket_1_1>() || has_interface<PPB_UDPSocket_1_0>(); } int32_t UDPSocket::Bind(const NetAddress& addr, const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_1_2>()) { + return get_interface<PPB_UDPSocket_1_2>()->Bind( + pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); + } if (has_interface<PPB_UDPSocket_1_1>()) { return get_interface<PPB_UDPSocket_1_1>()->Bind( pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); @@ -72,6 +84,11 @@ int32_t UDPSocket::Bind(const NetAddress& addr, } NetAddress UDPSocket::GetBoundAddress() { + if (has_interface<PPB_UDPSocket_1_2>()) { + return NetAddress( + PASS_REF, + get_interface<PPB_UDPSocket_1_2>()->GetBoundAddress(pp_resource())); + } if (has_interface<PPB_UDPSocket_1_1>()) { return NetAddress( PASS_REF, @@ -89,6 +106,11 @@ int32_t UDPSocket::RecvFrom( char* buffer, int32_t num_bytes, const CompletionCallbackWithOutput<NetAddress>& callback) { + if (has_interface<PPB_UDPSocket_1_2>()) { + return get_interface<PPB_UDPSocket_1_2>()->RecvFrom( + pp_resource(), buffer, num_bytes, callback.output(), + callback.pp_completion_callback()); + } if (has_interface<PPB_UDPSocket_1_1>()) { return get_interface<PPB_UDPSocket_1_1>()->RecvFrom( pp_resource(), buffer, num_bytes, callback.output(), @@ -106,6 +128,11 @@ int32_t UDPSocket::SendTo(const char* buffer, int32_t num_bytes, const NetAddress& addr, const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_1_2>()) { + return get_interface<PPB_UDPSocket_1_2>()->SendTo( + pp_resource(), buffer, num_bytes, addr.pp_resource(), + callback.pp_completion_callback()); + } if (has_interface<PPB_UDPSocket_1_1>()) { return get_interface<PPB_UDPSocket_1_1>()->SendTo( pp_resource(), buffer, num_bytes, addr.pp_resource(), @@ -120,6 +147,8 @@ int32_t UDPSocket::SendTo(const char* buffer, } void UDPSocket::Close() { + if (has_interface<PPB_UDPSocket_1_2>()) + return get_interface<PPB_UDPSocket_1_2>()->Close(pp_resource()); if (has_interface<PPB_UDPSocket_1_1>()) return get_interface<PPB_UDPSocket_1_1>()->Close(pp_resource()); if (has_interface<PPB_UDPSocket_1_0>()) @@ -129,6 +158,10 @@ void UDPSocket::Close() { int32_t UDPSocket::SetOption(PP_UDPSocket_Option name, const Var& value, const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_1_2>()) { + return get_interface<PPB_UDPSocket_1_2>()->SetOption( + pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); + } if (has_interface<PPB_UDPSocket_1_1>()) { return get_interface<PPB_UDPSocket_1_1>()->SetOption( pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); @@ -140,4 +173,22 @@ int32_t UDPSocket::SetOption(PP_UDPSocket_Option name, return callback.MayForce(PP_ERROR_NOINTERFACE); } +int32_t UDPSocket::JoinGroup(const NetAddress& group, + const CompletionCallback callback) { + if (has_interface<PPB_UDPSocket_1_2>()) { + return get_interface<PPB_UDPSocket_1_2>()->JoinGroup( + pp_resource(), group.pp_resource(), callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t UDPSocket::LeaveGroup(const NetAddress& group, + const CompletionCallback callback) { + if (has_interface<PPB_UDPSocket_1_2>()) { + return get_interface<PPB_UDPSocket_1_2>()->LeaveGroup( + pp_resource(), group.pp_resource(), callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + } // namespace pp |