kqueue for usb_dev

Kohji Okuno okuno.kohji at jp.panasonic.com
Thu Feb 27 07:04:05 UTC 2014


Hi John-Mark,

I tested the attached sample source with USB mouse.

Thanks,
 Kohji Okuno

From: John-Mark Gurney <jmg at funkthat.com>
> Kohji Okuno wrote this message on Thu, Feb 27, 2014 at 14:26 +0900:
>> I tried add kqueue I/F to usb_dev.c. I attached my patch.
>> What do you think about my patch?
> 
> Do you have test cases for these patches?
> 
> -- 
>   John-Mark Gurney				Voice: +1 415 225 5579
> 
>      "All that I will do, has been done, All that I have, has not."
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/event.h>
#include <sys/select.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#define	DEV	"/dev/ums0"

#if 0
int
main()
{
	int i;
	ssize_t ret;
	uint8_t buf[128];
	int fd = open(DEV, O_RDONLY);
	fd_set readfds;

	for (i = 0; i < 10; i++) {
		FD_ZERO(&readfds);
		FD_SET(fd, &readfds);
		ret = select(fd+1, &readfds, NULL, NULL, NULL);
		printf("select=%d\n", ret);

		ret = read(fd, buf, sizeof(buf));
		printf("%d:%02x %02x %02x\n", ret, buf[0], buf[1], buf[2]);
	}

	close(fd);
	exit(0);
}
#else
int
main()
{
	int i;
	int err;
	ssize_t ret;
	uint8_t buf[128];
	int fd = open(DEV, O_RDONLY);
	int kqfd = kqueue();
	struct kevent evlist[1];

	EV_SET(&evlist[0], fd, EVFILT_READ, EV_ADD, 0, 0, 0);
	err = kevent(kqfd, evlist, 1, 0, 0, 0);
	if (err) {
		perror("kevent");
		close(fd);
		close(kqfd);
		exit(1);
	}

	for (i = 0; i < 10; i++) {
		ret = kevent(kqfd, 0, 0, evlist, 1, 0);
		printf("kev=%d\n", ret);

		ret = read(fd, buf, sizeof(buf));
		printf("%d:%02x %02x %02x\n", ret, buf[0], buf[1], buf[2]);
	}

	close(fd);
	exit(0);
}
#endif


More information about the freebsd-current mailing list