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
), udp_socket_(this), factory_(this) {}
18 virtual ~MyInstance() {}
20 void DidBindUDPSocket(int32_t result
) {
21 // We should be able to bind the multicast socket with permission.
28 void DidSetOptionUDPSocket(int32_t result
) {
29 // We should be able to set the multicast option with permission.
30 if (result
!= PP_OK
) {
35 PP_NetAddress_IPv4 ipv4_address
= {80, {127, 0, 0, 1}};
36 pp::NetAddress
address(this, ipv4_address
);
37 udp_socket_
.Bind(address
,
38 factory_
.NewCallback(&MyInstance::DidBindUDPSocket
));
41 virtual bool Init(uint32_t argc
, const char* argn
[], const char* argv
[]) {
42 udp_socket_
.SetOption(
43 PP_UDPSOCKET_OPTION_MULTICAST_LOOP
, pp::Var(true),
44 factory_
.NewCallback(&MyInstance::DidSetOptionUDPSocket
));
49 pp::UDPSocket udp_socket_
;
50 pp::CompletionCallbackFactory
<MyInstance
> factory_
;
53 class MyModule
: public pp::Module
{
55 MyModule() : pp::Module() {}
56 virtual ~MyModule() {}
58 virtual pp::Instance
* CreateInstance(PP_Instance instance
) {
59 return new MyInstance(instance
);
67 Module
* CreateModule() {
68 return new MyModule();