]> git.eshelyaron.com Git - emacs.git/commitdiff
sys_select: Call mac_check_for_quit_char every second while blocking
authorSteven Tamm <steventamm@mac.com>
Sun, 8 Dec 2002 05:58:34 +0000 (05:58 +0000)
committerSteven Tamm <steventamm@mac.com>
Sun, 8 Dec 2002 05:58:34 +0000 (05:58 +0000)
sys_read: Use sys_select to test for input first before calling read to
allow sys_select to test for quit_char.

src/mac.c

index 833ee5f3bdcac4b921029b6ab14b206f225b8238..439f900db5b4694b88765e6f3aee83566679f2bf 100644 (file)
--- a/src/mac.c
+++ b/src/mac.c
@@ -2751,6 +2751,7 @@ and t is the same as `SECONDARY'.  */)
 #undef select
 
 extern int inhibit_window_system;
+extern int noninteractive;
 
 /* When Emacs is started from the Finder, SELECT always immediately
    returns as if input is present when file descriptor 0 is polled for
@@ -2767,8 +2768,58 @@ sys_select (n, rfds, wfds, efds, timeout)
 {
   if (!inhibit_window_system && rfds && FD_ISSET (0, rfds))
     return 1;
+  else if (inhibit_window_system || noninteractive)
+    return select(n, rfds, wfds, efds, timeout);
   else
-    return select (n, rfds, wfds, efds, timeout);
+    {
+      EMACS_TIME end_time, now;
+      
+      EMACS_GET_TIME (end_time);
+      if (timeout)
+       EMACS_ADD_TIME (end_time, end_time, *timeout);
+      
+      do
+       {
+         int r;
+         EMACS_TIME one_second;
+         
+         EMACS_SET_SECS (one_second, 1);
+         EMACS_SET_USECS (one_second, 0);
+         
+         if ((r = select (n, rfds, wfds, efds, &one_second)) > 0)
+           return r;
+         
+         mac_check_for_quit_char();
+         
+         EMACS_GET_TIME (now);
+         EMACS_SUB_TIME (now, end_time, now);
+       }
+      while (!timeout || !EMACS_TIME_NEG_P (now));
+      
+      return 0;
+    }
+}
+
+#undef read
+int sys_read (fds, buf, nbyte)
+     int fds;
+     char *buf;
+     unsigned int nbyte;
+{
+  SELECT_TYPE rfds;
+  EMACS_TIME one_second;
+  int r;
+
+  /* Use select to block on IO while still checking for quit_char */
+  if (!inhibit_window_system && !noninteractive)
+    {
+      FD_ZERO (&rfds);
+      FD_SET (fds, &rfds);
+      if (sys_select (fds+1, &rfds, 0, 0, NULL) < 0)
+       return -1;
+    }
+      
+  return read (fds, buf, nbyte);
 }