1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-09 13:50:00 +00:00

fix: use correct time to determine write buffer size (#6414)

This commit is contained in:
Yat Ho 2023-12-23 23:28:43 +08:00 committed by GitHub
parent 7c9e04d035
commit fe95914558
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1860,7 +1860,7 @@ namespace peer_pulse_helpers
return {}; return {};
} }
[[nodiscard]] size_t fill_output_buffer(tr_peerMsgsImpl* msgs, time_t now) [[nodiscard]] size_t fill_output_buffer(tr_peerMsgsImpl* msgs, time_t now_sec, uint64_t now_msec)
{ {
auto n_bytes_written = size_t{}; auto n_bytes_written = size_t{};
@ -1879,14 +1879,14 @@ namespace peer_pulse_helpers
for (;;) for (;;)
{ {
auto const old_len = n_bytes_written; auto const old_len = n_bytes_written;
n_bytes_written += add_next_piece(msgs, now); n_bytes_written += add_next_piece(msgs, now_msec);
if (old_len == n_bytes_written) if (old_len == n_bytes_written)
{ {
break; break;
} }
} }
if (msgs != nullptr && msgs->clientSentAnythingAt != 0 && now - msgs->clientSentAnythingAt > KeepaliveIntervalSecs) if (msgs != nullptr && msgs->clientSentAnythingAt != 0 && now_sec - msgs->clientSentAnythingAt > KeepaliveIntervalSecs)
{ {
n_bytes_written += protocol_send_keepalive(msgs); n_bytes_written += protocol_send_keepalive(msgs);
} }
@ -1900,15 +1900,16 @@ void peerPulse(void* vmsgs)
using namespace peer_pulse_helpers; using namespace peer_pulse_helpers;
auto* msgs = static_cast<tr_peerMsgsImpl*>(vmsgs); auto* msgs = static_cast<tr_peerMsgsImpl*>(vmsgs);
auto const now = tr_time(); auto const now_sec = tr_time();
auto const now_msec = tr_time_msec();
updateDesiredRequestCount(msgs); updateDesiredRequestCount(msgs);
updateBlockRequests(msgs); updateBlockRequests(msgs);
updateMetadataRequests(msgs, now); updateMetadataRequests(msgs, now_sec);
for (;;) for (;;)
{ {
if (fill_output_buffer(msgs, now) == 0U) if (fill_output_buffer(msgs, now_sec, now_msec) == 0U)
{ {
break; break;
} }