diff --git a/Lib/socket.py b/Lib/socket.py index 833a456b4fd..0daeadcb348 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -307,6 +307,17 @@ def readline(self, size=-1): data = self._rbuf if size < 0: # Read until \n or EOF, whichever comes first + if self._rbufsize <= 1: + # Speed up unbuffered case + assert data == "" + buffers = [] + recv = self._sock.recv + while data != "\n": + data = recv(1) + if not data: + break + buffers.append(data) + return "".join(buffers) nl = data.find('\n') if nl >= 0: nl += 1