diff options
Diffstat (limited to 'test/unit/__init__.py')
-rw-r--r-- | test/unit/__init__.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/unit/__init__.py b/test/unit/__init__.py index f9847a10a..0d0206f08 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -512,6 +512,17 @@ def readuntil2crlfs(fd): return rv +def readlength(fd, size, timeout=1.0): + buf = b'' + with eventlet.Timeout(timeout): + while len(buf) < size: + chunk = fd.read(min(64, size - len(buf))) + buf += chunk + if len(buf) >= size: + break + return buf + + def connect_tcp(hostport): rv = socket.socket() rv.connect(hostport) |