Make nonblock_read more flexible