initial version
This commit is contained in:
commit
6cdb039c6c
9 changed files with 556 additions and 0 deletions
59
twsmux-kq.c
Normal file
59
twsmux-kq.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct kevent ev;
|
||||
char *device;
|
||||
int fd, kq, kev;
|
||||
|
||||
if (argc == 2)
|
||||
device = argv[1];
|
||||
else
|
||||
device = "/dev/wskbd";
|
||||
|
||||
fd = open(device, O_RDWR);
|
||||
if (fd == -1)
|
||||
err(2, "open %s", device);
|
||||
|
||||
if ((kq = kqueue()) <= 0)
|
||||
err(2, "kqueue");
|
||||
|
||||
EV_SET(&ev, fd, EVFILT_DEVICE, EV_ADD | EV_ENABLE | EV_CLEAR,
|
||||
NOTE_CHG_DATA, 0, NULL);
|
||||
if (kevent(kq, &ev, 1, NULL, 0, NULL) < 0)
|
||||
err(2, "kevent init");
|
||||
|
||||
while (1) {
|
||||
#if 0
|
||||
struct pollfd fds;
|
||||
int result;
|
||||
|
||||
fds.fd = kq;
|
||||
fds.events = POLLIN;
|
||||
result = poll(&fds, 1, INFTIM);
|
||||
printf("poll result %d\n", result);
|
||||
#endif
|
||||
kev = kevent(kq, NULL, 0, &ev, 1, NULL);
|
||||
printf("kevent -> %d\n", kev);
|
||||
if (kev < 0)
|
||||
err(2, "kevent");
|
||||
if (kev /* && ev.fflags & NOTE_CHG_DATA */) {
|
||||
printf("kevent triggered %lx %hd %hx %x %lld\n",
|
||||
ev.ident, ev.filter, ev.flags, ev.fflags, ev.data);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue