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.
5 #include "ppapi/cpp/private/tcp_server_socket_private.h"
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"
17 template <> const char* interface_name
<PPB_TCPServerSocket_Private_0_2
>() {
18 return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_2
;
21 template <> const char* interface_name
<PPB_TCPServerSocket_Private_0_1
>() {
22 return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_1
;
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()));
40 bool TCPServerSocketPrivate::IsAvailable() {
41 return has_interface
<PPB_TCPServerSocket_Private_0_2
>() ||
42 has_interface
<PPB_TCPServerSocket_Private_0_1
>();
45 int32_t TCPServerSocketPrivate::Listen(const PP_NetAddress_Private
* addr
,
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());
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());
56 return callback
.MayForce(PP_ERROR_NOINTERFACE
);
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());
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());
69 return callback
.MayForce(PP_ERROR_NOINTERFACE
);
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(
77 return PP_ERROR_NOINTERFACE
;
80 void TCPServerSocketPrivate::StopListening() {
81 if (has_interface
<PPB_TCPServerSocket_Private_0_2
>()) {
82 return get_interface
<PPB_TCPServerSocket_Private_0_2
>()->StopListening(
85 if (has_interface
<PPB_TCPServerSocket_Private_0_1
>()) {
86 return get_interface
<PPB_TCPServerSocket_Private_0_1
>()->StopListening(