OLD | NEW |
---|---|
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 16 matching lines...) Expand all Loading... | |
27 1024 * UDPSocketResourceBase::kMaxWriteSize; | 27 1024 * UDPSocketResourceBase::kMaxWriteSize; |
28 const int32_t UDPSocketResourceBase::kMaxReceiveBufferSize = | 28 const int32_t UDPSocketResourceBase::kMaxReceiveBufferSize = |
29 1024 * UDPSocketResourceBase::kMaxReadSize; | 29 1024 * UDPSocketResourceBase::kMaxReadSize; |
30 const size_t UDPSocketResourceBase::kPluginReceiveBufferSlots = 32u; | 30 const size_t UDPSocketResourceBase::kPluginReceiveBufferSlots = 32u; |
31 | 31 |
32 UDPSocketResourceBase::UDPSocketResourceBase(Connection connection, | 32 UDPSocketResourceBase::UDPSocketResourceBase(Connection connection, |
33 PP_Instance instance, | 33 PP_Instance instance, |
34 bool private_api) | 34 bool private_api) |
35 : PluginResource(connection, instance), | 35 : PluginResource(connection, instance), |
36 private_api_(private_api), | 36 private_api_(private_api), |
37 bind_called_(false), | |
37 bound_(false), | 38 bound_(false), |
38 closed_(false), | 39 closed_(false), |
39 read_buffer_(NULL), | 40 read_buffer_(NULL), |
40 bytes_to_read_(-1), | 41 bytes_to_read_(-1), |
41 recvfrom_addr_resource_(NULL) { | 42 recvfrom_addr_resource_(NULL) { |
42 recvfrom_addr_.size = 0; | 43 recvfrom_addr_.size = 0; |
43 memset(recvfrom_addr_.data, 0, | 44 memset(recvfrom_addr_.data, 0, |
44 arraysize(recvfrom_addr_.data) * sizeof(*recvfrom_addr_.data)); | 45 arraysize(recvfrom_addr_.data) * sizeof(*recvfrom_addr_.data)); |
45 bound_addr_.size = 0; | 46 bound_addr_.size = 0; |
46 memset(bound_addr_.data, 0, | 47 memset(bound_addr_.data, 0, |
47 arraysize(bound_addr_.data) * sizeof(*bound_addr_.data)); | 48 arraysize(bound_addr_.data) * sizeof(*bound_addr_.data)); |
48 | 49 |
49 if (private_api) | 50 if (private_api) |
50 SendCreate(BROWSER, PpapiHostMsg_UDPSocket_CreatePrivate()); | 51 SendCreate(BROWSER, PpapiHostMsg_UDPSocket_CreatePrivate()); |
51 else | 52 else |
52 SendCreate(BROWSER, PpapiHostMsg_UDPSocket_Create()); | 53 SendCreate(BROWSER, PpapiHostMsg_UDPSocket_Create()); |
53 | 54 |
54 PluginGlobals::Get()->resource_reply_thread_registrar()->HandleOnIOThread( | 55 PluginGlobals::Get()->resource_reply_thread_registrar()->HandleOnIOThread( |
55 PpapiPluginMsg_UDPSocket_PushRecvResult::ID); | 56 PpapiPluginMsg_UDPSocket_PushRecvResult::ID); |
56 } | 57 } |
57 | 58 |
58 UDPSocketResourceBase::~UDPSocketResourceBase() { | 59 UDPSocketResourceBase::~UDPSocketResourceBase() { |
59 } | 60 } |
60 | 61 |
61 int32_t UDPSocketResourceBase::SetOptionImpl( | 62 int32_t UDPSocketResourceBase::SetOptionImpl( |
62 PP_UDPSocket_Option name, | 63 PP_UDPSocket_Option name, |
63 const PP_Var& value, | 64 const PP_Var& value, |
65 bool check_bind_state, | |
64 scoped_refptr<TrackedCallback> callback) { | 66 scoped_refptr<TrackedCallback> callback) { |
65 if (closed_) | 67 if (closed_) |
66 return PP_ERROR_FAILED; | 68 return PP_ERROR_FAILED; |
67 | 69 |
68 SocketOptionData option_data; | 70 SocketOptionData option_data; |
69 switch (name) { | 71 switch (name) { |
70 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: | 72 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: |
bbudge
2014/12/09 18:37:38
In the UDP IDL file, the documentation doesn't say
hidehiko
2014/12/09 19:51:42
First, I thought it was not necessary, because mes
| |
71 case PP_UDPSOCKET_OPTION_BROADCAST: { | 73 case PP_UDPSOCKET_OPTION_BROADCAST: { |
72 if (bound_) | 74 if (check_bind_state && bind_called_) |
bbudge
2014/12/09 18:37:38
You should add a comment about *why* you use bind_
hidehiko
2014/12/09 19:51:42
Done.
| |
73 return PP_ERROR_FAILED; | 75 return PP_ERROR_FAILED; |
74 if (value.type != PP_VARTYPE_BOOL) | 76 if (value.type != PP_VARTYPE_BOOL) |
75 return PP_ERROR_BADARGUMENT; | 77 return PP_ERROR_BADARGUMENT; |
76 option_data.SetBool(PP_ToBool(value.value.as_bool)); | 78 option_data.SetBool(PP_ToBool(value.value.as_bool)); |
77 break; | 79 break; |
78 } | 80 } |
79 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: | 81 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: |
80 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { | 82 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { |
81 if (!bound_) | 83 if (check_bind_state && !bound_) |
82 return PP_ERROR_FAILED; | 84 return PP_ERROR_FAILED; |
83 if (value.type != PP_VARTYPE_INT32) | 85 if (value.type != PP_VARTYPE_INT32) |
84 return PP_ERROR_BADARGUMENT; | 86 return PP_ERROR_BADARGUMENT; |
85 option_data.SetInt32(value.value.as_int); | 87 option_data.SetInt32(value.value.as_int); |
86 break; | 88 break; |
87 } | 89 } |
88 default: { | 90 default: { |
89 NOTREACHED(); | 91 NOTREACHED(); |
90 return PP_ERROR_BADARGUMENT; | 92 return PP_ERROR_BADARGUMENT; |
91 } | 93 } |
(...skipping 12 matching lines...) Expand all Loading... | |
104 int32_t UDPSocketResourceBase::BindImpl( | 106 int32_t UDPSocketResourceBase::BindImpl( |
105 const PP_NetAddress_Private* addr, | 107 const PP_NetAddress_Private* addr, |
106 scoped_refptr<TrackedCallback> callback) { | 108 scoped_refptr<TrackedCallback> callback) { |
107 if (!addr) | 109 if (!addr) |
108 return PP_ERROR_BADARGUMENT; | 110 return PP_ERROR_BADARGUMENT; |
109 if (bound_ || closed_) | 111 if (bound_ || closed_) |
110 return PP_ERROR_FAILED; | 112 return PP_ERROR_FAILED; |
111 if (TrackedCallback::IsPending(bind_callback_)) | 113 if (TrackedCallback::IsPending(bind_callback_)) |
112 return PP_ERROR_INPROGRESS; | 114 return PP_ERROR_INPROGRESS; |
113 | 115 |
116 bind_called_ = true; | |
114 bind_callback_ = callback; | 117 bind_callback_ = callback; |
115 | 118 |
116 // Send the request, the browser will call us back via BindReply. | 119 // Send the request, the browser will call us back via BindReply. |
117 Call<PpapiPluginMsg_UDPSocket_BindReply>( | 120 Call<PpapiPluginMsg_UDPSocket_BindReply>( |
118 BROWSER, | 121 BROWSER, |
119 PpapiHostMsg_UDPSocket_Bind(*addr), | 122 PpapiHostMsg_UDPSocket_Bind(*addr), |
120 base::Bind(&UDPSocketResourceBase::OnPluginMsgBindReply, | 123 base::Bind(&UDPSocketResourceBase::OnPluginMsgBindReply, |
121 base::Unretained(this)), | 124 base::Unretained(this)), |
122 callback); | 125 callback); |
123 return PP_OK_COMPLETIONPENDING; | 126 return PP_OK_COMPLETIONPENDING; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 if (result == PP_OK && !data.empty()) | 347 if (result == PP_OK && !data.empty()) |
345 memcpy(output_buffer, data.c_str(), data.size()); | 348 memcpy(output_buffer, data.c_str(), data.size()); |
346 | 349 |
347 recvfrom_addr_ = addr; | 350 recvfrom_addr_ = addr; |
348 | 351 |
349 return result == PP_OK ? static_cast<int32_t>(data.size()) : result; | 352 return result == PP_OK ? static_cast<int32_t>(data.size()) : result; |
350 } | 353 } |
351 | 354 |
352 } // namespace proxy | 355 } // namespace proxy |
353 } // namespace ppapi | 356 } // namespace ppapi |
OLD | NEW |