1 // Copyright (c) 2013 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/extensions/dev/socket_dev.h"
6
7 #include "ppapi/cpp/completion_callback.h"
8 #include "ppapi/cpp/extensions/optional.h"
9 #include "ppapi/cpp/extensions/to_var_converter.h"
10 #include "ppapi/cpp/logging.h"
11 #include "ppapi/cpp/module_impl.h"
12
13 namespace pp {
14
15 namespace {
16
interface_name()17 template <> const char* interface_name<PPB_Ext_Socket_Dev_0_2>() {
18 return PPB_EXT_SOCKET_DEV_INTERFACE_0_2;
19 }
20
21 } // namespace
22
23 namespace ext {
24 namespace socket {
25
26 const char* const SocketType_Dev::kTcp = "tcp";
27 const char* const SocketType_Dev::kUdp = "udp";
28
SocketType_Dev()29 SocketType_Dev::SocketType_Dev() : value(NONE) {
30 }
31
SocketType_Dev(ValueType in_value)32 SocketType_Dev::SocketType_Dev(ValueType in_value) : value(in_value) {
33 }
34
~SocketType_Dev()35 SocketType_Dev::~SocketType_Dev() {
36 }
37
Populate(const PP_Var & var_value)38 bool SocketType_Dev::Populate(const PP_Var& var_value) {
39 if (var_value.type != PP_VARTYPE_STRING)
40 return false;
41
42 std::string string_value = Var(var_value).AsString();
43 if (string_value == kTcp) {
44 value = TCP;
45 } else if (string_value == kUdp) {
46 value = UDP;
47 } else {
48 value = NONE;
49 return false;
50 }
51 return true;
52 }
53
CreateVar() const54 Var SocketType_Dev::CreateVar() const {
55 switch (value) {
56 case TCP:
57 return Var(kTcp);
58 case UDP:
59 return Var(kUdp);
60 default:
61 PP_NOTREACHED();
62 return Var(std::string());
63 }
64 }
65
66 const char* const CreateInfo_Dev::kSocketId = "socketId";
67
CreateInfo_Dev()68 CreateInfo_Dev::CreateInfo_Dev()
69 : socket_id(kSocketId) {
70 }
71
~CreateInfo_Dev()72 CreateInfo_Dev::~CreateInfo_Dev() {
73 }
74
Populate(const PP_Ext_Socket_CreateInfo_Dev & value)75 bool CreateInfo_Dev::Populate(const PP_Ext_Socket_CreateInfo_Dev& value) {
76 if (value.type != PP_VARTYPE_DICTIONARY)
77 return false;
78
79 VarDictionary dict(value);
80 bool result = socket_id.Populate(dict);
81
82 return result;
83 }
84
CreateVar() const85 Var CreateInfo_Dev::CreateVar() const {
86 VarDictionary dict;
87
88 bool result = socket_id.AddTo(&dict);
89 // Suppress unused variable warnings.
90 static_cast<void>(result);
91 PP_DCHECK(result);
92
93 return dict;
94 }
95
96 const char* const AcceptInfo_Dev::kResultCode = "resultCode";
97 const char* const AcceptInfo_Dev::kSocketId = "socketId";
98
AcceptInfo_Dev()99 AcceptInfo_Dev::AcceptInfo_Dev()
100 : result_code(kResultCode),
101 socket_id(kSocketId) {
102 }
103
~AcceptInfo_Dev()104 AcceptInfo_Dev::~AcceptInfo_Dev() {
105 }
106
Populate(const PP_Ext_Socket_AcceptInfo_Dev & value)107 bool AcceptInfo_Dev::Populate(const PP_Ext_Socket_AcceptInfo_Dev& value) {
108 if (value.type != PP_VARTYPE_DICTIONARY)
109 return false;
110
111 VarDictionary dict(value);
112 bool result = result_code.Populate(dict);
113 result = socket_id.Populate(dict) && result;
114
115 return result;
116 }
117
CreateVar() const118 Var AcceptInfo_Dev::CreateVar() const {
119 VarDictionary dict;
120
121 bool result = result_code.AddTo(&dict);
122 result = socket_id.MayAddTo(&dict) && result;
123 PP_DCHECK(result);
124
125 return dict;
126 }
127
128 const char* const ReadInfo_Dev::kResultCode = "resultCode";
129 const char* const ReadInfo_Dev::kData = "data";
130
ReadInfo_Dev()131 ReadInfo_Dev::ReadInfo_Dev()
132 : result_code(kResultCode),
133 data(kData) {
134 }
135
~ReadInfo_Dev()136 ReadInfo_Dev::~ReadInfo_Dev() {
137 }
138
Populate(const PP_Ext_Socket_ReadInfo_Dev & value)139 bool ReadInfo_Dev::Populate(const PP_Ext_Socket_ReadInfo_Dev& value) {
140 if (value.type != PP_VARTYPE_DICTIONARY)
141 return false;
142
143 VarDictionary dict(value);
144 bool result = result_code.Populate(dict);
145 result = data.Populate(dict) && result;
146
147 return result;
148 }
149
CreateVar() const150 Var ReadInfo_Dev::CreateVar() const {
151 VarDictionary dict;
152
153 bool result = result_code.AddTo(&dict);
154 result = data.AddTo(&dict) && result;
155 PP_DCHECK(result);
156
157 return dict;
158 }
159
160 const char* const WriteInfo_Dev::kBytesWritten = "bytesWritten";
161
WriteInfo_Dev()162 WriteInfo_Dev::WriteInfo_Dev()
163 : bytes_written(kBytesWritten) {
164 }
165
~WriteInfo_Dev()166 WriteInfo_Dev::~WriteInfo_Dev() {
167 }
168
Populate(const PP_Ext_Socket_WriteInfo_Dev & value)169 bool WriteInfo_Dev::Populate(const PP_Ext_Socket_WriteInfo_Dev& value) {
170 if (value.type != PP_VARTYPE_DICTIONARY)
171 return false;
172
173 VarDictionary dict(value);
174 bool result = bytes_written.Populate(dict);
175
176 return result;
177 }
178
CreateVar() const179 Var WriteInfo_Dev::CreateVar() const {
180 VarDictionary dict;
181
182 bool result = bytes_written.AddTo(&dict);
183 // Suppress unused variable warnings.
184 static_cast<void>(result);
185 PP_DCHECK(result);
186
187 return dict;
188 }
189
190 const char* const RecvFromInfo_Dev::kResultCode = "resultCode";
191 const char* const RecvFromInfo_Dev::kData = "data";
192 const char* const RecvFromInfo_Dev::kAddress = "address";
193 const char* const RecvFromInfo_Dev::kPort = "port";
194
RecvFromInfo_Dev()195 RecvFromInfo_Dev::RecvFromInfo_Dev()
196 : result_code(kResultCode),
197 data(kData),
198 address(kAddress),
199 port(kPort) {
200 }
201
~RecvFromInfo_Dev()202 RecvFromInfo_Dev::~RecvFromInfo_Dev() {
203 }
204
Populate(const PP_Ext_Socket_RecvFromInfo_Dev & value)205 bool RecvFromInfo_Dev::Populate(const PP_Ext_Socket_RecvFromInfo_Dev& value) {
206 if (value.type != PP_VARTYPE_DICTIONARY)
207 return false;
208
209 VarDictionary dict(value);
210 bool result = result_code.Populate(dict);
211 result = data.Populate(dict) && result;
212 result = address.Populate(dict) && result;
213 result = port.Populate(dict) && result;
214
215 return result;
216 }
217
CreateVar() const218 Var RecvFromInfo_Dev::CreateVar() const {
219 VarDictionary dict;
220
221 bool result = result_code.AddTo(&dict);
222 result = data.AddTo(&dict) && result;
223 result = address.AddTo(&dict) && result;
224 result = port.AddTo(&dict) && result;
225 PP_DCHECK(result);
226
227 return dict;
228 }
229
230 const char* const SocketInfo_Dev::kSocketType = "socketType";
231 const char* const SocketInfo_Dev::kConnected = "connected";
232 const char* const SocketInfo_Dev::kPeerAddress = "peerAddress";
233 const char* const SocketInfo_Dev::kPeerPort = "peerPort";
234 const char* const SocketInfo_Dev::kLocalAddress = "localAddress";
235 const char* const SocketInfo_Dev::kLocalPort = "localPort";
236
SocketInfo_Dev()237 SocketInfo_Dev::SocketInfo_Dev()
238 : socket_type(kSocketType),
239 connected(kConnected),
240 peer_address(kPeerAddress),
241 peer_port(kPeerPort),
242 local_address(kLocalAddress),
243 local_port(kLocalPort) {
244 }
245
~SocketInfo_Dev()246 SocketInfo_Dev::~SocketInfo_Dev() {
247 }
248
Populate(const PP_Ext_Socket_SocketInfo_Dev & value)249 bool SocketInfo_Dev::Populate(const PP_Ext_Socket_SocketInfo_Dev& value) {
250 if (value.type != PP_VARTYPE_DICTIONARY)
251 return false;
252
253 VarDictionary dict(value);
254 bool result = socket_type.Populate(dict);
255 result = connected.Populate(dict) && result;
256 result = peer_address.Populate(dict) && result;
257 result = peer_port.Populate(dict) && result;
258 result = local_address.Populate(dict) && result;
259 result = local_port.Populate(dict) && result;
260
261 return result;
262 }
263
CreateVar() const264 Var SocketInfo_Dev::CreateVar() const {
265 VarDictionary dict;
266
267 bool result = socket_type.AddTo(&dict);
268 result = connected.AddTo(&dict) && result;
269 result = peer_address.MayAddTo(&dict) && result;
270 result = peer_port.MayAddTo(&dict) && result;
271 result = local_address.MayAddTo(&dict) && result;
272 result = local_port.MayAddTo(&dict) && result;
273 PP_DCHECK(result);
274
275 return dict;
276 }
277
278 const char* const NetworkInterface_Dev::kName = "name";
279 const char* const NetworkInterface_Dev::kAddress = "address";
280
NetworkInterface_Dev()281 NetworkInterface_Dev::NetworkInterface_Dev()
282 : name(kName),
283 address(kAddress) {
284 }
285
~NetworkInterface_Dev()286 NetworkInterface_Dev::~NetworkInterface_Dev() {
287 }
288
Populate(const PP_Ext_Socket_NetworkInterface_Dev & value)289 bool NetworkInterface_Dev::Populate(
290 const PP_Ext_Socket_NetworkInterface_Dev& value) {
291 if (value.type != PP_VARTYPE_DICTIONARY)
292 return false;
293
294 VarDictionary dict(value);
295 bool result = name.Populate(dict);
296 result = address.Populate(dict) && result;
297
298 return result;
299 }
300
CreateVar() const301 Var NetworkInterface_Dev::CreateVar() const {
302 VarDictionary dict;
303
304 bool result = name.AddTo(&dict);
305 result = address.AddTo(&dict) && result;
306 PP_DCHECK(result);
307
308 return dict;
309 }
310
Socket_Dev(const InstanceHandle & instance)311 Socket_Dev::Socket_Dev(const InstanceHandle& instance) : instance_(instance) {
312 }
313
~Socket_Dev()314 Socket_Dev::~Socket_Dev() {
315 }
316
Create(const SocketType_Dev & type,const Optional<CreateOptions_Dev> & options,const CreateCallback & callback)317 int32_t Socket_Dev::Create(const SocketType_Dev& type,
318 const Optional<CreateOptions_Dev>& options,
319 const CreateCallback& callback) {
320 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
321 return callback.MayForce(PP_ERROR_NOINTERFACE);
322
323 internal::ToVarConverter<SocketType_Dev> type_var(type);
324 internal::ToVarConverter<Optional<CreateOptions_Dev> > options_var(options);
325
326 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Create(
327 instance_.pp_instance(),
328 type_var.pp_var(),
329 options_var.pp_var(),
330 callback.output(),
331 callback.pp_completion_callback());
332 }
333
Destroy(int32_t socket_id)334 void Socket_Dev::Destroy(int32_t socket_id) {
335 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
336 return;
337
338 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
339
340 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Destroy(
341 instance_.pp_instance(),
342 socket_id_var.pp_var());
343 }
344
Connect(int32_t socket_id,const std::string & hostname,int32_t port,const ConnectCallback & callback)345 int32_t Socket_Dev::Connect(int32_t socket_id,
346 const std::string& hostname,
347 int32_t port,
348 const ConnectCallback& callback) {
349 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
350 return callback.MayForce(PP_ERROR_NOINTERFACE);
351
352 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
353 internal::ToVarConverter<std::string> hostname_var(hostname);
354 internal::ToVarConverter<int32_t> port_var(port);
355
356 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Connect(
357 instance_.pp_instance(),
358 socket_id_var.pp_var(),
359 hostname_var.pp_var(),
360 port_var.pp_var(),
361 callback.output(),
362 callback.pp_completion_callback());
363 }
364
Bind(int32_t socket_id,const std::string & address,int32_t port,const BindCallback & callback)365 int32_t Socket_Dev::Bind(int32_t socket_id,
366 const std::string& address,
367 int32_t port,
368 const BindCallback& callback) {
369 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
370 return callback.MayForce(PP_ERROR_NOINTERFACE);
371
372 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
373 internal::ToVarConverter<std::string> address_var(address);
374 internal::ToVarConverter<int32_t> port_var(port);
375
376 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Bind(
377 instance_.pp_instance(),
378 socket_id_var.pp_var(),
379 address_var.pp_var(),
380 port_var.pp_var(),
381 callback.output(),
382 callback.pp_completion_callback());
383 }
384
Disconnect(int32_t socket_id)385 void Socket_Dev::Disconnect(int32_t socket_id) {
386 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
387 return;
388
389 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
390
391 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Disconnect(
392 instance_.pp_instance(),
393 socket_id_var.pp_var());
394 }
395
Read(int32_t socket_id,const Optional<int32_t> & buffer_size,const ReadCallback & callback)396 int32_t Socket_Dev::Read(int32_t socket_id,
397 const Optional<int32_t>& buffer_size,
398 const ReadCallback& callback) {
399 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
400 return callback.MayForce(PP_ERROR_NOINTERFACE);
401
402 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
403 internal::ToVarConverter<Optional<int32_t> > buffer_size_var(buffer_size);
404
405 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Read(
406 instance_.pp_instance(),
407 socket_id_var.pp_var(),
408 buffer_size_var.pp_var(),
409 callback.output(),
410 callback.pp_completion_callback());
411 }
412
Write(int32_t socket_id,const VarArrayBuffer & data,const WriteCallback & callback)413 int32_t Socket_Dev::Write(int32_t socket_id,
414 const VarArrayBuffer& data,
415 const WriteCallback& callback) {
416 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
417 return callback.MayForce(PP_ERROR_NOINTERFACE);
418
419 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
420 internal::ToVarConverter<Var> data_var(data);
421
422 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Write(
423 instance_.pp_instance(),
424 socket_id_var.pp_var(),
425 data_var.pp_var(),
426 callback.output(),
427 callback.pp_completion_callback());
428 }
429
RecvFrom(int32_t socket_id,const Optional<int32_t> & buffer_size,const RecvFromCallback & callback)430 int32_t Socket_Dev::RecvFrom(int32_t socket_id,
431 const Optional<int32_t>& buffer_size,
432 const RecvFromCallback& callback) {
433 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
434 return callback.MayForce(PP_ERROR_NOINTERFACE);
435
436 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
437 internal::ToVarConverter<Optional<int32_t> > buffer_size_var(buffer_size);
438
439 return get_interface<PPB_Ext_Socket_Dev_0_2>()->RecvFrom(
440 instance_.pp_instance(),
441 socket_id_var.pp_var(),
442 buffer_size_var.pp_var(),
443 callback.output(),
444 callback.pp_completion_callback());
445 }
446
SendTo(int32_t socket_id,const VarArrayBuffer & data,const std::string & address,int32_t port,const SendToCallback & callback)447 int32_t Socket_Dev::SendTo(int32_t socket_id,
448 const VarArrayBuffer& data,
449 const std::string& address,
450 int32_t port,
451 const SendToCallback& callback) {
452 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
453 return callback.MayForce(PP_ERROR_NOINTERFACE);
454
455 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
456 internal::ToVarConverter<Var> data_var(data);
457 internal::ToVarConverter<std::string> address_var(address);
458 internal::ToVarConverter<int32_t> port_var(port);
459
460 return get_interface<PPB_Ext_Socket_Dev_0_2>()->SendTo(
461 instance_.pp_instance(),
462 socket_id_var.pp_var(),
463 data_var.pp_var(),
464 address_var.pp_var(),
465 port_var.pp_var(),
466 callback.output(),
467 callback.pp_completion_callback());
468 }
469
Listen(int32_t socket_id,const std::string & address,int32_t port,const Optional<int32_t> & backlog,const ListenCallback & callback)470 int32_t Socket_Dev::Listen(int32_t socket_id,
471 const std::string& address,
472 int32_t port,
473 const Optional<int32_t>& backlog,
474 const ListenCallback& callback) {
475 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
476 return callback.MayForce(PP_ERROR_NOINTERFACE);
477
478 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
479 internal::ToVarConverter<std::string> address_var(address);
480 internal::ToVarConverter<int32_t> port_var(port);
481 internal::ToVarConverter<Optional<int32_t> > backlog_var(backlog);
482
483 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Listen(
484 instance_.pp_instance(),
485 socket_id_var.pp_var(),
486 address_var.pp_var(),
487 port_var.pp_var(),
488 backlog_var.pp_var(),
489 callback.output(),
490 callback.pp_completion_callback());
491 }
492
Accept(int32_t socket_id,const AcceptCallback & callback)493 int32_t Socket_Dev::Accept(int32_t socket_id,
494 const AcceptCallback& callback) {
495 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
496 return callback.MayForce(PP_ERROR_NOINTERFACE);
497
498 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
499
500 return get_interface<PPB_Ext_Socket_Dev_0_2>()->Accept(
501 instance_.pp_instance(),
502 socket_id_var.pp_var(),
503 callback.output(),
504 callback.pp_completion_callback());
505 }
506
SetKeepAlive(int32_t socket_id,bool enable,const Optional<int32_t> & delay,const SetKeepAliveCallback & callback)507 int32_t Socket_Dev::SetKeepAlive(int32_t socket_id,
508 bool enable,
509 const Optional<int32_t>& delay,
510 const SetKeepAliveCallback& callback) {
511 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
512 return callback.MayForce(PP_ERROR_NOINTERFACE);
513
514 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
515 internal::ToVarConverter<bool> enable_var(enable);
516 internal::ToVarConverter<Optional<int32_t> > delay_var(delay);
517
518 return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetKeepAlive(
519 instance_.pp_instance(),
520 socket_id_var.pp_var(),
521 enable_var.pp_var(),
522 delay_var.pp_var(),
523 callback.output(),
524 callback.pp_completion_callback());
525 }
526
SetNoDelay(int32_t socket_id,bool no_delay,const SetNoDelayCallback & callback)527 int32_t Socket_Dev::SetNoDelay(int32_t socket_id,
528 bool no_delay,
529 const SetNoDelayCallback& callback) {
530 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
531 return callback.MayForce(PP_ERROR_NOINTERFACE);
532
533 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
534 internal::ToVarConverter<bool> no_delay_var(no_delay);
535
536 return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetNoDelay(
537 instance_.pp_instance(),
538 socket_id_var.pp_var(),
539 no_delay_var.pp_var(),
540 callback.output(),
541 callback.pp_completion_callback());
542 }
543
GetInfo(int32_t socket_id,const GetInfoCallback & callback)544 int32_t Socket_Dev::GetInfo(int32_t socket_id,
545 const GetInfoCallback& callback) {
546 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
547 return callback.MayForce(PP_ERROR_NOINTERFACE);
548
549 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
550
551 return get_interface<PPB_Ext_Socket_Dev_0_2>()->GetInfo(
552 instance_.pp_instance(),
553 socket_id_var.pp_var(),
554 callback.output(),
555 callback.pp_completion_callback());
556 }
557
GetNetworkList(const GetNetworkListCallback & callback)558 int32_t Socket_Dev::GetNetworkList(const GetNetworkListCallback& callback) {
559 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
560 return callback.MayForce(PP_ERROR_NOINTERFACE);
561
562 return get_interface<PPB_Ext_Socket_Dev_0_2>()->GetNetworkList(
563 instance_.pp_instance(),
564 callback.output(),
565 callback.pp_completion_callback());
566 }
567
JoinGroup(int32_t socket_id,const std::string & address,const JoinGroupCallback & callback)568 int32_t Socket_Dev::JoinGroup(int32_t socket_id,
569 const std::string& address,
570 const JoinGroupCallback& callback) {
571 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
572 return callback.MayForce(PP_ERROR_NOINTERFACE);
573
574 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
575 internal::ToVarConverter<std::string> address_var(address);
576
577 return get_interface<PPB_Ext_Socket_Dev_0_2>()->JoinGroup(
578 instance_.pp_instance(),
579 socket_id_var.pp_var(),
580 address_var.pp_var(),
581 callback.output(),
582 callback.pp_completion_callback());
583 }
584
LeaveGroup(int32_t socket_id,const std::string & address,const LeaveGroupCallback & callback)585 int32_t Socket_Dev::LeaveGroup(int32_t socket_id,
586 const std::string& address,
587 const LeaveGroupCallback& callback) {
588 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
589 return callback.MayForce(PP_ERROR_NOINTERFACE);
590
591 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
592 internal::ToVarConverter<std::string> address_var(address);
593
594 return get_interface<PPB_Ext_Socket_Dev_0_2>()->LeaveGroup(
595 instance_.pp_instance(),
596 socket_id_var.pp_var(),
597 address_var.pp_var(),
598 callback.output(),
599 callback.pp_completion_callback());
600 }
601
SetMulticastTimeToLive(int32_t socket_id,int32_t ttl,const SetMulticastTimeToLiveCallback & callback)602 int32_t Socket_Dev::SetMulticastTimeToLive(
603 int32_t socket_id,
604 int32_t ttl,
605 const SetMulticastTimeToLiveCallback& callback) {
606 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
607 return callback.MayForce(PP_ERROR_NOINTERFACE);
608
609 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
610 internal::ToVarConverter<int32_t> ttl_var(ttl);
611
612 return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetMulticastTimeToLive(
613 instance_.pp_instance(),
614 socket_id_var.pp_var(),
615 ttl_var.pp_var(),
616 callback.output(),
617 callback.pp_completion_callback());
618 }
619
SetMulticastLoopbackMode(int32_t socket_id,bool enabled,const SetMulticastLoopbackModeCallback & callback)620 int32_t Socket_Dev::SetMulticastLoopbackMode(
621 int32_t socket_id,
622 bool enabled,
623 const SetMulticastLoopbackModeCallback& callback) {
624 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
625 return callback.MayForce(PP_ERROR_NOINTERFACE);
626
627 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
628 internal::ToVarConverter<bool> enabled_var(enabled);
629
630 return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetMulticastLoopbackMode(
631 instance_.pp_instance(),
632 socket_id_var.pp_var(),
633 enabled_var.pp_var(),
634 callback.output(),
635 callback.pp_completion_callback());
636 }
637
GetJoinedGroups(int32_t socket_id,const GetJoinedGroupsCallback & callback)638 int32_t Socket_Dev::GetJoinedGroups(int32_t socket_id,
639 const GetJoinedGroupsCallback& callback) {
640 if (!has_interface<PPB_Ext_Socket_Dev_0_2>())
641 return callback.MayForce(PP_ERROR_NOINTERFACE);
642
643 internal::ToVarConverter<int32_t> socket_id_var(socket_id);
644
645 return get_interface<PPB_Ext_Socket_Dev_0_2>()->GetJoinedGroups(
646 instance_.pp_instance(),
647 socket_id_var.pp_var(),
648 callback.output(),
649 callback.pp_completion_callback());
650 }
651
652 } // namespace socket
653 } // namespace ext
654 } // namespace pp
655