qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/2] char: introduce a blocking version of qemu_


From: Wenchao Xia
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
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130307 Thunderbird/17.0.4

于 2013-3-26 23:21, Peter Maydell 写道:
On 26 March 2013 15:11, Anthony Liguori <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]