Subject: select() does not work on /dev/audio
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: tech-kern
Date: 11/29/2005 16:13:23
Hi

The test pgoram above will show that select is not able to detect that
data is available for reading on /dev/audio. cat shows lots of data, so 
it's not a problem of data being unavailable.

How can this be fixed? I tried adding selnotify(&sc->sc_rsel, 0); at the
end of src/sys/dev/audio.c:audiostartr(), and selnotify(&sc->sc_wsel, 0); 
in audiostartp() but that does not seems to do the job. Any idea?

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#include <sysexits.h>
#include <sys/time.h>
#include <sys/types.h>


int
main(argc, argv)
	int argc;
	char **argv;
{
	int fd;
	fd_set set;
	int error;
	struct timeval tv;

	if (argc != 2) 
		err(EX_USAGE, "usage: select /dev/audio or select /dev/random");

	if ((fd = open(argv[1], O_RDONLY, 0)) == -1)
		err(EX_OSERR, "open \"%s\" failed", argv[1]);

	FD_ZERO(&set);
	FD_SET(fd, &set);

	tv.tv_sec = 2;
	tv.tv_usec = 0;

	if ((error = select(fd + 1, &set, NULL, NULL, &tv)) == -1)
		err(EX_OSERR, "select returned an error");

	if (FD_ISSET(fd, &set))
		printf("select found data on \"%s\"\n", argv[1]);
	else
		printf("select did not found data on \"%s\"\n", argv[1]);
	
	return 0;
		
}
-- 
Emmanuel Dreyfus
manu@netbsd.org