cover edge case of receiving the response to a request before the callback of sending the request. fixes assert

This commit is contained in:
Arvid Norberg 2014-08-02 06:09:07 +00:00
parent c60ceacb71
commit 0bc2d1eb8a
1 changed files with 6 additions and 1 deletions

View File

@ -2484,7 +2484,12 @@ namespace libtorrent
if (i->receiving == false)
{
i->receiving = true;
int rtt = int(total_milliseconds(time_now_hires() - i->request_time));
// if byte_offset is greater then or equal to 0, it means
// the callback of the send operation when we sent this
// request hasn't come back yet, and we're already
// receiving the response from it. Count the rtt as 0.
int rtt = (i->byte_offset >= 0) ? 0
: int(total_milliseconds(time_now_hires() - i->request_time));
m_rtt.add_sample(rtt);
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
peer_log("*** RTT: %d ms [%d +/- %d ms]", rtt, m_rtt.mean()