tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
poll(2)ing for USB device changes
usb(4) says:
| The /dev/usbN can be opened and a few operations can be performed on it.
| The poll(2) system call will say that I/O is possible on the controller
| device when a USB device has been connected or disconnected to the bus.
I'm trying to get that to work, with the below test case, but no amount
of plugging or unplugging USB devices will cause poll to return.
Is this broken or am I doing something wrong? The device I'm removing
/plugging in is this:
| uhub0 at usb0: NetBSD (0x0000) OHCI root hub (0x0000), class 9/0, rev 1.00/1.00, addr 1
| uplcom0 at uhub0 port 1
| ucom0 at uplcom0
Testcase:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <poll.h>
#include <dev/usb/usb.h>
#include <err.h>
int
main(void)
{
int fd = open("/dev/usb0", O_RDONLY, 0);
if (fd < 0)
err(EXIT_FAILURE, "open /dev/usb0");
struct pollfd fds[] = { {fd, POLLRDNORM|POLLRDBAND|POLLIN, 0 } };
int r = poll(fds, 1, INFTIM);
fprintf(stderr, "return %d\n", r);
close(fd);
}
Home |
Main Index |
Thread Index |
Old Index