From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULVzr-0005XB-Jj for qemu-devel@nongnu.org; Fri, 29 Mar 2013 05:53:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ULVzo-00045L-5v for qemu-devel@nongnu.org; Fri, 29 Mar 2013 05:53:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25929) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULVzn-00045H-Ue for qemu-devel@nongnu.org; Fri, 29 Mar 2013 05:53:16 -0400 Date: Fri, 29 Mar 2013 15:23:11 +0530 From: Amit Shah Message-ID: <20130329095311.GB14019@amit.redhat.com> References: <9b59ac17b9d0bb3972a73fed04d415f07b391936.1362505276.git.amit.shah@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9b59ac17b9d0bb3972a73fed04d415f07b391936.1362505276.git.amit.shah@redhat.com> Subject: Re: [Qemu-devel] [PATCH 03/20] char: add IOWatchPoll support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu list Cc: Anthony Liguori , Anthony Liguori On (Tue) 05 Mar 2013 [23:21:18], Amit Shah wrote: > From: Anthony Liguori > > This is a special GSource that supports CharDriverState style > poll callbacks. > > For reviewability and bisectability, this code is #if 0'd out in this > patch to avoid unused warnings since all of the functions are static. > > Signed-off-by: Anthony Liguori > Signed-off-by: Amit Shah > +static int io_channel_send_all(GIOChannel *fd, const void *_buf, int len1) > +{ > + GIOStatus status; > + gsize bytes_written; > + int len; > + const uint8_t *buf = _buf; > + > + len = len1; > + while (len > 0) { > + status = g_io_channel_write_chars(fd, (const gchar *)buf, len, > + &bytes_written, NULL); > + if (status != G_IO_STATUS_NORMAL) { > + if (status != G_IO_STATUS_AGAIN) { > + return -1; > + } It's not quite right to return -1 here; previous iterations of the while loop could have successfully written data, and (len1 - len) could be +ve. How to approach this? Convert all callers of qemu_chr_fe_write() to also pass a bytes_written param to handle this case? > + } else if (status == G_IO_STATUS_EOF) { > + break; > + } else { > + buf += bytes_written; > + len -= bytes_written; > + } > + } > + return len1 - len; > +} > +#endif > + > typedef struct { > int fd_in, fd_out; > int max_size; Amit