SDL: wayland: Dramatically lower the timeout when reading/writing pipes

From c59d4dcd38c382a1e9b69b053756f1139a861574 Mon Sep 17 00:00:00 2001
From: Ethan Lee <[EMAIL REDACTED]>
Date: Thu, 8 Apr 2021 15:32:33 -0400
Subject: [PATCH] wayland: Dramatically lower the timeout when reading/writing
 pipes

---
 src/video/wayland/SDL_waylanddatamanager.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index bd40e7306..dc444ff55 100644
--- a/src/video/wayland/SDL_waylanddatamanager.c
+++ b/src/video/wayland/SDL_waylanddatamanager.c
@@ -36,6 +36,11 @@
 
 #include "SDL_waylanddyn.h"
 
+/* FIXME: This is arbitrary, but we want this to be less than a frame because
+ * any longer can potentially spin an infinite loop of PumpEvents (!)
+ */
+#define PIPE_MS_TIMEOUT 10
+
 static ssize_t
 write_pipe(int fd, const void* buffer, size_t total_length, size_t *pos)
 {
@@ -47,7 +52,7 @@ write_pipe(int fd, const void* buffer, size_t total_length, size_t *pos)
     sigset_t old_sig_set;
     struct timespec zerotime = {0};
 
-    ready = SDL_IOReady(fd, SDL_TRUE, 1 * 1000);
+    ready = SDL_IOReady(fd, SDL_TRUE, PIPE_MS_TIMEOUT);
 
     sigemptyset(&sig_set);
     sigaddset(&sig_set, SIGPIPE);  
@@ -93,7 +98,7 @@ read_pipe(int fd, void** buffer, size_t* total_length, SDL_bool null_terminate)
     ssize_t bytes_read = 0;
     size_t pos = 0;
 
-    ready = SDL_IOReady(fd, SDL_FALSE, 1 * 1000);
+    ready = SDL_IOReady(fd, SDL_FALSE, PIPE_MS_TIMEOUT);
   
     if (ready == 0) {
         bytes_read = SDL_SetError("Pipe timeout");