[PATCH xserver 02/23] kdrive: switch from select(2) to poll(2)

Keith Packard keithp at keithp.com
Thu May 26 23:59:37 UTC 2016


This avoids fd limits

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 hw/kdrive/fake/mouse.c  |  1 -
 hw/kdrive/linux/evdev.c | 14 +++++++++-----
 hw/kdrive/linux/mouse.c | 34 +++++++++-------------------------
 hw/kdrive/linux/ms.c    | 13 +++++--------
 hw/kdrive/linux/ps2.c   | 13 +++++--------
 hw/kdrive/linux/tslib.c |  1 -
 6 files changed, 28 insertions(+), 48 deletions(-)

diff --git a/hw/kdrive/fake/mouse.c b/hw/kdrive/fake/mouse.c
index bb4c25e..564dae4 100644
--- a/hw/kdrive/fake/mouse.c
+++ b/hw/kdrive/fake/mouse.c
@@ -27,7 +27,6 @@
 #include <termios.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 8415772..9590413 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -27,7 +27,6 @@
 #include <linux/input.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -444,6 +443,7 @@ EvdevKbdLeds(KdKeyboardInfo * ki, int leds)
 {
     struct input_event event;
     Kevdev             *ke;
+    int                i;
 
     if (!ki)
         return;
@@ -458,22 +458,26 @@ EvdevKbdLeds(KdKeyboardInfo * ki, int leds)
     event.type = EV_LED;
     event.code = LED_CAPSL;
     event.value = leds & (1 << 0) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 
     event.type = EV_LED;
     event.code = LED_NUML;
     event.value = leds & (1 << 1) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 
     event.type = EV_LED;
     event.code = LED_SCROLLL;
     event.value = leds & (1 << 2) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 
     event.type = EV_LED;
     event.code = LED_COMPOSE;
     event.value = leds & (1 << 3) ? 1 : 0;
-    write(ke->fd, (char *) &event, sizeof(event));
+    i = write(ke->fd, (char *) &event, sizeof(event));
+    (void) i;
 }
 
 static void
diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c
index 2bfe7f2..3508b17 100644
--- a/hw/kdrive/linux/mouse.c
+++ b/hw/kdrive/linux/mouse.c
@@ -27,7 +27,7 @@
 #include <termios.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
+#include <poll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -47,23 +47,15 @@ typedef struct _kbufio {
 static Bool
 MouseWaitForReadable(int fd, int timeout)
 {
-    fd_set set;
-    struct timeval tv, *tp;
+    struct pollfd poll_fd;
     int n;
     CARD32 done;
 
     done = GetTimeInMillis() + timeout;
+    poll_fd.fd = fd;
+    poll_fd.events = POLLIN;
     for (;;) {
-        FD_ZERO(&set);
-        FD_SET(fd, &set);
-        if (timeout == -1)
-            tp = 0;
-        else {
-            tv.tv_sec = timeout / 1000;
-            tv.tv_usec = (timeout % 1000) * 1000;
-            tp = &tv;
-        }
-        n = select(fd + 1, &set, 0, 0, tp);
+        n = poll(&poll_fd, 1, timeout);
         if (n > 0)
             return TRUE;
         if (n < 0 && (errno == EAGAIN || errno == EINTR)) {
@@ -139,20 +131,12 @@ MousePeekByte(Kbufio * b, int timeout)
 static Bool
 MouseWaitForWritable(int fd, int timeout)
 {
-    fd_set set;
-    struct timeval tv, *tp;
+    struct pollfd poll_fd;
     int n;
 
-    FD_ZERO(&set);
-    FD_SET(fd, &set);
-    if (timeout == -1)
-        tp = 0;
-    else {
-        tv.tv_sec = timeout / 1000;
-        tv.tv_usec = (timeout % 1000) * 1000;
-        tp = &tv;
-    }
-    n = select(fd + 1, 0, &set, 0, tp);
+    poll_fd.fd = fd;
+    poll_fd.events = POLLOUT;
+    n = poll(&poll_fd, 1, timeout);
     if (n > 0)
         return TRUE;
     return FALSE;
diff --git a/hw/kdrive/linux/ms.c b/hw/kdrive/linux/ms.c
index e82350a..79e6373 100644
--- a/hw/kdrive/linux/ms.c
+++ b/hw/kdrive/linux/ms.c
@@ -26,9 +26,9 @@ THE SOFTWARE.
 #endif
 #include <errno.h>
 #include <termios.h>
+#include <poll.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -37,9 +37,10 @@ static int
 MsReadBytes(int fd, 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);
@@ -50,11 +51,7 @@ MsReadBytes(int fd, 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;
     }
diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c
index e5417a5..5d4a8eb 100644
--- a/hw/kdrive/linux/ps2.c
+++ b/hw/kdrive/linux/ps2.c
@@ -25,7 +25,7 @@
 #endif
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
+#include <poll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
@@ -34,10 +34,11 @@ static int
 Ps2ReadBytes(int fd, 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) {
@@ -47,11 +48,7 @@ Ps2ReadBytes(int fd, 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;
     }
diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
index 1403c79..0cdb4ea 100644
--- a/hw/kdrive/linux/tslib.c
+++ b/hw/kdrive/linux/tslib.c
@@ -36,7 +36,6 @@
 
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include <X11/Xpoll.h>
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "kdrive.h"
-- 
2.8.0.rc3



More information about the xorg-devel mailing list