Skip to content

Commit

Permalink
Fix hs.network.ping to always call didFinish callback #3530 (#3531)
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 Dec 10, 2023
1 parent aad8b59 commit 9345f83
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 9345f83

Please sign in to comment.