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/utility/completion_callback_factory.h"
13 class MyInstance
: public pp::Instance
{
15 explicit MyInstance(PP_Instance instance
)
16 : pp::Instance(instance
), socket_(this), factory_(this) { }
17 virtual ~MyInstance() { }
19 void DidBindSocket(int32_t result
) {
26 virtual bool Init(uint32_t argc
, const char* argn
[], const char* argv
[]) {
27 PP_NetAddress_IPv4 ipv4_address
= {80, {127, 0, 0, 1} };
28 pp::NetAddress
address(this, ipv4_address
);
29 socket_
.Bind(address
, factory_
.NewCallback(&MyInstance::DidBindSocket
));
34 pp::TCPSocket socket_
;
35 pp::CompletionCallbackFactory
<MyInstance
> factory_
;
38 class MyModule
: public pp::Module
{
40 MyModule() : pp::Module() { }
41 virtual ~MyModule() { }
43 virtual pp::Instance
* CreateInstance(PP_Instance instance
) {
44 return new MyInstance(instance
);
52 Module
* CreateModule() {
53 return new MyModule();