[2/2] sim: dv-sockser: use gnulib to set nonblocking mode

Message ID 20210904074934.21309-2-vapier@gentoo.org
State New
Headers show
Series
  • [1/2] gnulib: import nonblocking module
Related show

Commit Message

Tom Tromey via Gdb-patches Sept. 4, 2021, 7:49 a.m.
---
 sim/common/dv-sockser.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

-- 
2.31.1

Patch

diff --git a/sim/common/dv-sockser.c b/sim/common/dv-sockser.c
index d47d428d535d..ad4fc229a923 100644
--- a/sim/common/dv-sockser.c
+++ b/sim/common/dv-sockser.c
@@ -42,6 +42,8 @@  along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/select.h>
 #include <sys/socket.h>
 
+#include "nonblocking.h"
+
 #include "sim-assert.h"
 #include "sim-options.h"
 
@@ -51,7 +53,7 @@  along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 typedef int socklen_t;
 #endif
 
-/* Get definitions for both O_NONBLOCK and O_NDELAY.  */
+/* Get definitions for O_NDELAY.  */
 
 #ifndef O_NDELAY
 #ifdef FNDELAY
@@ -60,14 +62,6 @@  typedef int socklen_t;
 #define O_NDELAY 0
 #endif /* ! defined (FNDELAY) */
 #endif /* ! defined (O_NDELAY) */
-
-#ifndef O_NONBLOCK
-#ifdef FNBLOCK
-#define O_NONBLOCK FNBLOCK
-#else /* ! defined (FNBLOCK) */
-#define O_NONBLOCK 0
-#endif /* ! defined (FNBLOCK) */
-#endif /* ! defined (O_NONBLOCK) */
 
 
 /* Compromise between eating cpu and properly busy-waiting.
@@ -279,13 +273,15 @@  connected_p (SIM_DESC sd)
   flags = fcntl (sockser_fd, F_GETFL);
   flags |= O_NONBLOCK | O_NDELAY;
   if (fcntl (sockser_fd, F_SETFL, flags) == -1)
+#else
+  if (set_nonblocking_flag (sockser_fd, false))
+#endif
     {
       sim_io_eprintf (sd, "unable to set nonblocking i/o");
       close (sockser_fd);
       sockser_fd = -1;
       return 0;
     }
-#endif
   return 1;
 }