1 // Copyright 2015 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/completion_callback.h"
6 #include "ppapi/cpp/instance.h"
7 #include "ppapi/cpp/module.h"
8 #include "ppapi/cpp/tcp_socket.h"
9 #include "ppapi/cpp/udp_socket.h"
10 #include "ppapi/utility/completion_callback_factory.h"
14 class MyInstance
: public pp::Instance
{
16 explicit MyInstance(PP_Instance instance
)
17 : pp::Instance(instance
),
21 virtual ~MyInstance() {}
23 void DidBindTCPSocket(int32_t result
) {
24 // We should not be able to bind the TCP socket without permission.
25 if (result
== PP_OK
) {
29 PP_NetAddress_IPv4 ipv4_address
= {80, {127, 0, 0, 1}};
30 pp::NetAddress
address(this, ipv4_address
);
31 udp_socket_
.Bind(address
,
32 factory_
.NewCallback(&MyInstance::DidBindUDPSocket
));
35 void DidBindUDPSocket(int32_t result
) {
36 // We should not be able to bind the UDP socket without permission.
43 virtual bool Init(uint32_t argc
, const char* argn
[], const char* argv
[]) {
44 PP_NetAddress_IPv4 ipv4_address
= {80, {127, 0, 0, 1}};
45 pp::NetAddress
address(this, ipv4_address
);
46 tcp_socket_
.Bind(address
,
47 factory_
.NewCallback(&MyInstance::DidBindTCPSocket
));
52 pp::TCPSocket tcp_socket_
;
53 pp::UDPSocket udp_socket_
;
54 pp::CompletionCallbackFactory
<MyInstance
> factory_
;
57 class MyModule
: public pp::Module
{
59 MyModule() : pp::Module() {}
60 virtual ~MyModule() {}
62 virtual pp::Instance
* CreateInstance(PP_Instance instance
) {
63 return new MyInstance(instance
);
71 Module
* CreateModule() {
72 return new MyModule();