On Wed, Nov 23, 2022 at 09:28:14PM +0530, manish.mishra wrote: > > On 23/11/22 9:22 pm, Peter Xu wrote: > > 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? > > > sorry Peter, I did not quite understand it. Can you please give some more > details.
As Daniel pointed out, I think if we peek partially it'll go into a loop. Since we shouldn't read 0 anyway here, maybe you can directly write it as: while (true) { len = read(); if (len <= 0 && len != QIO_CHANNEL_ERR_BLOCK) { error_setg(...); return -1; } if (len == buflen) { break; } /* For either partial peek or QIO_CHANNEL_ERR_BLOCK, retry with timeout */ sleep(); } > > > > > > + 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; > > > +} > > Thanks > > Manish Mishra > -- Peter Xu