emacs-diffs
[Top][All Lists]
Advanced

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

master 873bcd6d5d: Minor fixes to x_next_event_from_any_display


From: Po Lu
Subject: master 873bcd6d5d: Minor fixes to x_next_event_from_any_display
Date: Wed, 1 Jun 2022 08:52:24 -0400 (EDT)

branch: master
commit 873bcd6d5d1d571caa3aa355fef2c9a987ebb4ca
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Minor fixes to x_next_event_from_any_display
    
    * src/xterm.c (x_next_event_from_any_display): Don't call
    XPending unless there is input to be read on the connection, and
    don't call ConnectionNumber twice.
---
 src/xterm.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index 484637807a..214419a336 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10292,8 +10292,11 @@ static void
 x_next_event_from_any_display (XEvent *event)
 {
   struct x_display_info *dpyinfo;
-  fd_set fds;
-  int fd, maxfd;
+  fd_set fds, rfds;
+  int fd, maxfd, rc;
+
+  rc = 0;
+  FD_ZERO (&rfds);
 
   while (true)
     {
@@ -10303,27 +10306,31 @@ x_next_event_from_any_display (XEvent *event)
       for (dpyinfo = x_display_list; dpyinfo;
           dpyinfo = dpyinfo->next)
        {
-         if (XPending (dpyinfo->display))
+         fd = ConnectionNumber (dpyinfo->display);
+
+         if ((rc < 0 || FD_ISSET (fd, &rfds))
+             && XPending (dpyinfo->display))
            {
              XNextEvent (dpyinfo->display, event);
              return;
            }
 
-         fd = XConnectionNumber (dpyinfo->display);
-
          if (fd > maxfd)
            maxfd = fd;
 
          eassert (fd < FD_SETSIZE);
-         FD_SET (XConnectionNumber (dpyinfo->display), &fds);
+         FD_SET (fd, &fds);
        }
 
       eassert (maxfd >= 0);
 
-      /* We don't have to check the return of pselect, because if an
+      /* Continue to read input even if pselect fails, because if an
         error occurs XPending will call the IO error handler, which
         then brings us out of this loop.  */
-      pselect (maxfd + 1, &fds, NULL, NULL, NULL, NULL);
+      rc = pselect (maxfd + 1, &fds, NULL, NULL, NULL, NULL);
+
+      if (rc >= 0)
+       rfds = fds;
     }
 }
 



reply via email to

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