From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WR1wb-0008M3-OY for qemu-devel@nongnu.org; Fri, 21 Mar 2014 12:05:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WR1wV-0002UE-Pp for qemu-devel@nongnu.org; Fri, 21 Mar 2014 12:05:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WR1wV-0002U8-I1 for qemu-devel@nongnu.org; Fri, 21 Mar 2014 12:05:11 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2LG5AX9032335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Mar 2014 12:05:10 -0400 From: Juan Quintela In-Reply-To: <20140321143919.GA8476@work-vm> (David Alan Gilbert's message of "Fri, 21 Mar 2014 14:39:19 +0000") References: <1395320327-16613-1-git-send-email-dgilbert@redhat.com> <871txvit1p.fsf@elfo.mitica> <20140321143919.GA8476@work-vm> Date: Fri, 21 Mar 2014 17:05:07 +0100 Message-ID: <87r45vh70s.fsf@elfo.mitica> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 1/1] Make qemu_peek_buffer loop until it gets it's data Reply-To: quintela@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" Cc: qemu-devel@nongnu.org "Dr. David Alan Gilbert" wrote: >> > + while (index >= f->buf_size) { >> > + int received = qemu_fill_buffer(f); >> > + >> > + if (received <= 0) { >> >> here, I don't know really what to do. We just need one character, so >> the 1st call to qemu_fill_buffer() gives it to us, or we are already on >> problems. i.e. no need of the while() loop. > > The problem is that peek_byte takes an offset, so while qemu_fill_buffer > will get us a byte, we actually need it to get us all the bytes upto the > offset, and that's not guaranteed from one call. that is not a problem. We never got a "hole" on the things that we ask for. We ask for the "next byte", or the "next bytes", so in qemu_peek_byte() we are guaranteed (with current users) that we would only have to read a single byte. I.e. qemu_peek_{buffer,byte}(....,offset, size) means that we have "already" peek until offset, and now we want size more bytes. Later, Juan.