separate ping from pong

this separates concerns and allows the pong_timeout to strictly handle timeouts for pongs.

patch bump
This commit is contained in:
2026-03-03 19:47:15 +00:00
parent 2dd52a7258
commit 3d01321be3
3 changed files with 23 additions and 37 deletions

View File

@@ -21,8 +21,8 @@ def ratelimit(func):
return wrapper
def ping_timeout(func):
"""ping_timeout decorator for {VbanCmd}._ping, to handle timeout logic and socket management."""
def pong_timeout(func):
"""pong_timeout decorator for {VbanCmd}._handle_pong, to handle timeout logic and socket management."""
def wrapper(self, timeout: float = None):
if timeout is None:
@@ -32,25 +32,14 @@ def ping_timeout(func):
self.sock.settimeout(0.5)
try:
func(self)
start_time = time.time()
response_count = 0
while time.time() - start_time < timeout:
try:
data, addr = self.sock.recvfrom(2048)
response_count += 1
self.logger.debug(
f'Received packet #{response_count} from {addr}: {len(data)} bytes'
)
self.logger.debug(
f'Response header: {data[: min(32, len(data))].hex()}'
)
result = func(self, data, addr)
if result is True:
if func(self):
return
except socket.timeout: