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>
This commit is contained in:
Keith Packard 2016-05-24 21:19:13 -07:00 committed by Adam Jackson
parent 05a793f5b3
commit 81135991a5
6 changed files with 28 additions and 48 deletions

View File

@ -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"

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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"