Chromium Code Reviews| Index: chrome/browser/extensions/api/socket/udp_socket.cc |
| diff --git a/chrome/browser/extensions/api/socket/udp_socket.cc b/chrome/browser/extensions/api/socket/udp_socket.cc |
| index b9a804cbb98d8e3d2ff057ca1b548de9eda27628..ff97df073611ceccd27fdd41b32ae390e091d899 100644 |
| --- a/chrome/browser/extensions/api/socket/udp_socket.cc |
| +++ b/chrome/browser/extensions/api/socket/udp_socket.cc |
| @@ -222,4 +222,60 @@ void UDPSocket::OnSendToComplete(int result) { |
| send_to_callback_.Reset(); |
| } |
| +int UDPSocket::JoinGroup(const std::string& address) { |
| + if (!socket_.is_connected()) |
| + return net::ERR_SOCKET_NOT_CONNECTED; |
| + net::IPAddressNumber ip; |
| + if (!net::ParseIPLiteralToNumber(address, &ip)) |
| + return net::ERR_ADDRESS_INVALID; |
| + |
| + std::string normalized_address = net::IPAddressToString(ip); |
| + base::hash_set<std::string>::iterator find_result = |
| + 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.
|
| + if (find_result != multicast_groups_.end()) { |
| + return net::ERR_ADDRESS_INVALID; |
| + } |
| + |
| + int rv = socket_.JoinGroup(ip); |
| + if (rv == 0) { |
| + multicast_groups_.insert(normalized_address); |
| + } |
| + return rv; |
| +} |
| + |
| +int UDPSocket::LeaveGroup(const std::string& address) { |
| + if (!socket_.is_connected()) |
| + return net::ERR_SOCKET_NOT_CONNECTED; |
| + net::IPAddressNumber ip; |
| + if (!net::ParseIPLiteralToNumber(address, &ip)) |
| + return net::ERR_ADDRESS_INVALID; |
| + |
| + std::string normalized_address = net::IPAddressToString(ip); |
| + base::hash_set<std::string>::iterator find_result = |
| + multicast_groups_.find(normalized_address); |
|
mmenke
2013/04/12 21:07:41
4-space indent when continued from previous line.
|
| + if (find_result == multicast_groups_.end()) { |
| + return net::ERR_ADDRESS_INVALID; |
| + } |
| + |
| + int rv = socket_.LeaveGroup(ip); |
| + if (rv == 0) { |
| + multicast_groups_.erase(find_result); |
| + } |
| + return rv; |
| +} |
| + |
| +int UDPSocket::SetMulticastTimeToLive(int ttl) { |
| + return socket_.SetMulticastTimeToLive(ttl); |
| +} |
| + |
| +int UDPSocket::SetMulticastLoopbackMode(bool loopback) { |
| + return socket_.SetMulticastLoopbackMode(loopback); |
| +} |
| + |
| +int UDPSocket::GetJoinedGroups(base::hash_set<std::string>& groups) const { |
| + if (!socket_.is_connected()) |
| + return net::ERR_SOCKET_NOT_CONNECTED; |
| + groups = multicast_groups_; |
| + return 0; |
| +} |
| } // namespace extensions |