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

Side by Side Diff: chrome/browser/extensions/api/socket/udp_socket.cc

Issue 12684008: Multicast socket API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/extensions/api/socket/udp_socket.h" 5 #include "chrome/browser/extensions/api/socket/udp_socket.h"
6 6
7 #include "chrome/browser/extensions/api/api_resource.h" 7 #include "chrome/browser/extensions/api/api_resource.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/udp/datagram_socket.h" 10 #include "net/udp/datagram_socket.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 recv_from_callback_.Run(result, io_buffer, ip, port); 215 recv_from_callback_.Run(result, io_buffer, ip, port);
216 recv_from_callback_.Reset(); 216 recv_from_callback_.Reset();
217 } 217 }
218 218
219 void UDPSocket::OnSendToComplete(int result) { 219 void UDPSocket::OnSendToComplete(int result) {
220 DCHECK(!send_to_callback_.is_null()); 220 DCHECK(!send_to_callback_.is_null());
221 send_to_callback_.Run(result); 221 send_to_callback_.Run(result);
222 send_to_callback_.Reset(); 222 send_to_callback_.Reset();
223 } 223 }
224 224
225 int UDPSocket::JoinGroup(const std::string& address) {
226 if (!socket_.is_connected())
227 return net::ERR_SOCKET_NOT_CONNECTED;
228 net::IPAddressNumber ip;
229 if (!net::ParseIPLiteralToNumber(address, &ip))
230 return net::ERR_ADDRESS_INVALID;
231
232 std::string normalized_address = net::IPAddressToString(ip);
233 base::hash_set<std::string>::iterator find_result =
234 multicast_groups_.find(normalized_address);
mmenke 2013/04/12 21:07:41 4-space indent when continued from previous line.
Bei Zhang 2013/04/15 22:30:26 Done.
235 if (find_result != multicast_groups_.end()) {
236 return net::ERR_ADDRESS_INVALID;
237 }
238
239 int rv = socket_.JoinGroup(ip);
240 if (rv == 0) {
241 multicast_groups_.insert(normalized_address);
242 }
243 return rv;
244 }
245
246 int UDPSocket::LeaveGroup(const std::string& address) {
247 if (!socket_.is_connected())
248 return net::ERR_SOCKET_NOT_CONNECTED;
249 net::IPAddressNumber ip;
250 if (!net::ParseIPLiteralToNumber(address, &ip))
251 return net::ERR_ADDRESS_INVALID;
252
253 std::string normalized_address = net::IPAddressToString(ip);
254 base::hash_set<std::string>::iterator find_result =
255 multicast_groups_.find(normalized_address);
mmenke 2013/04/12 21:07:41 4-space indent when continued from previous line.
256 if (find_result == multicast_groups_.end()) {
257 return net::ERR_ADDRESS_INVALID;
258 }
259
260 int rv = socket_.LeaveGroup(ip);
261 if (rv == 0) {
262 multicast_groups_.erase(find_result);
263 }
264 return rv;
265 }
266
267 int UDPSocket::SetMulticastTimeToLive(int ttl) {
268 return socket_.SetMulticastTimeToLive(ttl);
269 }
270
271 int UDPSocket::SetMulticastLoopbackMode(bool loopback) {
272 return socket_.SetMulticastLoopbackMode(loopback);
273 }
274
275 int UDPSocket::GetJoinedGroups(base::hash_set<std::string>& groups) const {
276 if (!socket_.is_connected())
277 return net::ERR_SOCKET_NOT_CONNECTED;
278 groups = multicast_groups_;
279 return 0;
280 }
225 } // namespace extensions 281 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698