From e7d369646d708adc4351e7f3fda89053d23f8a84 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 18 May 2015 01:30:32 +0000 Subject: [PATCH] fix gcc warnings --- include/libtorrent/alert.hpp | 11 +++- include/libtorrent/alert_types.hpp | 80 ++++++++++-------------------- include/libtorrent/bitfield.hpp | 7 ++- include/libtorrent/pe_crypto.hpp | 4 +- include/libtorrent/udp_socket.hpp | 2 +- src/broadcast_socket.cpp | 38 +++++++------- src/http_tracker_connection.cpp | 19 ++++--- src/kademlia/dht_tracker.cpp | 8 --- src/pe_crypto.cpp | 5 +- src/udp_socket.cpp | 2 + src/udp_tracker_connection.cpp | 5 +- src/upnp.cpp | 7 ++- src/utp_socket_manager.cpp | 12 +++-- src/utp_stream.cpp | 2 +- 14 files changed, 98 insertions(+), 104 deletions(-) diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index d0374ede5..b5f841f54 100644 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -260,13 +260,20 @@ namespace libtorrent { // when the alert queue is full. There are a few alerts which may not be discared, // since they would break the user contract, such as save_resume_data_alert. TORRENT_DEPRECATED - virtual bool discardable() const { return true; } + bool discardable() const { return discardable_impl(); } TORRENT_DEPRECATED severity_t severity() const { return warning; } // returns a pointer to a copy of the alert. - virtual std::auto_ptr clone() const = 0; + TORRENT_DEPRECATED + std::auto_ptr clone() const { return clone_impl(); } + + protected: + + virtual bool discardable_impl() const { return true; } + + virtual std::auto_ptr clone_impl() const = 0; #endif private: diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 5ad81b0bf..4e60e1cc4 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -143,10 +143,13 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE #define TORRENT_CLONE(name) \ - virtual std::auto_ptr clone() const \ + virtual std::auto_ptr clone_impl() const TORRENT_OVERRIDE \ { return std::auto_ptr(new name(*this)); } + #define TORRENT_NOT_DISCARDABLE \ + virtual bool discardable_impl() TORRENT_OVERRIDE { return false; } #else #define TORRENT_CLONE(name) + #define TORRENT_NOT_DISCARDABLE #endif #define TORRENT_DEFINE_ALERT_IMPL(name, seq, prio) \ @@ -198,9 +201,7 @@ namespace libtorrent TORRENT_DEFINE_ALERT_PRIO(torrent_removed_alert, 4) static const int static_category = alert::status_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE sha1_hash info_hash; }; @@ -212,7 +213,7 @@ namespace libtorrent // number of bytes that was read. // // If the operation fails, ec will indicat what went wrong. - struct TORRENT_EXPORT read_piece_alert: torrent_alert + struct TORRENT_EXPORT read_piece_alert: torrent_alert { // internal read_piece_alert(aux::stack_allocator& alloc, torrent_handle const& h @@ -223,9 +224,7 @@ namespace libtorrent static const int static_category = alert::storage_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE error_code ec; boost::shared_array buffer; @@ -263,9 +262,8 @@ namespace libtorrent static const int static_category = alert::storage_notification; virtual std::string message() const; + TORRENT_NOT_DISCARDABLE #ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } - std::string name; #endif @@ -291,9 +289,7 @@ namespace libtorrent static const int static_category = alert::storage_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // refers to the index of the file that was supposed to be renamed, // ``error`` is the error code returned from the filesystem. @@ -328,7 +324,7 @@ namespace libtorrent // is posted, there is a risk that the number of outstanding requests is too low // and limits the download rate. You might want to increase the ``max_out_request_queue`` // setting. - outstanding_request_limit_reached, + outstanding_request_limit_reached, // This warning is posted when the amount of TCP/IP overhead is greater than the // upload rate limit. When this happens, the TCP/IP overhead is caused by a much @@ -354,7 +350,7 @@ namespace libtorrent // send it all before the disk gets back to us. // The number of bytes that we keep outstanding, requested from the disk, is calculated // as follows:: - // + // // min(512, max(upload_rate * send_buffer_watermark_factor / 100, send_buffer_watermark)) // // If you receive this alert, you migth want to either increase your ``send_buffer_watermark`` @@ -967,9 +963,7 @@ namespace libtorrent static const int static_category = alert::storage_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE sha1_hash info_hash; }; @@ -988,9 +982,7 @@ namespace libtorrent | alert::error_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // tells you why it failed. error_code error; @@ -1017,9 +1009,7 @@ namespace libtorrent static const int static_category = alert::storage_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // points to the resume data. boost::shared_ptr resume_data; @@ -1039,9 +1029,7 @@ namespace libtorrent | alert::error_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // the error code from the resume_data failure error_code error; @@ -1288,9 +1276,9 @@ namespace libtorrent static const int static_category = alert::status_notification | alert::error_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } + TORRENT_NOT_DISCARDABLE +#ifndef TORRENT_NO_DEPRECATE // the interface libtorrent attempted to listen on std::string interface; #endif @@ -1331,9 +1319,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // the endpoint libtorrent ended up listening on. The address // refers to the local interface and the port is the listen port. @@ -1774,9 +1760,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE error_code error; }; @@ -1832,9 +1816,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // a copy of the parameters used when adding the torrent, it can be used // to identify which invocation to ``async_add_torrent()`` caused this alert. @@ -1858,9 +1840,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // contains the torrent status of all torrents that changed since last // time this message was posted. Note that you can map a torrent status @@ -1893,9 +1873,8 @@ namespace libtorrent static const int static_category = alert::stats_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + + TORRENT_NOT_DISCARDABLE // An array are a mix of *counters* and *gauges*, which meanings can be // queries via the session_stats_metrics() function on the session. The @@ -1926,9 +1905,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // ``old_ih`` and ``new_ih`` are the previous and new info-hash for the torrent, respectively. sha1_hash old_ih; @@ -1996,9 +1973,7 @@ namespace libtorrent | alert::dht_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + TORRENT_NOT_DISCARDABLE // the target hash of the immutable item. This must // match the sha-1 hash of the bencoded form of ``item``. @@ -2024,9 +1999,8 @@ namespace libtorrent static const int static_category = alert::error_notification | alert::dht_notification; virtual std::string message() const; -#ifndef TORRENT_NO_DEPRECATE - virtual bool discardable() const { return false; } -#endif + + TORRENT_NOT_DISCARDABLE // the public key that was looked up boost::array key; diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index a71f08fc4..e87e2ec98 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -100,7 +100,7 @@ namespace libtorrent TORRENT_ASSERT(index < size()); return (m_buf[index / 32] & htonl((0x80000000 >> (index & 31)))) != 0; } - + // set bit at ``index`` to 0 (clear_bit) or 1 (set_bit). void clear_bit(int index) { @@ -159,6 +159,11 @@ namespace libtorrent // returns a pointer to the internal buffer of the bitfield. char const* data() const { return reinterpret_cast(m_buf); } +#ifndef TORRENT_NO_DEPRECATE + TORRENT_DEPRECATED + char const* bytes() const { return data(); } +#endif + // copy operator bitfield& operator=(bitfield const& rhs) { diff --git a/include/libtorrent/pe_crypto.hpp b/include/libtorrent/pe_crypto.hpp index cbfd1b57e..ac4d8dbe1 100644 --- a/include/libtorrent/pe_crypto.hpp +++ b/include/libtorrent/pe_crypto.hpp @@ -72,7 +72,7 @@ namespace libtorrent char const* get_secret() const { return m_dh_shared_secret; } sha1_hash const& get_hash_xor_mask() const { return m_xor_mask; } - + private: int get_local_key_size() const @@ -126,7 +126,7 @@ namespace libtorrent // Input keys must be 20 bytes void set_incoming_key(unsigned char const* key, int len) TORRENT_OVERRIDE; void set_outgoing_key(unsigned char const* key, int len) TORRENT_OVERRIDE; - + int encrypt(std::vector& buf) TORRENT_OVERRIDE; void decrypt(std::vector& buf , int& consume diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index c6a6b118b..4f155d637 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -151,7 +151,7 @@ namespace libtorrent { return m_v4_outstanding #if TORRENT_USE_IPV6 - + m_v6_outstanding + + m_v6_outstanding #endif ; } diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index 5e034fa17..2c983f0a4 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -242,13 +242,14 @@ namespace libtorrent && !defined TORRENT_MINGW if (i->interface_address.is_v6() && - i->interface_address.to_v6().is_link_local()) { + i->interface_address.to_v6().is_link_local()) + { address_v6 addr6 = i->interface_address.to_v6(); addr6.scope_id(if_nametoindex(i->name)); open_multicast_socket(ios, addr6, loopback, ec); - address_v4 const& mask = i->netmask.is_v4() ? - i->netmask.to_v4() : address_v4(); + address_v4 const& mask = i->netmask.is_v4() + ? i->netmask.to_v4() : address_v4(); open_unicast_socket(ios, addr6, mask); continue; } @@ -324,11 +325,13 @@ namespace libtorrent void broadcast_socket::send(char const* buffer, int size, error_code& ec, int flags) { + bool all_fail = true; + error_code e; + for (std::list::iterator i = m_unicast_sockets.begin() , end(m_unicast_sockets.end()); i != end; ++i) { if (!i->socket) continue; - error_code e; i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e); // if the user specified the broadcast flag, send one to the broadcast @@ -337,41 +340,34 @@ namespace libtorrent i->socket->send_to(asio::buffer(buffer, size) , udp::endpoint(i->broadcast_address(), m_multicast_endpoint.port()), 0, e); -#ifdef TORRENT_DEBUG -// fprintf(stderr, " sending on unicast %s to: %s\n", print_address(i->socket->local_endpoint().address()).c_str() -// , print_endpoint(m_multicast_endpoint).c_str()); -#endif if (e) { -#ifdef TORRENT_DEBUG -// fprintf(stderr, " ERROR: %s\n", e.message().c_str()); -#endif i->socket->close(e); i->socket.reset(); } + else + { + all_fail = false; + } } for (std::list::iterator i = m_sockets.begin() , end(m_sockets.end()); i != end; ++i) { if (!i->socket) continue; - error_code e; i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e); -#ifdef TORRENT_DEBUG -// extern std::string print_address(address const& addr); -// extern std::string print_endpoint(udp::endpoint const& ep); -// fprintf(stderr, " sending on multicast %s to: %s\n", print_address(i->socket->local_endpoint().address()).c_str() -// , print_endpoint(m_multicast_endpoint).c_str()); -#endif if (e) { -#ifdef TORRENT_DEBUG -// fprintf(stderr, " ERROR: %s\n", e.message().c_str()); -#endif i->socket->close(e); i->socket.reset(); } + else + { + all_fail = false; + } } + + if (all_fail) ec = e; } void broadcast_socket::on_receive(socket_entry* s, error_code const& ec diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 56f89b762..3f6d4bf32 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -96,7 +96,7 @@ namespace libtorrent } url.replace(pos, 8, "scrape"); } - + #if TORRENT_USE_I2P bool i2p = is_i2p_url(url); #else @@ -113,7 +113,7 @@ namespace libtorrent url += "&"; else url += "?"; - + if (tracker_req().kind == tracker_request::announce_request) { const char* event_string[] = {"completed", "started", "stopped", "paused"}; @@ -251,15 +251,18 @@ namespace libtorrent tracker_connection::close(); } - void http_tracker_connection::on_filter(http_connection& c, std::vector& endpoints) + // endpoints is an in-out parameter + void http_tracker_connection::on_filter(http_connection& c + , std::vector& endpoints) { + TORRENT_UNUSED(c); if (!tracker_req().filter) return; // remove endpoints that are filtered by the IP filter for (std::vector::iterator i = endpoints.begin(); i != endpoints.end();) { - if (tracker_req().filter->access(i->address()) == ip_filter::blocked) + if (tracker_req().filter->access(i->address()) == ip_filter::blocked) i = endpoints.erase(i); else ++i; @@ -295,7 +298,7 @@ namespace libtorrent fail(ec); return; } - + if (!parser.header_finished()) { fail(asio::error::eof); @@ -308,13 +311,13 @@ namespace libtorrent , parser.status_code(), parser.message().c_str()); return; } - + if (ec && ec != asio::error::eof) { fail(ec, parser.status_code()); return; } - + received_bytes(size + parser.body_start()); // handle tracker response @@ -576,7 +579,7 @@ namespace libtorrent resp.external_ip = detail::read_v6_address(p); #endif } - + return resp; } } diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 09b6e32ff..09e636827 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -122,14 +122,6 @@ namespace libtorrent { namespace dht namespace { - node_id extract_node_id(bdecode_node e) - { - if (!e || e.type() != bdecode_node::dict_t) return (node_id::min)(); - bdecode_node nid = e.dict_find_string("node-id"); - if (!nid || nid.string_length() != 20) return (node_id::min)(); - return node_id(node_id(nid.string_ptr())); - } - node_id extract_node_id(entry const* e) { if (e == 0 || e->type() != entry::dictionary_t) return (node_id::min)(); diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index 7c5923ab2..e08ea4216 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -324,7 +324,10 @@ namespace libtorrent , int& produce , int& packet_size) { + // these are out-parameters that are not set TORRENT_UNUSED(consume); + TORRENT_UNUSED(packet_size); + if (!m_decrypt) return; int bytes_processed = 0; @@ -338,7 +341,7 @@ namespace libtorrent TORRENT_ASSERT(pos); bytes_processed += len; - rc4_encrypt((unsigned char*)pos, len, &m_rc4_incoming); + rc4_encrypt(reinterpret_cast(pos), len, &m_rc4_incoming); } buf.clear(); produce = bytes_processed; diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index f39aa0166..9f79b6d60 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -248,6 +248,8 @@ void udp_socket::on_writable(error_code const& ec, udp::socket* s) #endif m_v4_write_subscribed = false; + if (ec == asio::error::operation_aborted) return; + call_writable_handler(); } diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 974c6db9a..65c07e2fe 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -326,6 +326,7 @@ namespace libtorrent bool udp_tracker_connection::on_receive_hostname(error_code const& e , char const* hostname, char const* buf, int size) { + TORRENT_UNUSED(hostname); // just ignore the hostname this came from, pretend that // it's from the same endpoint we sent it to (i.e. the same // port). We have so many other ways of confirming this packet @@ -371,7 +372,7 @@ namespace libtorrent #endif return false; } - + if (e) fail(e); #ifndef TORRENT_DISABLE_LOGGING @@ -449,7 +450,7 @@ namespace libtorrent m_man.update_transaction_id(shared_from_this(), new_tid); m_transaction_id = new_tid; } - + bool udp_tracker_connection::on_connect_response(char const* buf, int size) { // ignore packets smaller than 16 bytes diff --git a/src/upnp.cpp b/src/upnp.cpp index 06a3bb155..8bbcbb637 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -69,7 +69,6 @@ namespace upnp_errors static error_code ec; -// TODO: 3 listen_interface is not used. It's meant to bind the broadcast socket upnp::upnp(io_service& ios , address const& listen_interface, std::string const& user_agent , portmap_callback_t const& cb, log_callback_t const& lcb @@ -90,6 +89,12 @@ upnp::upnp(io_service& ios , m_last_if_update(min_time()) { TORRENT_ASSERT(cb); + +// TODO: 3 listen_interface is not used. It's meant to bind the broadcast +// socket. it would probably have to be changed to a vector of interfaces to +// bind to though, since the broadcast socket opens one socket per local +// interface by default + TORRENT_UNUSED(listen_interface); } void upnp::start(void* state) diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index b372a11a3..ac92072b5 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -166,6 +166,9 @@ namespace libtorrent void utp_socket_manager::send_packet(udp::endpoint const& ep, char const* p , int len, error_code& ec, int flags) { +#if !defined TORRENT_HAS_DONT_FRAGMENT && !defined TORRENT_DEBUG_MTU + TORRENT_UNUSED(flags); +#endif if (!m_sock.is_open()) { ec = asio::error::operation_aborted; @@ -253,6 +256,9 @@ namespace libtorrent bool utp_socket_manager::incoming_packet(error_code const& ec, udp::endpoint const& ep , char const* p, int size) { + // TODO: 2 we may want to take ec into account here. possibly close + // connections quicker + TORRENT_UNUSED(ec); // UTP_LOGV("incoming packet size:%d\n", size); if (size < int(sizeof(utp_header))) return false; @@ -264,7 +270,7 @@ namespace libtorrent if (ph->get_version() != 1) return false; const time_point receive_time = clock_type::now(); - + // parse out connection ID and look for existing // connections. If found, forward to the utp_stream. boost::uint16_t id = ph->connection_id; @@ -363,7 +369,7 @@ namespace libtorrent void utp_socket_manager::socket_drained() { // flush all deferred acks - + std::vector deferred_acks; m_deferred_acks.swap(deferred_acks); for (std::vector::iterator i = deferred_acks.begin() @@ -405,7 +411,7 @@ namespace libtorrent if (m_last_socket == i->second) m_last_socket = 0; m_utp_sockets.erase(i); } - + void utp_socket_manager::set_sock_buf(int size) { if (size < m_sock_buf_size) return; diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index fc48fbc68..37c452fc2 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -3438,7 +3438,7 @@ void utp_socket_impl::do_ledbat(const int acked_bytes, const int delay } } -void utp_stream::bind(endpoint_type const& ep, error_code& ec) { } +void utp_stream::bind(endpoint_type const&, error_code&) { } void utp_stream::cancel_handlers(error_code const& ec) {