From 314f134e35b9b34608954c3bf5946c10cef21d3f Mon Sep 17 00:00:00 2001 From: Thomas Yuan Date: Mon, 31 Aug 2015 13:48:14 -0400 Subject: [PATCH] reorganize code to make it straightforward. --- src/kademlia/dht_tracker.cpp | 38 ++++++++++++------------------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index e08134afe..4322355fc 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -464,39 +464,27 @@ namespace libtorrent { namespace dht bencode(std::back_inserter(m_send_buf), e); error_code ec; - if (m_sock.send(addr, &m_send_buf[0], int(m_send_buf.size()), ec, send_flags)) - { - if (ec) - { - m_counters.inc_stats_counter(counters::dht_messages_out_dropped); -#ifndef TORRENT_DISABLE_LOGGING - m_log->log_packet(dht_logger::outgoing_message, &m_send_buf[0] - , m_send_buf.size(), addr); -#endif - return false; - } - - m_counters.inc_stats_counter(counters::dht_bytes_out, m_send_buf.size()); - // account for IP and UDP overhead - m_counters.inc_stats_counter(counters::sent_ip_overhead_bytes - , addr.address().is_v6() ? 48 : 28); - m_counters.inc_stats_counter(counters::dht_messages_out); -#ifndef TORRENT_DISABLE_LOGGING - m_log->log_packet(dht_logger::outgoing_message, &m_send_buf[0] - , m_send_buf.size(), addr); -#endif - return true; - } - else + bool ret = m_sock.send(addr, &m_send_buf[0], int(m_send_buf.size()), ec, send_flags); + if (!ret || ec) { m_counters.inc_stats_counter(counters::dht_messages_out_dropped); - #ifndef TORRENT_DISABLE_LOGGING m_log->log_packet(dht_logger::outgoing_message, &m_send_buf[0] , m_send_buf.size(), addr); #endif return false; } + + m_counters.inc_stats_counter(counters::dht_bytes_out, m_send_buf.size()); + // account for IP and UDP overhead + m_counters.inc_stats_counter(counters::sent_ip_overhead_bytes + , addr.address().is_v6() ? 48 : 28); + m_counters.inc_stats_counter(counters::dht_messages_out); +#ifndef TORRENT_DISABLE_LOGGING + m_log->log_packet(dht_logger::outgoing_message, &m_send_buf[0] + , m_send_buf.size(), addr); +#endif + return true; } }}