STINNER Victor added the comment: recvall.patch: implement socket.socket.recvall() in pure Python.
It raises a new socket.IncompleteReadError (copied from asyncio) exception if the connection is closed before we got the expected number of bytes. The patch has unit tests, document the new method and the new exception. TODO: I don't like how the method handles timeout. The method must fail if it takes longer than socket.gettimeout() seconds, whereas currently the timeout is reset each time we got data from the server. If the idea of the new socket method is accepted, I will reimplement it in C. In C, it's more easy to implement the timeout as I want. In Python, the socket timeout cannot be changed temporary, because it would impact other threads which may use the same socket. I changed how socket.sendall() handle timeout in Python 3.5, it is now the maximum total duration to send all data. The timeout is no more reset each time we send a packet. Related discussion: https://mail.python.org/pipermail/python-dev/2015-April/139001.html See also the issue #23236 which adds a timeout reset each time we get data to the asyncio read() method. It will be complementary to the existing "wait(read(), timeout)" timeout method, it's for a different use case. ---------- Added file: http://bugs.python.org/file40344/recvall.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue1103213> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com