Skip to content

Commit e0dcd34

Browse files
committed
convert m_listen_sockets to a vector of shared_ptr
1 parent 0f30815 commit e0dcd34

File tree

3 files changed

+153
-160
lines changed

3 files changed

+153
-160
lines changed

include/libtorrent/aux_/session_impl.hpp

+22-29
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,30 @@ namespace aux {
133133
TORRENT_EXTRA_EXPORT entry save_dht_settings(dht_settings const& settings);
134134
#endif
135135

136-
struct listen_socket_impl
136+
struct listen_socket_t final : aux::session_listen_socket
137137
{
138-
listen_socket_impl()
138+
listen_socket_t()
139139
{
140140
tcp_port_mapping[0] = -1;
141141
tcp_port_mapping[1] = -1;
142142
udp_port_mapping[0] = -1;
143143
udp_port_mapping[1] = -1;
144144
}
145145

146+
listen_socket_t(listen_socket_t const&) = delete;
147+
listen_socket_t(listen_socket_t&&) = delete;
148+
listen_socket_t& operator=(listen_socket_t const&) = delete;
149+
listen_socket_t& operator=(listen_socket_t&&) = delete;
150+
151+
address get_external_address() override
152+
{ return external_address.external_address(); }
153+
154+
tcp::endpoint get_local_endpoint() override
155+
{ return local_endpoint; }
156+
157+
bool is_ssl() override
158+
{ return ssl == transport::ssl; }
159+
146160
// this may be empty but can be set
147161
// to the WAN IP address of a NAT router
148162
ip_voter external_address;
@@ -185,27 +199,6 @@ namespace aux {
185199
std::shared_ptr<aux::session_udp_socket> udp_sock;
186200
};
187201

188-
struct listen_socket_t final : listen_socket_impl, aux::session_listen_socket
189-
{
190-
listen_socket_t(listen_socket_t const&) = delete;
191-
listen_socket_t(listen_socket_t&&) = delete;
192-
listen_socket_t& operator=(listen_socket_t const&) = delete;
193-
listen_socket_t& operator=(listen_socket_t&&) = delete;
194-
195-
address get_external_address() override
196-
{ return external_address.external_address(); }
197-
198-
tcp::endpoint get_local_endpoint() override
199-
{ return local_endpoint; }
200-
201-
bool is_ssl() override
202-
{ return ssl == transport::ssl; }
203-
204-
listen_socket_t(listen_socket_impl const& i) // NOLINT
205-
: listen_socket_impl(i)
206-
{}
207-
};
208-
209202
struct TORRENT_EXTRA_EXPORT listen_endpoint_t
210203
{
211204
listen_endpoint_t(address adr, int p, std::string dev, transport s)
@@ -226,10 +219,10 @@ namespace aux {
226219
// all matched sockets are ordered before unmatched sockets
227220
// matched endpoints are removed from the vector
228221
// returns an iterator to the first unmatched socket
229-
TORRENT_EXTRA_EXPORT std::list<listen_socket_t>::iterator
222+
TORRENT_EXTRA_EXPORT std::vector<std::shared_ptr<aux::listen_socket_t>>::iterator
230223
partition_listen_sockets(
231224
std::vector<listen_endpoint_t>& eps
232-
, std::list<listen_socket_t>& sockets);
225+
, std::vector<std::shared_ptr<aux::listen_socket_t>>& sockets);
233226

234227
// expand [::] to all IPv6 interfaces for BEP 45 compliance
235228
TORRENT_EXTRA_EXPORT void expand_unspecified_address(
@@ -595,7 +588,7 @@ namespace aux {
595588
{
596589
for (auto& s : m_listen_sockets)
597590
{
598-
f(&s);
591+
f(s.get());
599592
}
600593
}
601594

@@ -623,7 +616,7 @@ namespace aux {
623616
{
624617
for (auto const& s : m_listen_sockets)
625618
{
626-
if (s.udp_sock) return s.udp_external_port;
619+
if (s->udp_sock) return s->udp_external_port;
627620
}
628621
return -1;
629622
}
@@ -948,7 +941,7 @@ namespace aux {
948941

949942
// since we might be listening on multiple interfaces
950943
// we might need more than one listen socket
951-
std::list<listen_socket_t> m_listen_sockets;
944+
std::vector<std::shared_ptr<listen_socket_t>> m_listen_sockets;
952945

953946
outgoing_sockets m_outgoing_sockets;
954947

@@ -971,7 +964,7 @@ namespace aux {
971964
open_ssl_socket = 0x10
972965
};
973966

974-
listen_socket_impl setup_listener(std::string const& device
967+
std::shared_ptr<listen_socket_t> setup_listener(std::string const& device
975968
, tcp::endpoint bind_ep, int flags, error_code& ec);
976969

977970
#ifndef TORRENT_DISABLE_DHT

0 commit comments

Comments
 (0)