apply {get,set}_option to the appropriate socket based on the option's level

This avoids spurious errors being returned when trying to apply IPv4 options to
the IPv6 socket and vice-versa.
This commit is contained in:
Steven Siloti 2016-04-02 14:20:48 -07:00
parent 55c35332ba
commit 4949721389
2 changed files with 15 additions and 6 deletions

View File

@ -114,25 +114,34 @@ namespace libtorrent
template <class SocketOption> template <class SocketOption>
void get_option(SocketOption const& opt, error_code& ec) void get_option(SocketOption const& opt, error_code& ec)
{ {
m_ipv4_sock.get_option(opt, ec);
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
m_ipv6_sock.get_option(opt, ec); if (opt.level(udp::v6()) == IPPROTO_IPV6)
m_ipv6_sock.get_option(opt, ec);
else
#endif #endif
m_ipv4_sock.get_option(opt, ec);
} }
template <class SocketOption> template <class SocketOption>
void set_option(SocketOption const& opt, error_code& ec) void set_option(SocketOption const& opt, error_code& ec)
{ {
m_ipv4_sock.set_option(opt, ec); if (opt.level(udp::v4()) != IPPROTO_IPV6)
m_ipv4_sock.set_option(opt, ec);
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
m_ipv6_sock.set_option(opt, ec); if (opt.level(udp::v6()) != IPPROTO_IP)
m_ipv6_sock.set_option(opt, ec);
#endif #endif
} }
template <class SocketOption> template <class SocketOption>
void get_option(SocketOption& opt, error_code& ec) void get_option(SocketOption& opt, error_code& ec)
{ {
m_ipv4_sock.get_option(opt, ec); #if TORRENT_USE_IPV6
if (opt.level(udp::v6()) == IPPROTO_IPV6)
m_ipv6_sock.get_option(opt, ec);
else
#endif
m_ipv4_sock.get_option(opt, ec);
} }
udp::endpoint proxy_addr() const { return m_proxy_addr; } udp::endpoint proxy_addr() const { return m_proxy_addr; }

@ -1 +1 @@
Subproject commit 66356b0ce99cd126c7c99df50609b3050ba44e5d Subproject commit 0151d5c17fa3f4cf0ce518d0b8f90a23792c9b24