'Reads from the socket and appends the result to the read buffer.
Returns the number of bytes read.  Returns 0 if there is nothing
to read (i.e. the read returns EWOULDBLOCK or equivalent).  On
error closes the socket and raises an exception.'

def _read_to_buffer(self):

    while True:
        try:
            chunk = self.read_from_fd()
        except (socket.error, IOError, OSError) as e:
            if (errno_from_exception(e) == errno.EINTR):
                continue
            if self._is_connreset(e):
                self.close(exc_info=e)
                return
            self.close(exc_info=e)
            raise
        break
    if (chunk is None):
        return 0
    self._read_buffer += chunk
    self._read_buffer_size += len(chunk)
    if (self._read_buffer_size > self.max_buffer_size):
        gen_log.error('Reached    maximum    read    buffer    size')
        self.close()
        raise StreamBufferFullError('Reached    maximum    read    buffer    size')
    return len(chunk)
