Merge pull request #4489

00901e9c epee: initialize a few data members where it seems to be appropriate (moneromooo-monero)
144a6c32 abstract_tcp_server2: move m_period to subclass (moneromooo-monero)
758d7684 connection_basic: remove unused floating time start time (moneromooo-monero)
e5108a29 Catch more exceptions in dtors (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2018-10-15 13:37:18 +02:00
commit 5ccd3d32b4
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
22 changed files with 53 additions and 17 deletions

View file

@ -147,7 +147,8 @@ namespace misc_utils
{} {}
~call_befor_die() ~call_befor_die()
{ {
m_func(); try { m_func(); }
catch (...) { /* ignore */ }
} }
}; };

View file

@ -246,7 +246,6 @@ namespace net_utils
m_timer(io_serice) m_timer(io_serice)
{} {}
boost::asio::deadline_timer m_timer; boost::asio::deadline_timer m_timer;
uint64_t m_period;
}; };
template <class t_handler> template <class t_handler>
@ -262,25 +261,27 @@ namespace net_utils
{ {
return m_handler(); return m_handler();
} }
uint64_t m_period;
}; };
template<class t_handler> template<class t_handler>
bool add_idle_handler(t_handler t_callback, uint64_t timeout_ms) bool add_idle_handler(t_handler t_callback, uint64_t timeout_ms)
{ {
boost::shared_ptr<idle_callback_conext_base> ptr(new idle_callback_conext<t_handler>(io_service_, t_callback, timeout_ms)); boost::shared_ptr<idle_callback_conext<t_handler>> ptr(new idle_callback_conext<t_handler>(io_service_, t_callback, timeout_ms));
//needed call handler here ?... //needed call handler here ?...
ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period)); ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period));
ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler, this, ptr)); ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
return true; return true;
} }
bool global_timer_handler(/*const boost::system::error_code& err, */boost::shared_ptr<idle_callback_conext_base> ptr) template<class t_handler>
bool global_timer_handler(/*const boost::system::error_code& err, */boost::shared_ptr<idle_callback_conext<t_handler>> ptr)
{ {
//if handler return false - he don't want to be called anymore //if handler return false - he don't want to be called anymore
if(!ptr->call_handler()) if(!ptr->call_handler())
return true; return true;
ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period)); ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period));
ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler, this, ptr)); ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
return true; return true;
} }

View file

