Commit c59d4dcd38c382a1e9b69b053756f1139a861574

Ethan Lee 2021-04-08T15:32:33

wayland: Dramatically lower the timeout when reading/writing pipes

diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index bd40e73..dc444ff 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");