made http_connection build without exception support

This commit is contained in:
Arvid Norberg 2007-12-29 23:37:50 +00:00
parent 9e421b2945
commit ed4b39a2cc
1 changed files with 17 additions and 10 deletions

View File

@ -71,7 +71,8 @@ void http_connection::start(std::string const& hostname, std::string const& port
{ {
m_redirect = handle_redirect; m_redirect = handle_redirect;
m_timeout = timeout; m_timeout = timeout;
m_timer.expires_from_now(m_timeout); asio::error_code ec;
m_timer.expires_from_now(m_timeout, ec);
m_timer.async_wait(bind(&http_connection::on_timeout m_timer.async_wait(bind(&http_connection::on_timeout
, boost::weak_ptr<http_connection>(shared_from_this()), _1)); , boost::weak_ptr<http_connection>(shared_from_this()), _1));
m_called = false; m_called = false;
@ -83,7 +84,8 @@ void http_connection::start(std::string const& hostname, std::string const& port
} }
else else
{ {
m_sock.close(); asio::error_code ec;
m_sock.close(ec);
tcp::resolver::query query(hostname, port); tcp::resolver::query query(hostname, port);
m_resolver.async_resolve(query, bind(&http_connection::on_resolve m_resolver.async_resolve(query, bind(&http_connection::on_resolve
, shared_from_this(), _1, _2)); , shared_from_this(), _1, _2));
@ -119,16 +121,17 @@ void http_connection::on_timeout(boost::weak_ptr<http_connection> p
} }
if (!c->m_sock.is_open()) return; if (!c->m_sock.is_open()) return;
asio::error_code ec;
c->m_timer.expires_at(c->m_last_receive + c->m_timeout); c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec);
c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1)); c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1));
} }
void http_connection::close() void http_connection::close()
{ {
m_timer.cancel(); asio::error_code ec;
m_limiter_timer.cancel(); m_timer.cancel(ec);
m_sock.close(); m_limiter_timer.cancel(ec);
m_sock.close(ec);
m_hostname.clear(); m_hostname.clear();
m_port.clear(); m_port.clear();
@ -190,6 +193,7 @@ void http_connection::callback(asio::error_code const& e, char const* data, int
if (!m_bottled || !m_called) if (!m_bottled || !m_called)
{ {
m_called = true; 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);
} }
} }
@ -304,7 +308,8 @@ void http_connection::on_read(asio::error_code const& e
} }
else if (m_bottled && m_parser.finished()) else if (m_bottled && m_parser.finished())
{ {
m_timer.cancel(); asio::error_code ec;
m_timer.cancel(ec);
callback(e, m_parser.get_body().begin, m_parser.get_body().left()); callback(e, m_parser.get_body().begin, m_parser.get_body().left());
} }
} }
@ -368,8 +373,9 @@ void http_connection::on_assign_bandwidth(asio::error_code const& e)
, bind(&http_connection::on_read , bind(&http_connection::on_read
, shared_from_this(), _1, _2)); , shared_from_this(), _1, _2));
asio::error_code ec;
m_limiter_timer_active = true; m_limiter_timer_active = true;
m_limiter_timer.expires_from_now(milliseconds(250)); m_limiter_timer.expires_from_now(milliseconds(250), ec);
m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth
, shared_from_this(), _1)); , shared_from_this(), _1));
} }
@ -380,8 +386,9 @@ void http_connection::rate_limit(int limit)
if (!m_limiter_timer_active) if (!m_limiter_timer_active)
{ {
asio::error_code ec;
m_limiter_timer_active = true; m_limiter_timer_active = true;
m_limiter_timer.expires_from_now(milliseconds(250)); m_limiter_timer.expires_from_now(milliseconds(250), ec);
m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth
, shared_from_this(), _1)); , shared_from_this(), _1));
} }