qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Anthony Liguori <aliguori@us.ibm.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] char: introduce a blocking version of qemu_chr_fe_write
Date: Wed, 27 Mar 2013 15:21:37 +0800	[thread overview]
Message-ID: <51529E01.8030302@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAFEAcA9BFADJi2dODJ4rn6_4O-JBu_KKT-S6drgimj7xCXU1Cw@mail.gmail.com>

于 2013-3-26 23:21, Peter Maydell 写道:
> On 26 March 2013 15:11, Anthony Liguori <aliguori@us.ibm.com> wrote:
>> +int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len)
>> +{
>> +    int offset = 0;
>> +    int res;
>> +
>> +    while (offset < len) {
>> +        do {
>> +            res = s->chr_write(s, buf + offset, len - offset);
>> +            if (res == -1 && errno == EAGAIN) {
>> +                g_usleep(100);
>> +            }
>> +        } while (res == -1 && errno == EAGAIN);
>
>     for (;;) {
>         res = s->chr_write(s, buf + offset, len - offset);
>         if (!(res == -1 && errno == EAGAIN)) {
>             break;
>         }
>         g_usleep(100);
>     }
>
> would avoid the duplication of the retry condition.
>
> -- PMM
>
I think adjust like following make code easier to read:

     while (offset < len) {
         res = s->chr_write(s, buf + offset, len - offset);
         if (res == -1 && errno == EAGAIN) {
                 g_usleep(100)
                 continue;
         }
         .....
     }
-- 
Best Regards

Wenchao Xia

  reply	other threads:[~2013-03-27  7:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-26 15:11 [Qemu-devel] [PATCH 1/2] char: introduce a blocking version of qemu_chr_fe_write Anthony Liguori
2013-03-26 15:11 ` [Qemu-devel] [PATCH 2/2] qtest: use synchronous I/O for char device Anthony Liguori
2013-03-27  7:22   ` Wenchao Xia
2013-03-26 15:21 ` [Qemu-devel] [PATCH 1/2] char: introduce a blocking version of qemu_chr_fe_write Peter Maydell
2013-03-27  7:21   ` Wenchao Xia [this message]
2013-03-27 21:15 ` Anthony Liguori
2013-03-27 22:05   ` Peter Maydell
2013-03-27 23:01     ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51529E01.8030302@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).