def _read_from_socket(self, length=None):
    socket_read_size = self.socket_read_size
    buf = self._buffer
    buf.seek(self.bytes_written)
    marker = 0
    try:
        while True:
            data = self._sock.recv(socket_read_size)
            if (isinstance(data, bytes) and (len(data) == 0)):
                raise socket.error(SERVER_CLOSED_CONNECTION_ERROR)
            buf.write(data)
            data_length = len(data)
            self.bytes_written += data_length
            marker += data_length
            if ((length is not None) and (length > marker)):
                continue
            break
    except socket.timeout:
        raise TimeoutError('Timeout reading from socket')
    except socket.error:
        e = sys.exc_info()[1]
        raise ConnectionError(('Error while reading from socket: %s' % (e.args,)))
def _read_from_socket(self, length=None):
    socket_read_size = self.socket_read_size
    buf = self._buffer
    buf.seek(self.bytes_written)
    marker = 0
    try:
        while True:
            data = self._sock.recv(socket_read_size)
            if (isinstance(data, bytes) and (len(data) == 0)):
                raise socket.error(SERVER_CLOSED_CONNECTION_ERROR)
            buf.write(data)
            data_length = len(data)
            self.bytes_written += data_length
            marker += data_length
            if ((length is not None) and (length > marker)):
                continue
            break
    except socket.timeout:
        raise TimeoutError('Timeout reading from socket')
    except socket.error:
        e = sys.exc_info()[1]
        raise ConnectionError(('Error while reading from socket: %s' % (e.args,)))