From 7717c02c2f233bc5b1ab7fb6497e7f0604212862 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 17 Sep 2017 13:12:54 +0200 Subject: [PATCH] run sonarqube with deprecated functions disabled. fix some of its code smells --- .travis.yml | 2 +- include/libtorrent/block_cache.hpp | 1 - src/bandwidth_manager.cpp | 22 ++++++------- src/block_cache.cpp | 50 ------------------------------ src/path.cpp | 2 +- src/utp_stream.cpp | 34 ++++++++++---------- 6 files changed, 30 insertions(+), 81 deletions(-) diff --git a/.travis.yml b/.travis.yml index 623ea0268..a23070a1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -155,7 +155,7 @@ script: fi' - 'if [ "$sonar_scan" == "1" ]; then - build-wrapper-linux-x86-64 --out-dir bw-output bjam -a -j3 optimization=off crypto=$crypto $toolset variant=$variant -l300 && + build-wrapper-linux-x86-64 --out-dir bw-output bjam -a -j3 optimization=off crypto=$crypto deprecated-functions=off $toolset variant=$variant -l300 && sonar-scanner -D sonar.login=$SONAR_TOKEN; fi' diff --git a/include/libtorrent/block_cache.hpp b/include/libtorrent/block_cache.hpp index 880c22c16..ca708f037 100644 --- a/include/libtorrent/block_cache.hpp +++ b/include/libtorrent/block_cache.hpp @@ -485,7 +485,6 @@ namespace aux { int copy_from_piece(cached_piece_entry* p, disk_io_job* j , buffer_allocator_interface& allocator, bool expect_no_fail = false); - void free_piece(cached_piece_entry* p); int drain_piece_bufs(cached_piece_entry& p, std::vector& buf); // block container diff --git a/src/bandwidth_manager.cpp b/src/bandwidth_manager.cpp index 7119877c8..95728ef82 100644 --- a/src/bandwidth_manager.cpp +++ b/src/bandwidth_manager.cpp @@ -49,15 +49,15 @@ namespace libtorrent { { m_abort = true; - std::vector tm; - tm.swap(m_queue); + std::vector queue; + queue.swap(m_queue); m_queued_bytes = 0; - while (!tm.empty()) + while (!queue.empty()) { - bw_request& bwr = tm.back(); + bw_request& bwr = queue.back(); bwr.peer->assign_bandwidth(m_channel, bwr.assigned); - tm.pop_back(); + queue.pop_back(); } } @@ -148,7 +148,7 @@ namespace libtorrent { std::vector channels; - std::vector tm; + std::vector queue; for (auto i = m_queue.begin(); i != m_queue.end();) { @@ -165,7 +165,7 @@ namespace libtorrent { } i->assigned = 0; - tm.push_back(*i); + queue.push_back(*i); i = m_queue.erase(i); continue; } @@ -201,7 +201,7 @@ namespace libtorrent { { a += i->request_size - i->assigned; TORRENT_ASSERT(i->assigned <= i->request_size); - tm.push_back(*i); + queue.push_back(*i); i = m_queue.erase(i); } else @@ -211,11 +211,11 @@ namespace libtorrent { m_queued_bytes -= a; } - while (!tm.empty()) + while (!queue.empty()) { - bw_request& bwr = tm.back(); + bw_request& bwr = queue.back(); bwr.peer->assign_bandwidth(m_channel, bwr.assigned); - tm.pop_back(); + queue.pop_back(); } } } diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 92c9b40da..7314514ec 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -1400,56 +1400,6 @@ void block_cache::abort_dirty(cached_piece_entry* pe) update_cache_state(pe); } -// frees all buffers associated with this piece. May only -// be called for pieces with a refcount of 0 -void block_cache::free_piece(cached_piece_entry* pe) -{ - INVARIANT_CHECK; - - TORRENT_PIECE_ASSERT(pe->in_use, pe); - - TORRENT_PIECE_ASSERT(pe->refcount == 0, pe); - TORRENT_PIECE_ASSERT(pe->piece_refcount == 0, pe); - TORRENT_PIECE_ASSERT(pe->outstanding_read == 0, pe); - - // build a vector of all the buffers we need to free - // and free them all in one go - TORRENT_ALLOCA(to_delete, char*, pe->blocks_in_piece); - int num_to_delete = 0; - int removed_clean = 0; - for (int i = 0; i < pe->blocks_in_piece; ++i) - { - if (pe->blocks[i].buf == nullptr) continue; - TORRENT_PIECE_ASSERT(pe->blocks[i].pending == false, pe); - TORRENT_PIECE_ASSERT(pe->blocks[i].refcount == 0, pe); - TORRENT_PIECE_ASSERT(num_to_delete < pe->blocks_in_piece, pe); - to_delete[num_to_delete++] = pe->blocks[i].buf; - pe->blocks[i].buf = nullptr; - TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe); - --pe->num_blocks; - if (pe->blocks[i].dirty) - { - TORRENT_PIECE_ASSERT(m_write_cache_size > 0, pe); - --m_write_cache_size; - TORRENT_PIECE_ASSERT(pe->num_dirty > 0, pe); - --pe->num_dirty; - } - else - { - ++removed_clean; - } - } - - TORRENT_PIECE_ASSERT(m_read_cache_size >= removed_clean, pe); - m_read_cache_size -= removed_clean; - if (pe->cache_state == cached_piece_entry::volatile_read_lru) - { - m_volatile_size -= num_to_delete; - } - if (num_to_delete) free_multiple_buffers(to_delete.first(num_to_delete)); - update_cache_state(pe); -} - int block_cache::drain_piece_bufs(cached_piece_entry& p, std::vector& buf) { int const piece_size = p.storage->files().piece_size(p.piece); diff --git a/src/path.cpp b/src/path.cpp index 010bede09..d9e8806cb 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -301,7 +301,7 @@ namespace libtorrent { && GetLastError() != ERROR_ALREADY_EXISTS) ec.assign(GetLastError(), system_category()); #else - int ret = ::mkdir(n.c_str(), 0777); + int ret = ::mkdir(n.c_str(), S_IRWXU | S_IRGRP | S_IROTH); if (ret < 0 && errno != EEXIST) ec.assign(errno, system_category()); #endif diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 05dce6d63..ef5846d3a 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -295,7 +295,7 @@ struct utp_socket_impl bool test_socket_state(); void maybe_trigger_receive_callback(); void maybe_trigger_send_callback(); - bool cancel_handlers(error_code const& ec, bool kill); + bool cancel_handlers(error_code const& ec, bool shutdown); bool consume_incoming_data( utp_header const* ph, std::uint8_t const* ptr, int payload_size, time_point now); void update_mtu_limits(); @@ -881,18 +881,18 @@ void utp_stream::on_close_reason(void* self, close_reason_t reason) } void utp_stream::on_read(void* self, std::size_t const bytes_transferred - , error_code const& ec, bool const kill) + , error_code const& ec, bool const shutdown) { utp_stream* s = static_cast(self); - UTP_LOGV("%8p: calling read handler read:%d ec:%s kill:%d\n", static_cast(s->m_impl) - , int(bytes_transferred), ec.message().c_str(), kill); + UTP_LOGV("%8p: calling read handler read:%d ec:%s shutdown:%d\n", static_cast(s->m_impl) + , int(bytes_transferred), ec.message().c_str(), shutdown); TORRENT_ASSERT(s->m_read_handler); TORRENT_ASSERT(bytes_transferred > 0 || ec || s->m_impl->m_null_buffers); s->m_io_service.post(std::bind(std::move(s->m_read_handler), ec, bytes_transferred)); s->m_read_handler = nullptr; - if (kill && s->m_impl) + if (shutdown && s->m_impl) { TORRENT_ASSERT(ec); detach_utp_impl(s->m_impl); @@ -901,19 +901,19 @@ void utp_stream::on_read(void* self, std::size_t const bytes_transferred } void utp_stream::on_write(void* self, std::size_t const bytes_transferred - , error_code const& ec, bool const kill) + , error_code const& ec, bool const shutdown) { utp_stream* s = static_cast(self); - UTP_LOGV("%8p: calling write handler written:%d ec:%s kill:%d\n" + UTP_LOGV("%8p: calling write handler written:%d ec:%s shutdown:%d\n" , static_cast(s->m_impl) - , int(bytes_transferred), ec.message().c_str(), kill); + , int(bytes_transferred), ec.message().c_str(), shutdown); TORRENT_ASSERT(s->m_write_handler); TORRENT_ASSERT(bytes_transferred > 0 || ec); s->m_io_service.post(std::bind(std::move(s->m_write_handler), ec, bytes_transferred)); s->m_write_handler = nullptr; - if (kill && s->m_impl) + if (shutdown && s->m_impl) { TORRENT_ASSERT(ec); detach_utp_impl(s->m_impl); @@ -921,18 +921,18 @@ void utp_stream::on_write(void* self, std::size_t const bytes_transferred } } -void utp_stream::on_connect(void* self, error_code const& ec, bool kill) +void utp_stream::on_connect(void* self, error_code const& ec, bool shutdown) { utp_stream* s = static_cast(self); TORRENT_ASSERT(s); - UTP_LOGV("%8p: calling connect handler ec:%s kill:%d\n" - , static_cast(s->m_impl), ec.message().c_str(), kill); + UTP_LOGV("%8p: calling connect handler ec:%s shutdown:%d\n" + , static_cast(s->m_impl), ec.message().c_str(), shutdown); TORRENT_ASSERT(s->m_connect_handler); s->m_io_service.post(std::bind(std::move(s->m_connect_handler), ec)); s->m_connect_handler = nullptr; - if (kill && s->m_impl) + if (shutdown && s->m_impl) { TORRENT_ASSERT(ec); detach_utp_impl(s->m_impl); @@ -2396,7 +2396,7 @@ void utp_socket_impl::incoming(std::uint8_t const* buf, int size, packet_ptr p check_receive_buffers(); } -bool utp_socket_impl::cancel_handlers(error_code const& ec, bool kill) +bool utp_socket_impl::cancel_handlers(error_code const& ec, bool shutdown) { INVARIANT_CHECK; @@ -2413,9 +2413,9 @@ bool utp_socket_impl::cancel_handlers(error_code const& ec, bool kill) m_write_handler = false; m_connect_handler = false; - if (read) utp_stream::on_read(m_userdata, 0, ec, kill); - if (write) utp_stream::on_write(m_userdata, 0, ec, kill); - if (connect) utp_stream::on_connect(m_userdata, ec, kill); + if (read) utp_stream::on_read(m_userdata, 0, ec, shutdown); + if (write) utp_stream::on_write(m_userdata, 0, ec, shutdown); + if (connect) utp_stream::on_connect(m_userdata, ec, shutdown); return ret; }