Skip to content

Commit

Permalink
Fix hs.network.ping to always call didFinish callback #3530
Browse files Browse the repository at this point in the history
Right now, if the last ping packet send fails, `didFinish` is never invoked.
  • Loading branch information
earwin authored Sep 2, 2023
1 parent 0ccc9d0 commit fa7356c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions extensions/network/ping/network_ping.lua
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ module.ping = function(server, ...)
icmp = icmp,
}
internals[self].callback(self, msg, seq, err)
if internals[self].allSent then basicPingCompletionFunction(self) end
elseif msg == "receivedPacket" then
local icmp, seq = ...
internals[self].packets[seq + 1].recv = timer.secondsSinceEpoch()
Expand All @@ -496,9 +497,9 @@ module.ping = function(server, ...)
internals[self].pingTimer = timer.doEvery(interval, function()
if not internals[self].paused then
if internals[self].sentCount < internals[self].maxCount then
internals[self].pingObject:sendPayload()
internals[self].sentCount = internals[self].sentCount + 1
if internals[self].sentCount == internals[self].maxCount then internals[self].allSent = true end
internals[self].allSent = internals[self].sentCount == internals[self].maxCount
internals[self].pingObject:sendPayload()
else
internals[self].pingTimer:stop()
internals[self].pingTimer = nil
Expand Down

0 comments on commit fa7356c

Please sign in to comment.