From 79b0f677600bc65749dc6f55be8156830018d935 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Wed, 12 Dec 2007 20:23:31 +0000 Subject: [PATCH] lt bug fixes --- libtorrent/include/libtorrent/bandwidth_manager.hpp | 2 +- libtorrent/src/http_connection.cpp | 12 +++++++++++- libtorrent/src/http_tracker_connection.cpp | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libtorrent/include/libtorrent/bandwidth_manager.hpp b/libtorrent/include/libtorrent/bandwidth_manager.hpp index ecb065a9d..da251cf4b 100644 --- a/libtorrent/include/libtorrent/bandwidth_manager.hpp +++ b/libtorrent/include/libtorrent/bandwidth_manager.hpp @@ -111,7 +111,7 @@ struct bandwidth_limit void assign(int amount) throw() { - TORRENT_ASSERT(amount > 0); + TORRENT_ASSERT(amount >= 0); m_current_rate += amount; m_quota_left += amount; } diff --git a/libtorrent/src/http_connection.cpp b/libtorrent/src/http_connection.cpp index a0d8e3fa3..a73d0a9af 100644 --- a/libtorrent/src/http_connection.cpp +++ b/libtorrent/src/http_connection.cpp @@ -284,7 +284,17 @@ void http_connection::on_read(asio::error_code const& e { libtorrent::buffer::const_interval rcv_buf(&m_recvbuffer[0] , &m_recvbuffer[0] + m_read_pos); - m_parser.incoming(rcv_buf); + try + { + m_parser.incoming(rcv_buf); + } + catch (std::exception& e) + { + m_timer.cancel(); + m_handler(asio::error::fault, m_parser, 0, 0); + m_handler.clear(); + return; + } if (!m_bottled && m_parser.header_finished()) { if (m_read_pos > m_parser.body_start()) diff --git a/libtorrent/src/http_tracker_connection.cpp b/libtorrent/src/http_tracker_connection.cpp index 86d21e494..b9581e862 100755 --- a/libtorrent/src/http_tracker_connection.cpp +++ b/libtorrent/src/http_tracker_connection.cpp @@ -217,7 +217,11 @@ namespace libtorrent char dummy; std::string bytes; size_type range_start, range_end; - range_str >> bytes >> range_start >> dummy >> range_end; + // apparently some web servers do not send the "bytes" + // in their content-range + if (value.find(' ') != std::string::npos) + range_str >> bytes; + range_str >> range_start >> dummy >> range_end; if (!range_str || range_end < range_start) { throw std::runtime_error("invalid content-range in HTTP response: " + range_str.str());