From 8839722becdf3517ee90bc67a4e2c5b1b713fc0a Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Fri, 14 Oct 2016 14:12:02 -0600 Subject: [PATCH] minor http related code cleanup (#1212) --- include/libtorrent/http_parser.hpp | 2 +- src/bt_peer_connection.cpp | 4 ++-- src/http_connection.cpp | 4 ++-- src/http_parser.cpp | 29 +++++++++++++---------------- src/http_seed_connection.cpp | 2 +- src/http_tracker_connection.cpp | 2 -- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/include/libtorrent/http_parser.hpp b/include/libtorrent/http_parser.hpp index 2736f6fee..dddf8281e 100644 --- a/include/libtorrent/http_parser.hpp +++ b/include/libtorrent/http_parser.hpp @@ -119,7 +119,7 @@ namespace libtorrent bool connection_close() const { return m_connection_close; } std::multimap const& headers() const { return m_header; } - std::vector > const& chunks() const { return m_chunked_ranges; } + std::vector> const& chunks() const { return m_chunked_ranges; } private: std::int64_t m_recv_pos = 0; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index a99c6f55e..9bee9033f 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -497,7 +497,7 @@ namespace libtorrent #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) namespace { - char random_byte() { return random(0xff); } + char random_byte() { return char(random(0xff)); } } void bt_peer_connection::write_pe1_2_dhkey() @@ -2572,7 +2572,7 @@ namespace libtorrent int sub_transferred = 0; while (bytes_transferred > 0 && - ((sub_transferred = int(m_recv_buffer.advance_pos(int(bytes_transferred)))) > 0)) + ((sub_transferred = m_recv_buffer.advance_pos(int(bytes_transferred))) > 0)) { #if TORRENT_USE_ASSERTS std::int64_t cur_payload_dl = m_statistics.last_payload_downloaded(); diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 16fc9735d..5971725a9 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -395,7 +395,7 @@ void http_connection::start(std::string const& hostname, int port || ps->type == settings_pack::socks5_pw)) { m_hostname = hostname; - m_port = port; + m_port = std::uint16_t(port); m_endpoints.push_back(tcp::endpoint(address(), port)); connect(); } @@ -407,7 +407,7 @@ void http_connection::start(std::string const& hostname, int port , me, _1, _2)); } m_hostname = hostname; - m_port = port; + m_port = std::uint16_t(port); } } diff --git a/src/http_parser.cpp b/src/http_parser.cpp index 93fdf396e..d8215d37f 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -218,8 +218,8 @@ restart_response: while (newline != recv_buffer.end() && m_state == read_header) { - // if the LF character is preceeded by a CR - // charachter, don't copy it into the line string. + // if the LF character is preceded by a CR + // character, don't copy it into the line string. char const* line_end = newline; if (pos != line_end && *(line_end - 1) == '\r') --line_end; line.assign(pos, line_end); @@ -473,8 +473,8 @@ restart_response: std::string line; while (newline != buf.end()) { - // if the LF character is preceeded by a CR - // charachter, don't copy it into the line string. + // if the LF character is preceded by a CR + // character, don't copy it into the line string. char const* line_end = newline; if (pos != line_end && *(line_end - 1) == '\r') --line_end; line.assign(pos, line_end); @@ -492,11 +492,10 @@ restart_response: // the newline alone is two bytes TORRENT_ASSERT(newline - buf.data() > 2); - // we were successfull in parsing the headers. + // we were successful in parsing the headers. // add them to the headers in the parser - for (std::map::const_iterator i = tail_headers.begin(); - i != tail_headers.end(); ++i) - m_header.insert(std::make_pair(i->first, i->second)); + for (auto const& p : tail_headers) + m_header.insert(p); return true; } @@ -561,15 +560,13 @@ restart_response: // buffer, not start of the body, so subtract the size // of the HTTP header from them int const offset = body_start(); - std::vector > const& c = chunks(); - for (std::vector >::const_iterator i = c.begin() - , end(c.end()); i != end; ++i) + for (auto const& i : chunks()) { - TORRENT_ASSERT(i->second - i->first < (std::numeric_limits::max)()); - TORRENT_ASSERT(i->second - offset <= size); - int len = int(i->second - i->first); - if (i->first - offset + len > size) len = size - int(i->first) + offset; - memmove(write_ptr, buffer + i->first - offset, len); + TORRENT_ASSERT(i.second - i.first < (std::numeric_limits::max)()); + TORRENT_ASSERT(i.second - offset <= size); + int len = int(i.second - i.first); + if (i.first - offset + len > size) len = size - int(i.first) + offset; + std::memmove(write_ptr, buffer + i.first - offset, len); write_ptr += len; } size = write_ptr - buffer; diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index d145d5741..555d61996 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -412,7 +412,7 @@ namespace libtorrent { if (!m_parser.finished()) return; - int retry_time = atol(std::string(recv_buffer.begin(), recv_buffer.end()).c_str()); + int retry_time = std::atoi(std::string(recv_buffer.begin(), recv_buffer.end()).c_str()); if (retry_time <= 0) retry_time = 60; #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "CONNECT", "retrying in %d seconds", retry_time); diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index a869a9426..106e29aa6 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -289,7 +289,6 @@ namespace libtorrent error_code ec; tcp::endpoint ep = c.socket().remote_endpoint(ec); m_tracker_ip = ep.address(); - std::shared_ptr cb = requester(); } void http_tracker_connection::on_response(error_code const& ec @@ -493,7 +492,6 @@ namespace libtorrent #if TORRENT_USE_I2P if (0 != (flags & tracker_request::i2p)) { - error_code parse_error; for (int i = 0; i < len; i += 32) { if (len - i < 32) break;