| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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_socket_private.h" |
| 6 |
| 7 #include "ppapi/c/pp_bool.h" |
| 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/instance.h" |
| 11 #include "ppapi/cpp/module.h" |
| 12 #include "ppapi/cpp/module_impl.h" |
| 13 |
| 14 namespace pp { |
| 15 |
| 16 namespace { |
| 17 |
| 18 template <> const char* interface_name<PPB_TCPSocket_Private>() { |
| 19 return PPB_TCPSOCKET_PRIVATE_INTERFACE; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 TCPSocketPrivate::TCPSocketPrivate(Instance* instance) { |
| 25 if (has_interface<PPB_TCPSocket_Private>() && instance) { |
| 26 PassRefFromConstructor(get_interface<PPB_TCPSocket_Private>()->Create( |
| 27 instance->pp_instance())); |
| 28 } |
| 29 } |
| 30 |
| 31 int32_t TCPSocketPrivate::Connect(const char* host, |
| 32 uint16_t port, |
| 33 const CompletionCallback& callback) { |
| 34 if (!has_interface<PPB_TCPSocket_Private>()) |
| 35 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 36 return get_interface<PPB_TCPSocket_Private>()->Connect( |
| 37 pp_resource(), host, port, callback.pp_completion_callback()); |
| 38 } |
| 39 |
| 40 int32_t TCPSocketPrivate::ConnectWithNetAddress( |
| 41 const PP_NetAddress_Private* addr, |
| 42 const CompletionCallback& callback) { |
| 43 if (!has_interface<PPB_TCPSocket_Private>()) |
| 44 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 45 return get_interface<PPB_TCPSocket_Private>()->ConnectWithNetAddress( |
| 46 pp_resource(), addr, callback.pp_completion_callback()); |
| 47 } |
| 48 |
| 49 bool TCPSocketPrivate::GetLocalAddress(PP_NetAddress_Private* local_addr) { |
| 50 if (!has_interface<PPB_TCPSocket_Private>()) |
| 51 return false; |
| 52 |
| 53 PP_Bool result = get_interface<PPB_TCPSocket_Private>()->GetLocalAddress( |
| 54 pp_resource(), local_addr); |
| 55 return PP_ToBool(result); |
| 56 } |
| 57 |
| 58 bool TCPSocketPrivate::GetRemoteAddress(PP_NetAddress_Private* remote_addr) { |
| 59 if (!has_interface<PPB_TCPSocket_Private>()) |
| 60 return false; |
| 61 PP_Bool result = get_interface<PPB_TCPSocket_Private>()->GetRemoteAddress( |
| 62 pp_resource(), remote_addr); |
| 63 return PP_ToBool(result); |
| 64 } |
| 65 |
| 66 int32_t TCPSocketPrivate::SSLHandshake(const char* server_name, |
| 67 uint16_t server_port, |
| 68 const CompletionCallback& callback) { |
| 69 if (!has_interface<PPB_TCPSocket_Private>()) |
| 70 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 71 return get_interface<PPB_TCPSocket_Private>()->SSLHandshake( |
| 72 pp_resource(), server_name, server_port, |
| 73 callback.pp_completion_callback()); |
| 74 } |
| 75 |
| 76 int32_t TCPSocketPrivate::Read(char* buffer, |
| 77 int32_t bytes_to_read, |
| 78 const CompletionCallback& callback) { |
| 79 if (!has_interface<PPB_TCPSocket_Private>()) |
| 80 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 81 return get_interface<PPB_TCPSocket_Private>()->Read( |
| 82 pp_resource(), buffer, bytes_to_read, callback.pp_completion_callback()); |
| 83 } |
| 84 |
| 85 int32_t TCPSocketPrivate::Write(const char* buffer, |
| 86 int32_t bytes_to_write, |
| 87 const CompletionCallback& callback) { |
| 88 if (!has_interface<PPB_TCPSocket_Private>()) |
| 89 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 90 return get_interface<PPB_TCPSocket_Private>()->Write( |
| 91 pp_resource(), buffer, bytes_to_write, callback.pp_completion_callback()); |
| 92 } |
| 93 |
| 94 void TCPSocketPrivate::Disconnect() { |
| 95 if (!has_interface<PPB_TCPSocket_Private>()) |
| 96 return; |
| 97 return get_interface<PPB_TCPSocket_Private>()->Disconnect(pp_resource()); |
| 98 } |
| 99 |
| 100 } // namespace pp |
| OLD | NEW |