This commit is contained in:
Arvid Norberg 2008-05-17 00:27:26 +00:00
parent f296d5a64d
commit 5ec7da07e6
5 changed files with 26 additions and 17 deletions

View File

@ -60,7 +60,7 @@ struct http_connection;
class connection_queue;
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;

View File

@ -103,13 +103,14 @@ private:
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
, libtorrent::http_parser const& p, rootdevice& d
, int mapping);
, int mapping, http_connection& c);
void on_upnp_unmap_response(error_code const& e
, libtorrent::http_parser const& p, rootdevice& d
, int mapping);
, int mapping, http_connection& c);
void on_expire(error_code const& e);
void disable(char const* msg);

View File

@ -307,7 +307,7 @@ void http_connection::callback(error_code const& e, char const* data, int size)
std::string 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();
return;
}
@ -317,7 +317,7 @@ void http_connection::callback(error_code const& e, char const* data, int size)
}
m_called = true;
m_timer.cancel();
if (m_handler) m_handler(e, m_parser, data, size);
if (m_handler) m_handler(e, m_parser, data, size, *this);
}
}

View File

@ -248,9 +248,10 @@ void upnp::resend_request(error_code const& e)
m_log << time_now_string()
<< " ==> connecting to " << d.url << std::endl;
#endif
if (d.upnp_connection) d.upnp_connection->close();
d.upnp_connection.reset(new http_connection(m_io_service
, 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);
}
catch (std::exception& e)
@ -492,9 +493,10 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
m_log << time_now_string()
<< " ==> connecting to " << d.url << std::endl;
#endif
if (d.upnp_connection) d.upnp_connection->close();
d.upnp_connection.reset(new http_connection(m_io_service
, 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);
#ifndef BOOST_NO_EXCEPTIONS
}
@ -631,9 +633,10 @@ void upnp::update_map(rootdevice& d, int i)
return;
}
if (d.upnp_connection) d.upnp_connection->close();
d.upnp_connection.reset(new http_connection(m_io_service
, 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)));
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)
{
if (d.upnp_connection) d.upnp_connection->close();
d.upnp_connection.reset(new http_connection(m_io_service
, 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)));
d.upnp_connection->start(d.hostname, boost::lexical_cast<std::string>(d.port)
, seconds(10), 1);
@ -752,12 +756,13 @@ namespace
}
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);
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.reset();
@ -911,12 +916,13 @@ namespace
}
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);
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.reset();
@ -1066,12 +1072,13 @@ void upnp::return_error(int mapping, int code)
}
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);
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.reset();

View File

@ -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"));
}
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;
data_size = size;