@ -92,7 +92,6 @@ class connection_basic { // not-templated base class for rapid developmet of som
critical_section m_send_que_lock; critical_section m_send_que_lock;
std::list<std::string> m_send_que; std::list<std::string> m_send_que;
volatile bool m_is_multithreaded; volatile bool m_is_multithreaded;
double m_start_time;
/// Strand to ensure the connection's handlers are not called concurrently. /// Strand to ensure the connection's handlers are not called concurrently.
boost::asio::io_service::strand strand_; boost::asio::io_service::strand strand_;
/// Socket for the connection. /// Socket for the connection.
@ -112,8 +111,6 @@ class connection_basic { // not-templated base class for rapid developmet of som
void logger_handle_net_write(size_t size); // network data written void logger_handle_net_write(size_t size); // network data written
void logger_handle_net_read(size_t size); // network data read void logger_handle_net_read(size_t size); // network data read
void set_start_time();
// config for rate limit // config for rate limit
static void set_rate_up_limit(uint64_t limit); static void set_rate_up_limit(uint64_t limit);

View file

@ -99,7 +99,7 @@ public:
size_t get_connections_count(); size_t get_connections_count();
void set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*) = NULL); void set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*) = NULL);
async_protocol_handler_config():m_pcommands_handler(NULL), m_pcommands_handler_destroy(NULL), m_max_packet_size(LEVIN_DEFAULT_MAX_PACKET_SIZE) async_protocol_handler_config():m_pcommands_handler(NULL), m_pcommands_handler_destroy(NULL), m_max_packet_size(LEVIN_DEFAULT_MAX_PACKET_SIZE), m_invoke_timeout(LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
{} {}
~async_protocol_handler_config() { set_handler(NULL, NULL); } ~async_protocol_handler_config() { set_handler(NULL, NULL); }
void del_out_connections(size_t count); void del_out_connections(size_t count);
@ -272,6 +272,8 @@ public:
m_wait_count = 0; m_wait_count = 0;
m_oponent_protocol_ver = 0; m_oponent_protocol_ver = 0;
m_connection_initialized = false; m_connection_initialized = false;
m_invoke_buf_ready = 0;
m_invoke_result_code = LEVIN_ERROR_CONNECTION;
} }
virtual ~async_protocol_handler() virtual ~async_protocol_handler()
{ {

View file

@ -250,22 +250,15 @@ void connection_basic::sleep_before_packet(size_t packet_size, int phase, int q
} }
} }
void connection_basic::set_start_time() {
CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out );
m_start_time = network_throttle_manager::get_global_throttle_out().get_time_seconds();
}
void connection_basic::do_send_handler_write(const void* ptr , size_t cb ) { void connection_basic::do_send_handler_write(const void* ptr , size_t cb ) {
// No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write // No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write
MTRACE("handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)"); MTRACE("handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)");
set_start_time();
} }
void connection_basic::do_send_handler_write_from_queue( const boost::system::error_code& e, size_t cb, int q_len ) { void connection_basic::do_send_handler_write_from_queue( const boost::system::error_code& e, size_t cb, int q_len ) {
// No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write // No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write
MTRACE("handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)"); MTRACE("handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)");
set_start_time();
} }
void connection_basic::logger_handle_net_read(size_t size) { // network data read void connection_basic::logger_handle_net_read(size_t size) { // network data read

View file

@ -146,6 +146,7 @@ network_throttle::network_throttle(const std::string &nameshort, const std::stri
m_network_add_cost = 128; m_network_add_cost = 128;
m_network_minimal_segment = 256; m_network_minimal_segment = 256;
m_network_max_segment = 1024*1024; m_network_max_segment = 1024*1024;
m_start_time = 0;
m_any_packet_yet = false; m_any_packet_yet = false;
m_slot_size = 1.0; // hard coded in few places m_slot_size = 1.0; // hard coded in few places
m_target_speed = 16 * 1024; // other defaults are probably defined in the command-line parsing code when this class is used e.g. as main global throttle m_target_speed = 16 * 1024; // other defaults are probably defined in the command-line parsing code when this class is used e.g. as main global throttle

View file

@ -51,11 +51,19 @@ threadpool::threadpool(unsigned int max_threads) : running(true), active(0) {
} }
threadpool::~threadpool() { threadpool::~threadpool() {
try
{ {
const boost::unique_lock<boost::mutex> lock(mutex); const boost::unique_lock<boost::mutex> lock(mutex);
running = false; running = false;
has_work.notify_all(); has_work.notify_all();
} }
catch (...)
{
// if the lock throws, we're just do it without a lock and hope,
// since the alternative is terminate
running = false;
has_work.notify_all();
}
for (size_t i = 0; i<threads.size(); i++) { for (size_t i = 0; i<threads.size(); i++) {
try { threads[i].join(); } try { threads[i].join(); }
catch (...) { /* ignore */ } catch (...) { /* ignore */ }
@ -91,11 +99,13 @@ unsigned int threadpool::get_max_concurrency() const {
threadpool::waiter::~waiter() threadpool::waiter::~waiter()
{ {
try
{ {
boost::unique_lock<boost::mutex> lock(mt); boost::unique_lock<boost::mutex> lock(mt);
if (num) if (num)
MERROR("wait should have been called before waiter dtor - waiting now"); MERROR("wait should have been called before waiter dtor - waiting now");
} }
catch (...) { /* ignore */ }
try try
{ {
wait(NULL); wait(NULL);

View file

@ -35,6 +35,7 @@
#include <vector> #include <vector>
#include "warnings.h" #include "warnings.h"
#include "misc_log_ex.h"
#include "crypto/crypto.h" #include "crypto/crypto.h"
#include "crypto/hash.h" #include "crypto/hash.h"
#include "crypto-tests.h" #include "crypto-tests.h"
@ -59,6 +60,7 @@ bool operator !=(const key_derivation &a, const key_derivation &b) {
DISABLE_GCC_WARNING(maybe-uninitialized) DISABLE_GCC_WARNING(maybe-uninitialized)
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
TRY_ENTRY();
fstream input; fstream input;
string cmd; string cmd;
size_t test = 0; size_t test = 0;
@ -266,4 +268,5 @@ error:
error = true; error = true;
} }
return error ? 1 : 0; return error ? 1 : 0;
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -68,7 +68,9 @@ int Base58Fuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
Base58Fuzzer fuzzer; Base58Fuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -61,6 +61,8 @@ int BlockFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
BlockFuzzer fuzzer; BlockFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -65,6 +65,8 @@ int BulletproofFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
BulletproofFuzzer fuzzer; BulletproofFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -95,7 +95,9 @@ int ColdOutputsFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
ColdOutputsFuzzer fuzzer; ColdOutputsFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -97,6 +97,8 @@ int ColdTransactionFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
ColdTransactionFuzzer fuzzer; ColdTransactionFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -92,7 +92,9 @@ int HTTPClientFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
HTTPClientFuzzer fuzzer; HTTPClientFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -341,7 +341,9 @@ int LevinFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
LevinFuzzer fuzzer; LevinFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -70,7 +70,9 @@ int PortableStorageFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
PortableStorageFuzzer fuzzer; PortableStorageFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -70,7 +70,9 @@ int PortableStorageFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
PortableStorageFuzzer fuzzer; PortableStorageFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -68,7 +68,9 @@ int ParseURLFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
ParseURLFuzzer fuzzer; ParseURLFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -92,6 +92,8 @@ int SignatureFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
SignatureFuzzer fuzzer; SignatureFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -61,6 +61,8 @@ int TransactionFuzzer::run(const std::string &filename)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
TRY_ENTRY();
TransactionFuzzer fuzzer; TransactionFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer); return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -629,6 +629,7 @@ TEST_F(net_load_test_clt, permament_open_and_close_and_connections_closed_by_ser
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
TRY_ENTRY();
tools::on_startup(); tools::on_startup();
epee::debug::get_set_enable_assert(true, false); epee::debug::get_set_enable_assert(true, false);
//set up logging options //set up logging options
@ -636,4 +637,5 @@ int main(int argc, char** argv)
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
CATCH_ENTRY_L0("main", 1);
} }

View file

@ -216,6 +216,7 @@ namespace
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
TRY_ENTRY();
tools::on_startup(); tools::on_startup();
//set up logging options //set up logging options
mlog_configure(mlog_get_default_log_path("net_load_tests_srv.log"), true); mlog_configure(mlog_get_default_log_path("net_load_tests_srv.log"), true);
@ -234,4 +235,5 @@ int main(int argc, char** argv)
if (!tcp_server.run_server(thread_count, true)) if (!tcp_server.run_server(thread_count, true))
return 2; return 2;
return 0; return 0;
CATCH_ENTRY_L0("main", 1);
} }