From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULYLs-00025W-0M for qemu-devel@nongnu.org; Fri, 29 Mar 2013 08:24:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ULYLq-00028O-TA for qemu-devel@nongnu.org; Fri, 29 Mar 2013 08:24:11 -0400 Received: from mail-gg0-x236.google.com ([2607:f8b0:4002:c02::236]:42347) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULYLq-00028H-Ok for qemu-devel@nongnu.org; Fri, 29 Mar 2013 08:24:10 -0400 Received: by mail-gg0-f182.google.com with SMTP id u2so16525ggn.27 for ; Fri, 29 Mar 2013 05:24:10 -0700 (PDT) From: Anthony Liguori In-Reply-To: <20130329095311.GB14019@amit.redhat.com> References: <9b59ac17b9d0bb3972a73fed04d415f07b391936.1362505276.git.amit.shah@redhat.com> <20130329095311.GB14019@amit.redhat.com> Date: Fri, 29 Mar 2013 07:24:07 -0500 Message-ID: <87fvzefl7c.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH 03/20] char: add IOWatchPoll support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amit Shah , qemu list Amit Shah writes: > 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. Once -1 is returned, it's a terminal error. It doesn't matter that we may have written some data. Regards, Anthony Liguori > > 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