diff options
author | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 09:45:14 +0000 |
---|---|---|
committer | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 09:45:14 +0000 |
commit | 4f9e7222c8086d1484d6002f5977c8774e86448f (patch) | |
tree | d7dd966c2c3754ef2c3d8a88793d6319c4a6bf8d /ppapi/cpp | |
parent | 18bcaed2ab84b5259f2e392a843a5ea5b5661043 (diff) | |
download | chromium_src-4f9e7222c8086d1484d6002f5977c8774e86448f.zip chromium_src-4f9e7222c8086d1484d6002f5977c8774e86448f.tar.gz chromium_src-4f9e7222c8086d1484d6002f5977c8774e86448f.tar.bz2 |
Added CPP wrapper for PPB_TCPServerSocket_Private.
BUG=
TEST=PPAPI(NaCl?)Test.TestTCPServerSocketPrivate
Review URL: http://codereview.chromium.org/9568007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/private/tcp_server_socket_private.cc | 59 | ||||
-rw-r--r-- | ppapi/cpp/private/tcp_server_socket_private.h | 38 | ||||
-rw-r--r-- | ppapi/cpp/private/tcp_socket_private.cc | 6 | ||||
-rw-r--r-- | ppapi/cpp/private/tcp_socket_private.h | 5 |
4 files changed, 106 insertions, 2 deletions
diff --git a/ppapi/cpp/private/tcp_server_socket_private.cc b/ppapi/cpp/private/tcp_server_socket_private.cc new file mode 100644 index 0000000..5f315bf --- /dev/null +++ b/ppapi/cpp/private/tcp_server_socket_private.cc @@ -0,0 +1,59 @@ +// 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<PPB_TCPServerSocket_Private>() { + return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE; +} + +} // namespace + +TCPServerSocketPrivate::TCPServerSocketPrivate(const InstanceHandle& instance) { + if (has_interface<PPB_TCPServerSocket_Private>()) { + PassRefFromConstructor(get_interface<PPB_TCPServerSocket_Private>()->Create( + instance.pp_instance())); + } +} + +// static +bool TCPServerSocketPrivate::IsAvailable() { + return has_interface<PPB_TCPServerSocket_Private>(); +} + +int32_t TCPServerSocketPrivate::Listen(const PP_NetAddress_Private* addr, + int32_t backlog, + const CompletionCallback& callback) { + if (!has_interface<PPB_TCPServerSocket_Private>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_TCPServerSocket_Private>()->Listen( + pp_resource(), addr, backlog, callback.pp_completion_callback()); +} + +int32_t TCPServerSocketPrivate::Accept(PP_Resource* tcp_socket, + const CompletionCallback& callback) { + if (!has_interface<PPB_TCPServerSocket_Private>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_TCPServerSocket_Private>()->Accept( + pp_resource(), tcp_socket, callback.pp_completion_callback()); +} + +void TCPServerSocketPrivate::StopListening() { + if (!has_interface<PPB_TCPServerSocket_Private>()) + return; + return get_interface<PPB_TCPServerSocket_Private>()->StopListening( + pp_resource()); +} + +} // namespace pp diff --git a/ppapi/cpp/private/tcp_server_socket_private.h b/ppapi/cpp/private/tcp_server_socket_private.h new file mode 100644 index 0000000..3d40cea --- /dev/null +++ b/ppapi/cpp/private/tcp_server_socket_private.h @@ -0,0 +1,38 @@ +// 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. + +#ifndef PPAPI_CPP_PRIVATE_TCP_SERVER_SOCKET_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_TCP_SERVER_SOCKET_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_tcp_server_socket_private.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class InstanceHandle; + +class TCPServerSocketPrivate : public Resource { + public: + explicit TCPServerSocketPrivate(const InstanceHandle& instance); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + int32_t Listen(const PP_NetAddress_Private* addr, + int32_t backlog, + const CompletionCallback& callback); + // Accepts incoming connection and stores resource of accepted + // socket into |socket|. If Accept returns PP_OK_COMPLETIONPENDING, + // the memory pointed by |socket| should stay valid until the + // |callback| is called or StopListening method is called. + int32_t Accept(PP_Resource* socket, + const CompletionCallback& callback); + void StopListening(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_TCP_SERVER_SOCKET_PRIVATE_H_ diff --git a/ppapi/cpp/private/tcp_socket_private.cc b/ppapi/cpp/private/tcp_socket_private.cc index 9e2c1f6..e15f537 100644 --- a/ppapi/cpp/private/tcp_socket_private.cc +++ b/ppapi/cpp/private/tcp_socket_private.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -28,6 +28,10 @@ TCPSocketPrivate::TCPSocketPrivate(const InstanceHandle& instance) { } } +TCPSocketPrivate::TCPSocketPrivate(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { +} + // static bool TCPSocketPrivate::IsAvailable() { return has_interface<PPB_TCPSocket_Private>(); diff --git a/ppapi/cpp/private/tcp_socket_private.h b/ppapi/cpp/private/tcp_socket_private.h index 415a1ed..839c7cf 100644 --- a/ppapi/cpp/private/tcp_socket_private.h +++ b/ppapi/cpp/private/tcp_socket_private.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -7,6 +7,7 @@ #include "ppapi/c/pp_stdint.h" #include "ppapi/c/private/ppb_tcp_socket_private.h" +#include "ppapi/cpp/pass_ref.h" #include "ppapi/cpp/resource.h" namespace pp { @@ -18,6 +19,8 @@ class TCPSocketPrivate : public Resource { public: explicit TCPSocketPrivate(const InstanceHandle& instance); + TCPSocketPrivate(PassRef, PP_Resource resource); + // Returns true if the required interface is available. static bool IsAvailable(); |