some code refactor and cleanup in broadcast_socket

This commit is contained in:
Alden Torres 2018-03-21 13:42:11 -04:00 committed by Arvid Norberg
parent e08ec99132
commit 6b35ebb9ad
2 changed files with 7 additions and 17 deletions

View File

@ -79,10 +79,10 @@ namespace libtorrent {
struct socket_entry struct socket_entry
{ {
explicit socket_entry(std::shared_ptr<udp::socket> const& s) explicit socket_entry(std::shared_ptr<udp::socket> s)
: socket(s), broadcast(false) { std::memset(buffer, 0, sizeof(buffer)); } : socket(std::move(s)), broadcast(false) { std::memset(buffer, 0, sizeof(buffer)); }
socket_entry(std::shared_ptr<udp::socket> const& s socket_entry(std::shared_ptr<udp::socket> s
, address_v4 const& mask): socket(s), netmask(mask), broadcast(false) , address_v4 const& mask): socket(std::move(s)), netmask(mask), broadcast(false)
{ std::memset(buffer, 0, sizeof(buffer)); } { std::memset(buffer, 0, sizeof(buffer)); }
std::shared_ptr<udp::socket> socket; std::shared_ptr<udp::socket> socket;
char buffer[1500]; char buffer[1500];

View File

@ -33,17 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp"
#if defined TORRENT_OS2
#include <pthread.h>
#endif
#include <boost/asio/ip/multicast.hpp> #include <boost/asio/ip/multicast.hpp>
#ifdef TORRENT_WINDOWS
#include <iphlpapi.h> // for if_nametoindex
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
@ -129,9 +119,9 @@ namespace libtorrent {
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
TORRENT_TRY { TORRENT_TRY {
if (!addr.is_v6()) return false; if (!addr.is_v6()) return false;
std::uint8_t teredo_prefix[] = {0x20, 0x01, 0, 0}; static const std::uint8_t teredo_prefix[] = {0x20, 0x01, 0, 0};
address_v6::bytes_type b = addr.to_v6().to_bytes(); address_v6::bytes_type b = addr.to_v6().to_bytes();
return std::memcmp(&b[0], teredo_prefix, 4) == 0; return std::memcmp(b.data(), teredo_prefix, 4) == 0;
} TORRENT_CATCH(std::exception const&) { return false; } } TORRENT_CATCH(std::exception const&) { return false; }
#else #else
TORRENT_UNUSED(addr); TORRENT_UNUSED(addr);
@ -189,7 +179,7 @@ namespace libtorrent {
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec); std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
if (m_multicast_endpoint.address().is_v6()) if (m_multicast_endpoint.protocol() == udp::v6())
open_multicast_socket(ios, address_v6::any(), loopback, ec); open_multicast_socket(ios, address_v6::any(), loopback, ec);
else else
#endif #endif