Use select() if kevent() does not work, e.g. file on msdosfs.

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@337 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Jilles Tjoelker 2004-08-28 21:30:54 +00:00
parent 8038fbe363
commit debd70f269
1 changed files with 40 additions and 25 deletions

View File

@ -146,11 +146,10 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
#ifdef HAVE_KQUEUE
struct kevent evt[2];
static int kq = -1;
#else
#endif
struct timeval w = { 0, 100000 };
int counter = 0;
fd_set readfs;
#endif
struct termios t;
int doread = 0;
@ -172,6 +171,9 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
fflush(stdout);
clearerr (fp);
#ifdef HAVE_KQUEUE
n = -1;
if (kq != -2)
{
EV_SET (&evt[0], STDIN_FILENO, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
EV_SET (&evt[1], fileno (fp), EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
n = kevent (kq, evt, 2, evt, 1, NULL);
@ -179,7 +181,20 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
evt[0].filter == EVFILT_READ) ||
(n >= 2 && evt[1].ident == STDIN_FILENO &&
evt[1].filter == EVFILT_READ);
#else
if (n == -1)
{
/*
* Perhaps kevent(2) doesn't work on this fstype,
* use select(2) instead. Never use kevent again, assuming all
* active ttyrecs are on the same fstype.
*/
close(kq);
kq = -2;
}
}
if (n == -1)
#endif
{
if (counter++ > (20 * 60 * 10))
{
/*
@ -195,7 +210,7 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
FD_SET (STDIN_FILENO, &readfs);
n = select (1, &readfs, NULL, NULL, &w);
doread = n >= 1 && FD_ISSET (0, &readfs);
#endif
}
if (n == -1)
{
printf("select()/kevent() failed.\n");