| 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..737166ebf754bd33c83cc696409a714cf4e0d917 100644
|
| --- a/chrome/browser/extensions/api/socket/udp_socket.cc
|
| +++ b/chrome/browser/extensions/api/socket/udp_socket.cc
|
| @@ -222,4 +222,58 @@ 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);
|
| + 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);
|
| + 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->clear();
|
| + groups->insert(multicast_groups_.begin(), multicast_groups_.end());
|
| + return 0;
|
| +}
|
| +
|
| } // namespace extensions
|
|
|