• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "ppapi/cpp/private/tcp_server_socket_private.h"
6 
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/cpp/completion_callback.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/module_impl.h"
12 
13 namespace pp {
14 
15 namespace {
16 
interface_name()17 template <> const char* interface_name<PPB_TCPServerSocket_Private_0_2>() {
18   return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_2;
19 }
20 
interface_name()21 template <> const char* interface_name<PPB_TCPServerSocket_Private_0_1>() {
22   return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_1;
23 }
24 
25 }  // namespace
26 
TCPServerSocketPrivate(const InstanceHandle & instance)27 TCPServerSocketPrivate::TCPServerSocketPrivate(const InstanceHandle& instance) {
28   if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
29     PassRefFromConstructor(
30         get_interface<PPB_TCPServerSocket_Private_0_2>()->Create(
31             instance.pp_instance()));
32   } else if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
33     PassRefFromConstructor(
34         get_interface<PPB_TCPServerSocket_Private_0_1>()->Create(
35             instance.pp_instance()));
36   }
37 }
38 
39 // static
IsAvailable()40 bool TCPServerSocketPrivate::IsAvailable() {
41   return has_interface<PPB_TCPServerSocket_Private_0_2>() ||
42       has_interface<PPB_TCPServerSocket_Private_0_1>();
43 }
44 
Listen(const PP_NetAddress_Private * addr,int32_t backlog,const CompletionCallback & callback)45 int32_t TCPServerSocketPrivate::Listen(const PP_NetAddress_Private* addr,
46                                        int32_t backlog,
47                                        const CompletionCallback& callback) {
48   if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
49     return get_interface<PPB_TCPServerSocket_Private_0_2>()->Listen(
50         pp_resource(), addr, backlog, callback.pp_completion_callback());
51   }
52   if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
53     return get_interface<PPB_TCPServerSocket_Private_0_1>()->Listen(
54         pp_resource(), addr, backlog, callback.pp_completion_callback());
55   }
56   return callback.MayForce(PP_ERROR_NOINTERFACE);
57 }
58 
Accept(PP_Resource * tcp_socket,const CompletionCallback & callback)59 int32_t TCPServerSocketPrivate::Accept(PP_Resource* tcp_socket,
60                                        const CompletionCallback& callback) {
61   if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
62     return get_interface<PPB_TCPServerSocket_Private_0_2>()->Accept(
63         pp_resource(), tcp_socket, callback.pp_completion_callback());
64   }
65   if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
66     return get_interface<PPB_TCPServerSocket_Private_0_1>()->Accept(
67         pp_resource(), tcp_socket, callback.pp_completion_callback());
68   }
69   return callback.MayForce(PP_ERROR_NOINTERFACE);
70 }
71 
GetLocalAddress(PP_NetAddress_Private * addr)72 int32_t TCPServerSocketPrivate::GetLocalAddress(PP_NetAddress_Private* addr) {
73   if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
74     return get_interface<PPB_TCPServerSocket_Private_0_2>()->GetLocalAddress(
75         pp_resource(), addr);
76   }
77   return PP_ERROR_NOINTERFACE;
78 }
79 
StopListening()80 void TCPServerSocketPrivate::StopListening() {
81   if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
82     return get_interface<PPB_TCPServerSocket_Private_0_2>()->StopListening(
83         pp_resource());
84   }
85   if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
86     return get_interface<PPB_TCPServerSocket_Private_0_1>()->StopListening(
87         pp_resource());
88   }
89 }
90 
91 }  // namespace pp
92