diff mbox series

[v2,20/26] io: replace qemu_set{_non}block()

Message ID 20220426092715.3931705-21-marcandre.lureau@redhat.com
State New
Headers show
Series Misc cleanups | expand

Commit Message

Marc-André Lureau April 26, 2022, 9:27 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Those calls are non-socket fd, or are POSIX-specific. Use the dedicated
GLib API. (qemu_set_nonblock() is for socket-like)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 io/channel-command.c | 16 +++++++++-------
 io/channel-file.c    | 13 +++++++++----
 2 files changed, 18 insertions(+), 11 deletions(-)

Comments

Daniel P. Berrangé May 3, 2022, 10:33 a.m. UTC | #1
On Tue, Apr 26, 2022 at 01:27:09PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Those calls are non-socket fd, or are POSIX-specific. Use the dedicated
> GLib API. (qemu_set_nonblock() is for socket-like)
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  io/channel-command.c | 16 +++++++++-------
>  io/channel-file.c    | 13 +++++++++----
>  2 files changed, 18 insertions(+), 11 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
diff mbox series

Patch

diff --git a/io/channel-command.c b/io/channel-command.c
index 0790ac7895c0..4a1f969aaa8e 100644
--- a/io/channel-command.c
+++ b/io/channel-command.c
@@ -301,16 +301,18 @@  static int qio_channel_command_set_blocking(QIOChannel *ioc,
                                             bool enabled,
                                             Error **errp)
 {
+#ifdef WIN32
+    /* command spawn is not supported on win32 */
+    g_assert_not_reached();
+#else
     QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc);
 
-    if (enabled) {
-        qemu_set_block(cioc->writefd);
-        qemu_set_block(cioc->readfd);
-    } else {
-        qemu_set_nonblock(cioc->writefd);
-        qemu_set_nonblock(cioc->readfd);
+    if (!g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL) ||
+        !g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL)) {
+        error_setg_errno(errp, errno, "Failed to set FD nonblocking");
+        return -1;
     }
-
+#endif
     return 0;
 }
 
diff --git a/io/channel-file.c b/io/channel-file.c
index d7cf6d278ff9..d146ace7db9f 100644
--- a/io/channel-file.c
+++ b/io/channel-file.c
@@ -139,14 +139,19 @@  static int qio_channel_file_set_blocking(QIOChannel *ioc,
                                          bool enabled,
                                          Error **errp)
 {
+#ifdef WIN32
+    /* not implemented */
+    error_setg_errno(errp, errno, "Failed to set FD nonblocking");
+    return -1;
+#else
     QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
 
-    if (enabled) {
-        qemu_set_block(fioc->fd);
-    } else {
-        qemu_set_nonblock(fioc->fd);
+    if (!g_unix_set_fd_nonblocking(fioc->fd, !enabled, NULL)) {
+        error_setg_errno(errp, errno, "Failed to set FD nonblocking");
+        return -1;
     }
     return 0;
+#endif
 }