poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 2/5] Improve portability (particularly for Woe32)


From: Bruno Haible
Subject: Re: [PATCH 2/5] Improve portability (particularly for Woe32)
Date: Sat, 27 Mar 2021 13:19:51 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-203-generic; KDE/5.18.0; x86_64; ; )

Hi,

Regarding this patch:

@@ -167,6 +168,7 @@ pk_mi_send_frame_msg (const char *payload)
 /* Set fd to non-blocking and return old flags or -1 on error. */
 static int pk_mi_fd_set_nonblocking (int fd)
 {
+#if defined HAVE_FCNTL
   int flags = fcntl (fd, F_GETFL, 0);

   if (flags >= 0 && (flags & O_NONBLOCK) == 0)
@@ -179,16 +181,21 @@ static int pk_mi_fd_set_nonblocking (int fd)
     perror ("fcntl");

   return flags;
+#else
+  return 0;
+#endif
 }


Gnulib has support for non-blocking sockets also on native Windows;
you need the 'nonblocking' module for this.

However, the 'select' module has problems: It can happen (on Windows)
that select() reports that a file descriptor has data to be read when
it doesn't, or vice versa. Especially for pipes.

The approach I would recommend to avoid this is to use multithreading:
use an extra thread for the MI I/O, that only uses read() and write(),
no select() nor poll(). At least on native Windows. (That's also how
the Gnulib modules 'pipe-filter-ii' and 'pipe-filter'gi' operate.)

Bruno




reply via email to

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