summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-05-24 21:59:38 -0700
committerAdam Jackson <ajax@redhat.com>2016-07-18 15:25:59 -0400
commit559aac2d71250e3137aaa582e2a59a918ddf21b7 (patch)
tree99aefc553448bb3eb6878bedfddadfd5338642bb
parentaa6717ce213e79735c72afc5ec9cc1f9c0297e09 (diff)
dmx: Switch from select(2) to poll(2) for input
Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
-rw-r--r--hw/dmx/input/lnx-ms.c19
-rw-r--r--hw/dmx/input/lnx-ps2.c12
2 files changed, 15 insertions, 16 deletions
diff --git a/hw/dmx/input/lnx-ms.c b/hw/dmx/input/lnx-ms.c
index cb3b25f09..c7a09cab7 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 9041974c9..00ccc014e 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;
}