// 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. #include "ppapi/cpp/private/tcp_server_socket_private.h" #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" namespace pp { namespace { template <> const char* interface_name() { return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_2; } template <> const char* interface_name() { return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_1; } } // namespace TCPServerSocketPrivate::TCPServerSocketPrivate(const InstanceHandle& instance) { if (has_interface()) { PassRefFromConstructor( get_interface()->Create( instance.pp_instance())); } else if (has_interface()) { PassRefFromConstructor( get_interface()->Create( instance.pp_instance())); } } // static bool TCPServerSocketPrivate::IsAvailable() { return has_interface() || has_interface(); } int32_t TCPServerSocketPrivate::Listen(const PP_NetAddress_Private* addr, int32_t backlog, const CompletionCallback& callback) { if (has_interface()) { return get_interface()->Listen( pp_resource(), addr, backlog, callback.pp_completion_callback()); } if (has_interface()) { return get_interface()->Listen( pp_resource(), addr, backlog, callback.pp_completion_callback()); } return callback.MayForce(PP_ERROR_NOINTERFACE); } int32_t TCPServerSocketPrivate::Accept(PP_Resource* tcp_socket, const CompletionCallback& callback) { if (has_interface()) { return get_interface()->Accept( pp_resource(), tcp_socket, callback.pp_completion_callback()); } if (has_interface()) { return get_interface()->Accept( pp_resource(), tcp_socket, callback.pp_completion_callback()); } return callback.MayForce(PP_ERROR_NOINTERFACE); } int32_t TCPServerSocketPrivate::GetLocalAddress(PP_NetAddress_Private* addr) { if (has_interface()) { return get_interface()->GetLocalAddress( pp_resource(), addr); } return PP_ERROR_NOINTERFACE; } void TCPServerSocketPrivate::StopListening() { if (has_interface()) { return get_interface()->StopListening( pp_resource()); } if (has_interface()) { return get_interface()->StopListening( pp_resource()); } } } // namespace pp