关于 Python asyncio StreamReader 读取的疑惑
資深大佬 : RandomAccess 3
async def hanlder(reader, writer): data = b"" while not reader.at_eof(): _ = await reader.read(1024) data += _ ...
客户端建立了一个 TCP 链接后,发送了一个 http 请求,大小不固定,传送的 binary data 按道理是在 buffer 中,然后用 read 循环读取,判断直到 buffer is empty,然后解析请求的数据,但是实际情况是循环不退出
如果使用
async def hanlder(reader, writer): data = b"" while True: _ = await reader.read(1024) if not _: break data += _ ...
客户端主动关闭 TCP 链接后才会退出循环 在源码中 at_eof()是需要”buffer is empty and ‘feed_eof’ was called” 官方文档中关于 feed_eof()的信息基本没有,求大佬解答
大佬有話說 (1)