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>
This commit is contained in:
parent
aa6717ce21
commit
559aac2d71
|
@ -76,6 +76,7 @@
|
||||||
#include <X11/Xos.h>
|
#include <X11/Xos.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Define some macros to make it easier to move this file to another
|
/* 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)
|
msLinuxReadBytes(int fd, unsigned char *buf, int len, int min)
|
||||||
{
|
{
|
||||||
int n, tot;
|
int n, tot;
|
||||||
fd_set set;
|
struct pollfd poll_fd;
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
tot = 0;
|
tot = 0;
|
||||||
|
poll_fd.fd = fd;
|
||||||
|
poll_fd.events = POLLIN;
|
||||||
while (len) {
|
while (len) {
|
||||||
n = read(fd, buf, len);
|
n = read(fd, buf, len);
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
|
@ -133,11 +135,7 @@ msLinuxReadBytes(int fd, unsigned char *buf, int len, int min)
|
||||||
}
|
}
|
||||||
if (tot % min == 0)
|
if (tot % min == 0)
|
||||||
break;
|
break;
|
||||||
FD_ZERO(&set);
|
n = poll(&poll_fd, 1, 100);
|
||||||
FD_SET(fd, &set);
|
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = 100 * 1000;
|
|
||||||
n = select(fd + 1, &set, 0, 0, &tv);
|
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +244,8 @@ msLinuxInit(DevicePtr pDev)
|
||||||
if (tcgetattr(priv->fd, &priv->tty) < 0)
|
if (tcgetattr(priv->fd, &priv->tty) < 0)
|
||||||
FATAL1("msLinuxInit: tcgetattr failed (%s)\n", strerror(errno));
|
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);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,6 +255,7 @@ msLinuxOn(DevicePtr pDev)
|
||||||
{
|
{
|
||||||
GETPRIV;
|
GETPRIV;
|
||||||
struct termios nTty;
|
struct termios nTty;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (priv->fd < 0)
|
if (priv->fd < 0)
|
||||||
msLinuxInit(pDev);
|
msLinuxInit(pDev);
|
||||||
|
@ -273,7 +273,8 @@ msLinuxOn(DevicePtr pDev)
|
||||||
cfsetospeed(&nTty, B1200);
|
cfsetospeed(&nTty, B1200);
|
||||||
if (tcsetattr(priv->fd, TCSANOW, &nTty) < 0)
|
if (tcsetattr(priv->fd, TCSANOW, &nTty) < 0)
|
||||||
FATAL1("msLinuxInit: tcsetattr failed (%s)\n", strerror(errno));
|
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;
|
return priv->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
#include <X11/Xos.h>
|
#include <X11/Xos.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Define some macros to make it easier to move this file to another
|
/* 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)
|
ps2LinuxReadBytes(int fd, unsigned char *buf, int len, int min)
|
||||||
{
|
{
|
||||||
int n, tot;
|
int n, tot;
|
||||||
fd_set set;
|
struct pollfd poll_fd;
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
|
poll_fd.fd = fd;
|
||||||
|
poll_fd.events = POLLIN;
|
||||||
tot = 0;
|
tot = 0;
|
||||||
while (len) {
|
while (len) {
|
||||||
n = read(fd, buf, len);
|
n = read(fd, buf, len);
|
||||||
|
@ -129,11 +131,7 @@ ps2LinuxReadBytes(int fd, unsigned char *buf, int len, int min)
|
||||||
}
|
}
|
||||||
if (tot % min == 0)
|
if (tot % min == 0)
|
||||||
break;
|
break;
|
||||||
FD_ZERO(&set);
|
n = poll(&poll_fd, 1, 100);
|
||||||
FD_SET(fd, &set);
|
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = 100 * 1000;
|
|
||||||
n = select(fd + 1, &set, 0, 0, &tv);
|
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue