forked from premiere/premiere-libtorrent
fixes #332
This commit is contained in:
parent
f296d5a64d
commit
5ec7da07e6
|
@ -60,7 +60,7 @@ struct http_connection;
|
||||||
class connection_queue;
|
class connection_queue;
|
||||||
|
|
||||||
typedef boost::function<void(error_code const&
|
typedef boost::function<void(error_code const&
|
||||||
, http_parser const&, char const* data, int size)> http_handler;
|
, http_parser const&, char const* data, int size, http_connection&)> http_handler;
|
||||||
|
|
||||||
typedef boost::function<void(http_connection&)> http_connect_handler;
|
typedef boost::function<void(http_connection&)> http_connect_handler;
|
||||||
|
|
||||||
|
|
|
@ -103,13 +103,14 @@ private:
|
||||||
|
|
||||||
|
|
||||||
void on_upnp_xml(error_code const& e
|
void on_upnp_xml(error_code const& e
|
||||||
, libtorrent::http_parser const& p, rootdevice& d);
|
, libtorrent::http_parser const& p, rootdevice& d
|
||||||
|
, http_connection& c);
|
||||||
void on_upnp_map_response(error_code const& e
|
void on_upnp_map_response(error_code const& e
|
||||||
, libtorrent::http_parser const& p, rootdevice& d
|
, libtorrent::http_parser const& p, rootdevice& d
|
||||||
, int mapping);
|
, int mapping, http_connection& c);
|
||||||
void on_upnp_unmap_response(error_code const& e
|
void on_upnp_unmap_response(error_code const& e
|
||||||
, libtorrent::http_parser const& p, rootdevice& d
|
, libtorrent::http_parser const& p, rootdevice& d
|
||||||
, int mapping);
|
, int mapping, http_connection& c);
|
||||||
void on_expire(error_code const& e);
|
void on_expire(error_code const& e);
|
||||||
|
|
||||||
void disable(char const* msg);
|
void disable(char const* msg);
|
||||||
|
|
|
@ -307,7 +307,7 @@ void http_connection::callback(error_code const& e, char const* data, int size)
|
||||||
std::string error;
|
std::string error;
|
||||||
if (inflate_gzip(data, size, buf, max_bottled_buffer, error))
|
if (inflate_gzip(data, size, buf, max_bottled_buffer, error))
|
||||||
{
|
{
|
||||||
callback(asio::error::fault, data, size);
|
if (m_handler) m_handler(asio::error::fault, m_parser, data, size, *this);
|
||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ void http_connection::callback(error_code const& e, char const* data, int size)
|
||||||
}
|
}
|
||||||
m_called = true;
|
m_called = true;
|
||||||
m_timer.cancel();
|
m_timer.cancel();
|
||||||
if (m_handler) m_handler(e, m_parser, data, size);
|
if (m_handler) m_handler(e, m_parser, data, size, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
src/upnp.cpp
27
src/upnp.cpp
|
@ -248,9 +248,10 @@ void upnp::resend_request(error_code const& e)
|
||||||
m_log << time_now_string()
|
m_log << time_now_string()
|
||||||
<< " ==> connecting to " << d.url << std::endl;
|
<< " ==> connecting to " << d.url << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
if (d.upnp_connection) d.upnp_connection->close();
|
||||||
d.upnp_connection.reset(new http_connection(m_io_service
|
d.upnp_connection.reset(new http_connection(m_io_service
|
||||||
, m_cc, bind(&upnp::on_upnp_xml, self(), _1, _2
|
, m_cc, bind(&upnp::on_upnp_xml, self(), _1, _2
|
||||||
, boost::ref(d))));
|
, boost::ref(d), _5)));
|
||||||
d.upnp_connection->get(d.url, seconds(30), 1);
|
d.upnp_connection->get(d.url, seconds(30), 1);
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
|
@ -492,9 +493,10 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
|
||||||
m_log << time_now_string()
|
m_log << time_now_string()
|
||||||
<< " ==> connecting to " << d.url << std::endl;
|
<< " ==> connecting to " << d.url << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
if (d.upnp_connection) d.upnp_connection->close();
|
||||||
d.upnp_connection.reset(new http_connection(m_io_service
|
d.upnp_connection.reset(new http_connection(m_io_service
|
||||||
, m_cc, bind(&upnp::on_upnp_xml, self(), _1, _2
|
, m_cc, bind(&upnp::on_upnp_xml, self(), _1, _2
|
||||||
, boost::ref(d))));
|
, boost::ref(d), _5)));
|
||||||
d.upnp_connection->get(d.url, seconds(30), 1);
|
d.upnp_connection->get(d.url, seconds(30), 1);
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
}
|
}
|
||||||
|
@ -631,9 +633,10 @@ void upnp::update_map(rootdevice& d, int i)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (d.upnp_connection) d.upnp_connection->close();
|
||||||
d.upnp_connection.reset(new http_connection(m_io_service
|
d.upnp_connection.reset(new http_connection(m_io_service
|
||||||
, m_cc, bind(&upnp::on_upnp_map_response, self(), _1, _2
|
, m_cc, bind(&upnp::on_upnp_map_response, self(), _1, _2
|
||||||
, boost::ref(d), i), true
|
, boost::ref(d), i, _5), true
|
||||||
, bind(&upnp::create_port_mapping, self(), _1, boost::ref(d), i)));
|
, bind(&upnp::create_port_mapping, self(), _1, boost::ref(d), i)));
|
||||||
|
|
||||||
d.upnp_connection->start(d.hostname, boost::lexical_cast<std::string>(d.port)
|
d.upnp_connection->start(d.hostname, boost::lexical_cast<std::string>(d.port)
|
||||||
|
@ -641,9 +644,10 @@ void upnp::update_map(rootdevice& d, int i)
|
||||||
}
|
}
|
||||||
else if (m.action == mapping_t::action_delete)
|
else if (m.action == mapping_t::action_delete)
|
||||||
{
|
{
|
||||||
|
if (d.upnp_connection) d.upnp_connection->close();
|
||||||
d.upnp_connection.reset(new http_connection(m_io_service
|
d.upnp_connection.reset(new http_connection(m_io_service
|
||||||
, m_cc, bind(&upnp::on_upnp_unmap_response, self(), _1, _2
|
, m_cc, bind(&upnp::on_upnp_unmap_response, self(), _1, _2
|
||||||
, boost::ref(d), i), true
|
, boost::ref(d), i, _5), true
|
||||||
, bind(&upnp::delete_port_mapping, self(), boost::ref(d), i)));
|
, bind(&upnp::delete_port_mapping, self(), boost::ref(d), i)));
|
||||||
d.upnp_connection->start(d.hostname, boost::lexical_cast<std::string>(d.port)
|
d.upnp_connection->start(d.hostname, boost::lexical_cast<std::string>(d.port)
|
||||||
, seconds(10), 1);
|
, seconds(10), 1);
|
||||||
|
@ -752,12 +756,13 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
void upnp::on_upnp_xml(error_code const& e
|
void upnp::on_upnp_xml(error_code const& e
|
||||||
, libtorrent::http_parser const& p, rootdevice& d)
|
, libtorrent::http_parser const& p, rootdevice& d
|
||||||
|
, http_connection& c)
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
TORRENT_ASSERT(d.magic == 1337);
|
TORRENT_ASSERT(d.magic == 1337);
|
||||||
if (d.upnp_connection)
|
if (d.upnp_connection && d.upnp_connection.get() == &c)
|
||||||
{
|
{
|
||||||
d.upnp_connection->close();
|
d.upnp_connection->close();
|
||||||
d.upnp_connection.reset();
|
d.upnp_connection.reset();
|
||||||
|
@ -911,12 +916,13 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
void upnp::on_upnp_map_response(error_code const& e
|
void upnp::on_upnp_map_response(error_code const& e
|
||||||
, libtorrent::http_parser const& p, rootdevice& d, int mapping)
|
, libtorrent::http_parser const& p, rootdevice& d, int mapping
|
||||||
|
, http_connection& c)
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
TORRENT_ASSERT(d.magic == 1337);
|
TORRENT_ASSERT(d.magic == 1337);
|
||||||
if (d.upnp_connection)
|
if (d.upnp_connection && d.upnp_connection.get() == &c)
|
||||||
{
|
{
|
||||||
d.upnp_connection->close();
|
d.upnp_connection->close();
|
||||||
d.upnp_connection.reset();
|
d.upnp_connection.reset();
|
||||||
|
@ -1066,12 +1072,13 @@ void upnp::return_error(int mapping, int code)
|
||||||
}
|
}
|
||||||
|
|
||||||
void upnp::on_upnp_unmap_response(error_code const& e
|
void upnp::on_upnp_unmap_response(error_code const& e
|
||||||
, libtorrent::http_parser const& p, rootdevice& d, int mapping)
|
, libtorrent::http_parser const& p, rootdevice& d, int mapping
|
||||||
|
, http_connection& c)
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
TORRENT_ASSERT(d.magic == 1337);
|
TORRENT_ASSERT(d.magic == 1337);
|
||||||
if (d.upnp_connection)
|
if (d.upnp_connection && d.upnp_connection.get() == &c)
|
||||||
{
|
{
|
||||||
d.upnp_connection->close();
|
d.upnp_connection->close();
|
||||||
d.upnp_connection.reset();
|
d.upnp_connection.reset();
|
||||||
|
|
|
@ -38,7 +38,8 @@ void http_connect_handler(http_connection& c)
|
||||||
TEST_CHECK(c.socket().remote_endpoint().address() == address::from_string("127.0.0.1"));
|
TEST_CHECK(c.socket().remote_endpoint().address() == address::from_string("127.0.0.1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void http_handler(error_code const& ec, http_parser const& parser, char const* data, int size)
|
void http_handler(error_code const& ec, http_parser const& parser
|
||||||
|
, char const* data, int size, http_connection& c)
|
||||||
{
|
{
|
||||||
++handler_called;
|
++handler_called;
|
||||||
data_size = size;
|
data_size = size;
|
||||||
|
|
Loading…
Reference in New Issue