From e95ca088a5923f1f9650d01ffeb4a5d99a6d513d Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Thu, 15 Jun 2023 01:22:27 +0200 Subject: [PATCH] ospfsock: Wait for the socket answer The error handling is horrible though. --- birdvisu/ospfsock.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/birdvisu/ospfsock.py b/birdvisu/ospfsock.py index b034d06..01e20a0 100644 --- a/birdvisu/ospfsock.py +++ b/birdvisu/ospfsock.py @@ -3,6 +3,7 @@ from dataclasses import dataclass,field import socket as sk from string import digits +from select import select class BirdError(Exception): def __init__(self, code, where, text): @@ -55,6 +56,10 @@ class BirdSocketConnection: code : str | None = None # string because of leading zeroes, and it has no numeric interpretation anyway start = None cont = True + # The response might not yet be ready + rrdy, wrdy, xrdy = select([self.socket], [], [], 1) + if len(rrdy) == 0: + print('WTF, no response in 1 second?') f = self.socket.makefile('r') for i, line in enumerate(f, start=1): assert cont, "WTF bad format (should not continue)."