[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 2/2] migration: check magic value for deciding the mapping
From: |
Peter Xu |
Subject: |
Re: [PATCH v4 2/2] migration: check magic value for deciding the mapping of channels |
Date: |
Wed, 23 Nov 2022 10:52:01 -0500 |
On Wed, Nov 23, 2022 at 03:05:27PM +0000, manish.mishra wrote:
> +int migration_channel_read_peek(QIOChannel *ioc,
> + const char *buf,
> + const size_t buflen,
> + Error **errp)
> +{
> + ssize_t len = 0;
> + struct iovec iov = { .iov_base = (char *)buf, .iov_len = buflen };
> +
> + while (len < buflen) {
> + len = qio_channel_readv_full(ioc, &iov, 1, NULL,
> + NULL, QIO_CHANNEL_READ_FLAG_MSG_PEEK,
> errp);
> +
> + if (len == QIO_CHANNEL_ERR_BLOCK) {
This needs to take care of partial len too?
> + if (qemu_in_coroutine()) {
> + /* 1ms sleep. */
> + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000);
> + } else {
> + qio_channel_wait(ioc, G_IO_IN);
> + }
> + continue;
> + }
> + if (len == 0) {
> + error_setg(errp,
> + "Unexpected end-of-file on channel");
> + return -1;
> + }
> + if (len < 0) {
> + return -1;
> + }
> + }
> +
> + return 0;
> +}
--
Peter Xu