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 <termios.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xpoll.h>
#include "inputstr.h" #include "inputstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "kdrive.h" #include "kdrive.h"

View File

@ -27,7 +27,6 @@
#include <linux/input.h> #include <linux/input.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xpoll.h>
#include "inputstr.h" #include "inputstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "kdrive.h" #include "kdrive.h"
@ -444,6 +443,7 @@ EvdevKbdLeds(KdKeyboardInfo * ki, int leds)
{ {
struct input_event event; struct input_event event;
Kevdev *ke; Kevdev *ke;
int i;
if (!ki) if (!ki)
return; return;
@ -458,22 +458,26 @@ EvdevKbdLeds(KdKeyboardInfo * ki, int leds)
event.type = EV_LED; event.type = EV_LED;
event.code = LED_CAPSL; event.code = LED_CAPSL;
event.value = leds & (1 << 0) ? 1 : 0; 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.type = EV_LED;
event.code = LED_NUML; event.code = LED_NUML;
event.value = leds & (1 << 1) ? 1 : 0; 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.type = EV_LED;
event.code = LED_SCROLLL; event.code = LED_SCROLLL;
event.value = leds & (1 << 2) ? 1 : 0; 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.type = EV_LED;
event.code = LED_COMPOSE; event.code = LED_COMPOSE;
event.value = leds & (1 << 3) ? 1 : 0; 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 static void

View File

@ -27,7 +27,7 @@
#include <termios.h> #include <termios.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xpoll.h> #include <poll.h>
#include "inputstr.h" #include "inputstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "kdrive.h" #include "kdrive.h"
@ -47,23 +47,15 @@ typedef struct _kbufio {
static Bool static Bool
MouseWaitForReadable(int fd, int timeout) MouseWaitForReadable(int fd, int timeout)
{ {
fd_set set; struct pollfd poll_fd;
struct timeval tv, *tp;
int n; int n;
CARD32 done; CARD32 done;
done = GetTimeInMillis() + timeout; done = GetTimeInMillis() + timeout;
poll_fd.fd = fd;
poll_fd.events = POLLIN;
for (;;) { for (;;) {
FD_ZERO(&set); n = poll(&poll_fd, 1, timeout);
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);
if (n > 0) if (n > 0)
return TRUE; return TRUE;
if (n < 0 && (errno == EAGAIN || errno == EINTR)) { if (n < 0 && (errno == EAGAIN || errno == EINTR)) {
@ -139,20 +131,12 @@ MousePeekByte(Kbufio * b, int timeout)
static Bool static Bool
MouseWaitForWritable(int fd, int timeout) MouseWaitForWritable(int fd, int timeout)
{ {
fd_set set; struct pollfd poll_fd;
struct timeval tv, *tp;
int n; int n;
FD_ZERO(&set); poll_fd.fd = fd;
FD_SET(fd, &set); poll_fd.events = POLLOUT;
if (timeout == -1) n = poll(&poll_fd, 1, timeout);
tp = 0;
else {
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
tp = &tv;
}
n = select(fd + 1, 0, &set, 0, tp);
if (n > 0) if (n > 0)
return TRUE; return TRUE;
return FALSE; return FALSE;

View File

@ -26,9 +26,9 @@ THE SOFTWARE.
#endif #endif
#include <errno.h> #include <errno.h>
#include <termios.h> #include <termios.h>
#include <poll.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xpoll.h>
#include "inputstr.h" #include "inputstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "kdrive.h" #include "kdrive.h"
@ -37,9 +37,10 @@ static int
MsReadBytes(int fd, char *buf, int len, int min) MsReadBytes(int fd, 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);
@ -50,11 +51,7 @@ MsReadBytes(int fd, 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;
} }

View File

@ -25,7 +25,7 @@
#endif #endif
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xpoll.h> #include <poll.h>
#include "inputstr.h" #include "inputstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "kdrive.h" #include "kdrive.h"
@ -34,10 +34,11 @@ static int
Ps2ReadBytes(int fd, char *buf, int len, int min) Ps2ReadBytes(int fd, 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) {
@ -47,11 +48,7 @@ Ps2ReadBytes(int fd, 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;
} }

View File

@ -36,7 +36,6 @@
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xpoll.h>
#include "inputstr.h" #include "inputstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "kdrive.h" #include "kdrive.h"