[PATCH xserver 24/25] dmx: Switch from select(2) to poll(2) for input

Keith Packard keithp at keithp.com
Wed May 25 05:39:01 UTC 2016


Signed-off-by: Keith Packard <keithp at keithp.com>
---
 hw/dmx/input/lnx-ms.c  | 19 ++++++++++---------
 hw/dmx/input/lnx-ps2.c | 12 +++++-------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/hw/dmx/input/lnx-ms.c b/hw/dmx/input/lnx-ms.c
index 621f0fe..3d028be 100644
--- a/hw/dmx/input/lnx-ms.c
+++ b/hw/dmx/input/lnx-ms.c
@@ -76,6 +76,7 @@
 #include <X11/Xos.h>
 #include <errno.h>
 #include <termios.h>
+#include <poll.h>
 
 /*****************************************************************************/
 /* Define some macros to make it easier to move this file to another
@@ -120,10 +121,11 @@ static int
 msLinuxReadBytes(int fd, unsigned char *buf, int len, int min)
 {
     int n, tot;
-    fd_set set;
-    struct timeval tv;
+    struct pollfd poll_fd;
 
     tot = 0;
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     while (len) {
         n = read(fd, buf, len);
         if (n > 0) {
@@ -133,11 +135,7 @@ msLinuxReadBytes(int fd, unsigned char *buf, int len, int min)
         }
         if (tot % min == 0)
             break;
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        tv.tv_sec = 0;
-        tv.tv_usec = 100 * 1000;
-        n = select(fd + 1, &set, 0, 0, &tv);
+        n = poll(&poll_fd, 1, 100);
         if (n <= 0)
             break;
     }
@@ -246,7 +244,8 @@ msLinuxInit(DevicePtr pDev)
     if (tcgetattr(priv->fd, &priv->tty) < 0)
         FATAL1("msLinuxInit: tcgetattr failed (%s)\n", strerror(errno));
 
-    write(priv->fd, "*n", 2);   /* 1200 baud */
+    i = write(priv->fd, "*n", 2);   /* 1200 baud */
+    (void) i;
     usleep(100000);
 }
 
@@ -256,6 +255,7 @@ msLinuxOn(DevicePtr pDev)
 {
     GETPRIV;
     struct termios nTty;
+    int i;
 
     if (priv->fd < 0)
         msLinuxInit(pDev);
@@ -273,7 +273,8 @@ msLinuxOn(DevicePtr pDev)
     cfsetospeed(&nTty, B1200);
     if (tcsetattr(priv->fd, TCSANOW, &nTty) < 0)
         FATAL1("msLinuxInit: tcsetattr failed (%s)\n", strerror(errno));
-    write(priv->fd, "*V", 2);   /* 2 button 3 byte protocol */
+    i = write(priv->fd, "*V", 2);   /* 2 button 3 byte protocol */
+    (void) i;
     return priv->fd;
 }
 
diff --git a/hw/dmx/input/lnx-ps2.c b/hw/dmx/input/lnx-ps2.c
index dd70cb8..834beb0 100644
--- a/hw/dmx/input/lnx-ps2.c
+++ b/hw/dmx/input/lnx-ps2.c
@@ -73,6 +73,7 @@
 #include <X11/Xos.h>
 #include <errno.h>
 #include <termios.h>
+#include <poll.h>
 
 /*****************************************************************************/
 /* Define some macros to make it easier to move this file to another
@@ -116,9 +117,10 @@ static int
 ps2LinuxReadBytes(int fd, unsigned char *buf, int len, int min)
 {
     int n, tot;
-    fd_set set;
-    struct timeval tv;
+    struct pollfd poll_fd;
 
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     tot = 0;
     while (len) {
         n = read(fd, buf, len);
@@ -129,11 +131,7 @@ ps2LinuxReadBytes(int fd, unsigned char *buf, int len, int min)
         }
         if (tot % min == 0)
             break;
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        tv.tv_sec = 0;
-        tv.tv_usec = 100 * 1000;
-        n = select(fd + 1, &set, 0, 0, &tv);
+        n = poll(&poll_fd, 1, 100);
         if (n <= 0)
             break;
     }
-- 
2.8.0.rc3



More information about the xorg-devel mailing list