Bug 89775 - [kqueue] [hang] kevent hangs on second wait for /dev/dsp
Summary: [kqueue] [hang] kevent hangs on second wait for /dev/dsp
Status: Closed Overcome By Events
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-30 20:20 UTC by yuri
Modified: 2017-08-27 04:24 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yuri 2005-11-30 20:20:03 UTC
If kernel queue has sound device /dev/dsp in it kevent only being triggered once.
Second call to it hangs although data is obviously continuously available from soundcard.

relevant dmesg messages describing the card are:
pcm0: <Creative EMU10K1> port 0xdc00-0xdc1f irq 17 at device 6.0 on pci0
pcm0: <TriTech TR28602 AC97 Codec>

Fix: 

N/A
How-To-Repeat: compile and run the following code:
----code------
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
                                                                                                                                                                                                     
#include <sys/types.h>
#include <sys/event.h>
                                                                                                                                                                                                     
                                                                                                                                                                                                     
int
main(int argc, char *argv[]) {
  int res, kq;
  int dsp;
                                                                                                                                                                                                     
                                                                                                                                                                                                     
  kq = kqueue();
  printf("kqueue returned %i\n", kq);
                                                                                                                                                                                                     
  char buf[1024];
                                                                                                                                                                                                     
  dsp = open("/dev/dsp", O_RDONLY);
                                                                                                                                                                                                     
  struct kevent kev;
  EV_SET(&kev, dsp, EVFILT_READ, EV_ADD, 0/*fflags*/, 0/*data*/, NULL);
                                                                                                                                                                                                     
  struct kevent result_events[256];
                                                                                                                                                                                                     
  // 1
  printf(">kevent1\n");
  res = kevent(kq,
     &kev, 1,
     &result_events[0], 256,
     NULL
  );
  printf("<kevent1 returned %i\n", res);
                                                                                                                                                                                                     
  printf(">read returned %i\n", res);
  res = read(dsp, buf, sizeof(buf));
  printf("<read returned %i\n", res);
                                                                                                                                                                                                     
  // 2
  printf(">kevent2\n");
  res = kevent(kq,
     NULL/*&kev*/, 0,
     &result_events[0], 256,
     NULL
  );
  printf("<kevent2 returned %i\n", res);
                                                                                                                                                                                                     
  //
  close(dsp);
                                                                                                                                                                                                     
  return (0);
}
Comment 1 yuri 2005-12-01 06:45:42 UTC
Moreover, if right after open I make FD async with these 2 lines:

int on = 1;
ioctl(dsp, FIONBIO, &on);

the first 'read' call fails with 'Resource temporarily unavailable' 
error (right after kevent returns that data is available).

Yuri