make listen_socket_t non-copyable and non-movable (#2137)
The DHT stores a pointer to this struct so it must not be copied or moved once it is stored in m_listen_sockets.
This commit is contained in:
parent
718c5f0dcb
commit
389b4eb3f2
|
@ -133,15 +133,9 @@ namespace aux {
|
|||
TORRENT_EXTRA_EXPORT entry save_dht_settings(dht_settings const& settings);
|
||||
#endif
|
||||
|
||||
struct listen_socket_t final : aux::session_listen_socket
|
||||
struct listen_socket_impl
|
||||
{
|
||||
address get_external_address() override
|
||||
{ return external_address.external_address(); }
|
||||
|
||||
tcp::endpoint get_local_endpoint() override
|
||||
{ return local_endpoint; }
|
||||
|
||||
listen_socket_t()
|
||||
listen_socket_impl()
|
||||
{
|
||||
tcp_port_mapping[0] = -1;
|
||||
tcp_port_mapping[1] = -1;
|
||||
|
@ -191,6 +185,24 @@ namespace aux {
|
|||
std::shared_ptr<aux::session_udp_socket> udp_sock;
|
||||
};
|
||||
|
||||
struct listen_socket_t final : listen_socket_impl, aux::session_listen_socket
|
||||
{
|
||||
listen_socket_t(listen_socket_t const&) = delete;
|
||||
listen_socket_t(listen_socket_t&&) = delete;
|
||||
listen_socket_t& operator=(listen_socket_t const&) = delete;
|
||||
listen_socket_t& operator=(listen_socket_t&&) = delete;
|
||||
|
||||
address get_external_address() override
|
||||
{ return external_address.external_address(); }
|
||||
|
||||
tcp::endpoint get_local_endpoint() override
|
||||
{ return local_endpoint; }
|
||||
|
||||
listen_socket_t(listen_socket_impl const& i) // NOLINT
|
||||
: listen_socket_impl(i)
|
||||
{}
|
||||
};
|
||||
|
||||
struct TORRENT_EXTRA_EXPORT listen_endpoint_t
|
||||
{
|
||||
listen_endpoint_t(address adr, int p, std::string dev, transport s)
|
||||
|
@ -954,7 +966,7 @@ namespace aux {
|
|||
open_ssl_socket = 0x10
|
||||
};
|
||||
|
||||
listen_socket_t setup_listener(std::string const& device
|
||||
listen_socket_impl setup_listener(std::string const& device
|
||||
, tcp::endpoint bind_ep, int flags, error_code& ec);
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
|
|
|
@ -1447,7 +1447,7 @@ namespace {
|
|||
|
||||
enum { listen_no_system_port = 0x02 };
|
||||
|
||||
listen_socket_t session_impl::setup_listener(std::string const& device
|
||||
listen_socket_impl session_impl::setup_listener(std::string const& device
|
||||
, tcp::endpoint bind_ep, int flags, error_code& ec)
|
||||
{
|
||||
int retries = m_settings.get_int(settings_pack::max_retry_port_bind);
|
||||
|
@ -1460,7 +1460,7 @@ namespace {
|
|||
}
|
||||
#endif
|
||||
|
||||
listen_socket_t ret;
|
||||
listen_socket_impl ret;
|
||||
ret.ssl = (flags & open_ssl_socket) != 0 ? transport::ssl : transport::plaintext;
|
||||
ret.original_port = bind_ep.port();
|
||||
operation_t last_op = operation_t::unknown;
|
||||
|
@ -1975,13 +1975,13 @@ namespace {
|
|||
// an existing socket
|
||||
for (auto const& ep : eps)
|
||||
{
|
||||
listen_socket_t const s = setup_listener(ep.device
|
||||
listen_socket_impl const s = setup_listener(ep.device
|
||||
, tcp::endpoint(ep.addr, std::uint16_t(ep.port))
|
||||
, flags | (ep.ssl == transport::ssl ? open_ssl_socket : 0), ec);
|
||||
|
||||
if (!ec && (s.sock || s.udp_sock))
|
||||
{
|
||||
m_listen_sockets.push_back(s);
|
||||
m_listen_sockets.emplace_back(s);
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
if (m_dht)
|
||||
|
|
|
@ -61,10 +61,10 @@ namespace
|
|||
return aux::listen_endpoint_t(address::from_string(ip), port, device, ssl);
|
||||
}
|
||||
|
||||
aux::listen_socket_t sock(char const* ip, int const port
|
||||
aux::listen_socket_impl sock(char const* ip, int const port
|
||||
, int const original_port, char const* device = "", tp ssl = tp::plaintext)
|
||||
{
|
||||
aux::listen_socket_t s;
|
||||
aux::listen_socket_impl s;
|
||||
s.local_endpoint = tcp::endpoint(address::from_string(ip), port);
|
||||
s.original_port = original_port;
|
||||
s.device = device;
|
||||
|
@ -72,13 +72,13 @@ namespace
|
|||
return s;
|
||||
}
|
||||
|
||||
aux::listen_socket_t sock(char const* ip, int const port, tp ssl)
|
||||
aux::listen_socket_impl sock(char const* ip, int const port, tp ssl)
|
||||
{ return sock(ip, port, port, "", ssl); }
|
||||
|
||||
aux::listen_socket_t sock(char const* ip, int const port, char const* dev)
|
||||
aux::listen_socket_impl sock(char const* ip, int const port, char const* dev)
|
||||
{ return sock(ip, port, port, dev); }
|
||||
|
||||
aux::listen_socket_t sock(char const* ip, int const port)
|
||||
aux::listen_socket_impl sock(char const* ip, int const port)
|
||||
{ return sock(ip, port, port); }
|
||||
|
||||
} // anonymous namespace
|
||||
|
|
Loading…
Reference in New Issue