Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1295)

Side by Side Diff: ppapi/proxy/udp_socket_resource_base.cc

Issue 704133005: Pepper: Add support for multicast in PPB_UDPSocket API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests, thunk code auto generated Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/udp_socket_resource_base.h" 5 #include "ppapi/proxy/udp_socket_resource_base.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 62
63 int32_t UDPSocketResourceBase::SetOptionImpl( 63 int32_t UDPSocketResourceBase::SetOptionImpl(
64 PP_UDPSocket_Option name, 64 PP_UDPSocket_Option name,
65 const PP_Var& value, 65 const PP_Var& value,
66 bool check_bind_state, 66 bool check_bind_state,
67 scoped_refptr<TrackedCallback> callback) { 67 scoped_refptr<TrackedCallback> callback) {
68 if (closed_) 68 if (closed_)
69 return PP_ERROR_FAILED; 69 return PP_ERROR_FAILED;
70 70
71 SocketOptionData option_data; 71 // Check if socket is expected to be bound or not according to the option.
72 switch (name) { 72 switch (name) {
73 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: 73 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE:
74 case PP_UDPSOCKET_OPTION_BROADCAST: { 74 case PP_UDPSOCKET_OPTION_BROADCAST:
75 case PP_UDPSOCKET_OPTION_MULTICAST_LOOP:
76 case PP_UDPSOCKET_OPTION_MULTICAST_TTL: {
75 if ((check_bind_state || name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) && 77 if ((check_bind_state || name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) &&
76 bind_called_) { 78 bind_called_) {
77 // SetOption should fail in this case in order to give predictable 79 // SetOption should fail in this case in order to give predictable
78 // behavior while binding. Note that we use |bind_called_| rather 80 // behavior while binding. Note that we use |bind_called_| rather
79 // than |bound_| since the latter is only set on successful completion 81 // than |bound_| since the latter is only set on successful completion
80 // of Bind(). 82 // of Bind().
81 return PP_ERROR_FAILED; 83 return PP_ERROR_FAILED;
82 } 84 }
85 break;
86 }
87 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE:
88 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: {
89 if (check_bind_state && !bound_)
90 return PP_ERROR_FAILED;
91 break;
92 }
93 }
94
95 SocketOptionData option_data;
96 switch (name) {
97 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE:
98 case PP_UDPSOCKET_OPTION_BROADCAST:
99 case PP_UDPSOCKET_OPTION_MULTICAST_LOOP: {
83 if (value.type != PP_VARTYPE_BOOL) 100 if (value.type != PP_VARTYPE_BOOL)
84 return PP_ERROR_BADARGUMENT; 101 return PP_ERROR_BADARGUMENT;
85 option_data.SetBool(PP_ToBool(value.value.as_bool)); 102 option_data.SetBool(PP_ToBool(value.value.as_bool));
86 break; 103 break;
87 } 104 }
88 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: 105 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE:
89 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { 106 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: {
90 if (check_bind_state && !bound_)
91 return PP_ERROR_FAILED;
92 if (value.type != PP_VARTYPE_INT32) 107 if (value.type != PP_VARTYPE_INT32)
93 return PP_ERROR_BADARGUMENT; 108 return PP_ERROR_BADARGUMENT;
94 option_data.SetInt32(value.value.as_int); 109 option_data.SetInt32(value.value.as_int);
95 break; 110 break;
96 } 111 }
112 case PP_UDPSOCKET_OPTION_MULTICAST_TTL: {
113 int32_t ival = value.value.as_int;
114 if (value.type != PP_VARTYPE_INT32 && (ival < 0 || ival > 255))
115 return PP_ERROR_BADARGUMENT;
116 option_data.SetInt32(ival);
117 break;
118 }
97 default: { 119 default: {
98 NOTREACHED(); 120 NOTREACHED();
99 return PP_ERROR_BADARGUMENT; 121 return PP_ERROR_BADARGUMENT;
100 } 122 }
101 } 123 }
102 124
103 Call<PpapiPluginMsg_UDPSocket_SetOptionReply>( 125 Call<PpapiPluginMsg_UDPSocket_SetOptionReply>(
104 BROWSER, 126 BROWSER,
105 PpapiHostMsg_UDPSocket_SetOption(name, option_data), 127 PpapiHostMsg_UDPSocket_SetOption(name, option_data),
106 base::Bind(&UDPSocketResourceBase::OnPluginMsgSetOptionReply, 128 base::Bind(&UDPSocketResourceBase::OnPluginMsgGeneralReply,
107 base::Unretained(this), 129 base::Unretained(this),
108 callback), 130 callback),
109 callback); 131 callback);
110 return PP_OK_COMPLETIONPENDING; 132 return PP_OK_COMPLETIONPENDING;
111 } 133 }
112 134
113 int32_t UDPSocketResourceBase::BindImpl( 135 int32_t UDPSocketResourceBase::BindImpl(
114 const PP_NetAddress_Private* addr, 136 const PP_NetAddress_Private* addr,
115 scoped_refptr<TrackedCallback> callback) { 137 scoped_refptr<TrackedCallback> callback) {
116 if (!addr) 138 if (!addr)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 while (!sendto_callbacks_.empty()) { 248 while (!sendto_callbacks_.empty()) {
227 scoped_refptr<TrackedCallback> callback = sendto_callbacks_.front(); 249 scoped_refptr<TrackedCallback> callback = sendto_callbacks_.front();
228 sendto_callbacks_.pop(); 250 sendto_callbacks_.pop();
229 PostAbortIfNecessary(&callback); 251 PostAbortIfNecessary(&callback);
230 } 252 }
231 253
232 read_buffer_ = NULL; 254 read_buffer_ = NULL;
233 bytes_to_read_ = -1; 255 bytes_to_read_ = -1;
234 } 256 }
235 257
258 int32_t UDPSocketResourceBase::JoinGroupImpl(
259 const PP_NetAddress_Private *group,
260 scoped_refptr<TrackedCallback> callback) {
261 DCHECK(group);
262
263 Call<PpapiPluginMsg_UDPSocket_JoinGroupReply>(
264 BROWSER,
265 PpapiHostMsg_UDPSocket_JoinGroup(*group),
266 base::Bind(&UDPSocketResourceBase::OnPluginMsgGeneralReply,
267 base::Unretained(this),
268 callback),
269 callback);
270 return PP_OK_COMPLETIONPENDING;
271 }
272
273 int32_t UDPSocketResourceBase::LeaveGroupImpl(
274 const PP_NetAddress_Private *group,
275 scoped_refptr<TrackedCallback> callback) {
276 DCHECK(group);
277
278 Call<PpapiPluginMsg_UDPSocket_LeaveGroupReply>(
279 BROWSER,
280 PpapiHostMsg_UDPSocket_LeaveGroup(*group),
281 base::Bind(&UDPSocketResourceBase::OnPluginMsgGeneralReply,
282 base::Unretained(this),
283 callback),
284 callback);
285 return PP_OK_COMPLETIONPENDING;
286 }
287
236 void UDPSocketResourceBase::OnReplyReceived( 288 void UDPSocketResourceBase::OnReplyReceived(
237 const ResourceMessageReplyParams& params, 289 const ResourceMessageReplyParams& params,
238 const IPC::Message& msg) { 290 const IPC::Message& msg) {
239 PPAPI_BEGIN_MESSAGE_MAP(UDPSocketResourceBase, msg) 291 PPAPI_BEGIN_MESSAGE_MAP(UDPSocketResourceBase, msg)
240 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( 292 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
241 PpapiPluginMsg_UDPSocket_PushRecvResult, 293 PpapiPluginMsg_UDPSocket_PushRecvResult,
242 OnPluginMsgPushRecvResult) 294 OnPluginMsgPushRecvResult)
243 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( 295 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
244 PluginResource::OnReplyReceived(params, msg)) 296 PluginResource::OnReplyReceived(params, msg))
245 PPAPI_END_MESSAGE_MAP() 297 PPAPI_END_MESSAGE_MAP()
246 } 298 }
247 299
248 void UDPSocketResourceBase::PostAbortIfNecessary( 300 void UDPSocketResourceBase::PostAbortIfNecessary(
249 scoped_refptr<TrackedCallback>* callback) { 301 scoped_refptr<TrackedCallback>* callback) {
250 if (TrackedCallback::IsPending(*callback)) 302 if (TrackedCallback::IsPending(*callback))
251 (*callback)->PostAbort(); 303 (*callback)->PostAbort();
252 } 304 }
253 305
254 void UDPSocketResourceBase::OnPluginMsgSetOptionReply( 306 void UDPSocketResourceBase::OnPluginMsgGeneralReply(
255 scoped_refptr<TrackedCallback> callback, 307 scoped_refptr<TrackedCallback> callback,
256 const ResourceMessageReplyParams& params) { 308 const ResourceMessageReplyParams& params) {
257 if (TrackedCallback::IsPending(callback)) 309 if (TrackedCallback::IsPending(callback))
258 RunCallback(callback, params.result()); 310 RunCallback(callback, params.result());
259 } 311 }
260 312
261 void UDPSocketResourceBase::OnPluginMsgBindReply( 313 void UDPSocketResourceBase::OnPluginMsgBindReply(
262 const ResourceMessageReplyParams& params, 314 const ResourceMessageReplyParams& params,
263 const PP_NetAddress_Private& bound_addr) { 315 const PP_NetAddress_Private& bound_addr) {
264 // It is possible that |bind_callback_| is pending while |closed_| is true: 316 // It is possible that |bind_callback_| is pending while |closed_| is true:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 if (result == PP_OK && !data.empty()) 417 if (result == PP_OK && !data.empty())
366 memcpy(output_buffer, data.c_str(), data.size()); 418 memcpy(output_buffer, data.c_str(), data.size());
367 419
368 recvfrom_addr_ = addr; 420 recvfrom_addr_ = addr;
369 421
370 return result == PP_OK ? static_cast<int32_t>(data.size()) : result; 422 return result == PP_OK ? static_cast<int32_t>(data.size()) : result;
371 } 423 }
372 424
373 } // namespace proxy 425 } // namespace proxy
374 } // namespace ppapi 426 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698