summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-05-24 21:19:13 -0700
committerAdam Jackson <ajax@redhat.com>2016-07-18 15:25:59 -0400
commit81135991a583b3b30a90e82ddc1d5c86d57bf00b (patch)
treea20b496189c730bd7d38559e66e061d685e46afc
parent05a793f5b3c40747d5a92a076def7f4fb673c7e7 (diff)
kdrive: switch from select(2) to poll(2)
This avoids fd limits Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
-rw-r--r--hw/kdrive/fake/mouse.c1
-rw-r--r--hw/kdrive/linux/evdev.c14
-rw-r--r--hw/kdrive/linux/mouse.c34
-rw-r--r--hw/kdrive/linux/ms.c13
-rw-r--r--hw/kdrive/linux/ps2.c13
-rw-r--r--hw/kdrive/linux/tslib.c1
6 files changed, 28 insertions, 48 deletions
diff --git a/hw/kdrive/fake/mouse.c b/hw/kdrive/fake/mouse.c
index bb4c25eeb..564dae445 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 8415772ac..9590413be 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 2bfe7f242..3508b1761 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 e82350ac5..79e6373dd 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 e5417a567..5d4a8eb33 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 1403c7968..0cdb4ea7d 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"