OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shared_impl/private/udp_socket_private_impl.h" | 5 #include "ppapi/shared_impl/private/udp_socket_private_impl.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // TODO(dmichael): use some other strategy for determining if an | 51 // TODO(dmichael): use some other strategy for determining if an |
52 // operation is in progress | 52 // operation is in progress |
53 | 53 |
54 bind_callback_ = new TrackedCallback(this, callback); | 54 bind_callback_ = new TrackedCallback(this, callback); |
55 | 55 |
56 // Send the request, the browser will call us back via BindACK. | 56 // Send the request, the browser will call us back via BindACK. |
57 SendBind(*addr); | 57 SendBind(*addr); |
58 return PP_OK_COMPLETIONPENDING; | 58 return PP_OK_COMPLETIONPENDING; |
59 } | 59 } |
60 | 60 |
| 61 PP_Bool UDPSocketPrivateImpl::GetBoundAddress(PP_NetAddress_Private* addr) { |
| 62 if (!addr || !bound_ || closed_) |
| 63 return PP_FALSE; |
| 64 |
| 65 *addr = bound_addr_; |
| 66 return PP_TRUE; |
| 67 } |
| 68 |
61 int32_t UDPSocketPrivateImpl::RecvFrom(char* buffer, | 69 int32_t UDPSocketPrivateImpl::RecvFrom(char* buffer, |
62 int32_t num_bytes, | 70 int32_t num_bytes, |
63 PP_CompletionCallback callback) { | 71 PP_CompletionCallback callback) { |
64 if (!buffer || num_bytes <= 0 || !callback.func) | 72 if (!buffer || num_bytes <= 0 || !callback.func) |
65 return PP_ERROR_BADARGUMENT; | 73 return PP_ERROR_BADARGUMENT; |
66 if (!bound_) | 74 if (!bound_) |
67 return PP_ERROR_FAILED; | 75 return PP_ERROR_FAILED; |
68 if (TrackedCallback::IsPending(recvfrom_callback_)) | 76 if (TrackedCallback::IsPending(recvfrom_callback_)) |
69 return PP_ERROR_INPROGRESS; | 77 return PP_ERROR_INPROGRESS; |
70 | 78 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 123 |
116 SendClose(); | 124 SendClose(); |
117 | 125 |
118 socket_id_ = 0; | 126 socket_id_ = 0; |
119 | 127 |
120 PostAbortIfNecessary(&bind_callback_); | 128 PostAbortIfNecessary(&bind_callback_); |
121 PostAbortIfNecessary(&recvfrom_callback_); | 129 PostAbortIfNecessary(&recvfrom_callback_); |
122 PostAbortIfNecessary(&sendto_callback_); | 130 PostAbortIfNecessary(&sendto_callback_); |
123 } | 131 } |
124 | 132 |
125 void UDPSocketPrivateImpl::OnBindCompleted(bool succeeded) { | 133 void UDPSocketPrivateImpl::OnBindCompleted( |
| 134 bool succeeded, |
| 135 const PP_NetAddress_Private& addr) { |
126 if (!TrackedCallback::IsPending(bind_callback_)) { | 136 if (!TrackedCallback::IsPending(bind_callback_)) { |
127 NOTREACHED(); | 137 NOTREACHED(); |
128 return; | 138 return; |
129 } | 139 } |
130 | 140 |
131 if (succeeded) | 141 if (succeeded) |
132 bound_ = true; | 142 bound_ = true; |
133 | 143 |
| 144 bound_addr_ = addr; |
| 145 |
134 TrackedCallback::ClearAndRun(&bind_callback_, | 146 TrackedCallback::ClearAndRun(&bind_callback_, |
135 succeeded ? PP_OK : PP_ERROR_FAILED); | 147 succeeded ? PP_OK : PP_ERROR_FAILED); |
136 } | 148 } |
137 | 149 |
138 void UDPSocketPrivateImpl::OnRecvFromCompleted( | 150 void UDPSocketPrivateImpl::OnRecvFromCompleted( |
139 bool succeeded, | 151 bool succeeded, |
140 const std::string& data, | 152 const std::string& data, |
141 const PP_NetAddress_Private& addr) { | 153 const PP_NetAddress_Private& addr) { |
142 if (!TrackedCallback::IsPending(recvfrom_callback_) || !read_buffer_) { | 154 if (!TrackedCallback::IsPending(recvfrom_callback_) || !read_buffer_) { |
143 NOTREACHED(); | 155 NOTREACHED(); |
144 return; | 156 return; |
145 } | 157 } |
(...skipping 27 matching lines...) Expand all Loading... |
173 DCHECK(socket_id != 0); | 185 DCHECK(socket_id != 0); |
174 socket_id_ = socket_id; | 186 socket_id_ = socket_id; |
175 bound_ = false; | 187 bound_ = false; |
176 closed_ = false; | 188 closed_ = false; |
177 read_buffer_ = NULL; | 189 read_buffer_ = NULL; |
178 bytes_to_read_ = -1; | 190 bytes_to_read_ = -1; |
179 | 191 |
180 recvfrom_addr_.size = 0; | 192 recvfrom_addr_.size = 0; |
181 memset(recvfrom_addr_.data, 0, | 193 memset(recvfrom_addr_.data, 0, |
182 arraysize(recvfrom_addr_.data) * sizeof(*recvfrom_addr_.data)); | 194 arraysize(recvfrom_addr_.data) * sizeof(*recvfrom_addr_.data)); |
| 195 bound_addr_.size = 0; |
| 196 memset(bound_addr_.data, 0, |
| 197 arraysize(bound_addr_.data) * sizeof(*bound_addr_.data)); |
183 } | 198 } |
184 | 199 |
185 void UDPSocketPrivateImpl::PostAbortIfNecessary( | 200 void UDPSocketPrivateImpl::PostAbortIfNecessary( |
186 scoped_refptr<TrackedCallback>* callback) { | 201 scoped_refptr<TrackedCallback>* callback) { |
187 if (callback->get()) | 202 if (callback->get()) |
188 (*callback)->PostAbort(); | 203 (*callback)->PostAbort(); |
189 } | 204 } |
190 | 205 |
191 } // namespace ppapi | 206 } // namespace ppapi |
OLD | NEW |