made it possible to export the upnp state and insert it into a different upnp instance

This commit is contained in:
Arvid Norberg 2008-06-20 16:14:10 +00:00
parent b13911a7ed
commit b183b2e593
2 changed files with 30 additions and 2 deletions

View File

@ -69,9 +69,11 @@ class upnp : public intrusive_ptr_base<upnp>
public:
upnp(io_service& ios, connection_queue& cc
, address const& listen_interface, std::string const& user_agent
, portmap_callback_t const& cb, bool ignore_nonrouters);
, portmap_callback_t const& cb, bool ignore_nonrouters, void* state = 0);
~upnp();
void* drain_state();
enum protocol_type { none = 0, udp = 1, tcp = 2 };
int add_mapping(protocol_type p, int external_port, int local_port);
void delete_mapping(int mapping_index);
@ -226,6 +228,12 @@ private:
{ return url < rhs.url; }
};
struct upnp_state_t
{
std::vector<global_mapping_t> mappings;
std::set<rootdevice> devices;
};
std::vector<global_mapping_t> m_mappings;
std::string const& m_user_agent;

View File

@ -61,7 +61,7 @@ using namespace libtorrent;
upnp::upnp(io_service& ios, connection_queue& cc
, address const& listen_interface, std::string const& user_agent
, portmap_callback_t const& cb, bool ignore_nonrouters)
, portmap_callback_t const& cb, bool ignore_nonrouters, void* state)
: m_user_agent(user_agent)
, m_callback(cb)
, m_retry_count(0)
@ -79,6 +79,26 @@ upnp::upnp(io_service& ios, connection_queue& cc
m_log.open("upnp.log", std::ios::in | std::ios::out | std::ios::trunc);
#endif
m_retry_count = 0;
if (state)
{
upnp_state_t* s = (upnp_state_t*)s;
m_devices.swap(s->devices);
m_mappings.swap(s->mappings);
delete s;
}
}
void* upnp::drain_state()
{
upnp_state_t* s = new upnp_state_t;
s->mappings.swap(m_mappings);
for (std::set<rootdevice>::iterator i = m_devices.begin()
, end(m_devices.end()); i != end; ++i)
i->upnp_connection.reset();
s->devices.swap(m_devices);
return s;
}
upnp::~upnp()