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:
parent
8038fbe363
commit
debd70f269
65
ttyplay.c
65
ttyplay.c
|
@ -146,11 +146,10 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
|
||||||
#ifdef HAVE_KQUEUE
|
#ifdef HAVE_KQUEUE
|
||||||
struct kevent evt[2];
|
struct kevent evt[2];
|
||||||
static int kq = -1;
|
static int kq = -1;
|
||||||
#else
|
#endif
|
||||||
struct timeval w = { 0, 100000 };
|
struct timeval w = { 0, 100000 };
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
fd_set readfs;
|
fd_set readfs;
|
||||||
#endif
|
|
||||||
struct termios t;
|
struct termios t;
|
||||||
int doread = 0;
|
int doread = 0;
|
||||||
|
|
||||||
|
@ -172,30 +171,46 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
clearerr (fp);
|
clearerr (fp);
|
||||||
#ifdef HAVE_KQUEUE
|
#ifdef HAVE_KQUEUE
|
||||||
EV_SET (&evt[0], STDIN_FILENO, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
|
n = -1;
|
||||||
EV_SET (&evt[1], fileno (fp), EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
|
if (kq != -2)
|
||||||
n = kevent (kq, evt, 2, evt, 1, NULL);
|
{
|
||||||
doread = (n >= 1 && evt[0].ident == STDIN_FILENO &&
|
EV_SET (&evt[0], STDIN_FILENO, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
|
||||||
evt[0].filter == EVFILT_READ) ||
|
EV_SET (&evt[1], fileno (fp), EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
|
||||||
(n >= 2 && evt[1].ident == STDIN_FILENO &&
|
n = kevent (kq, evt, 2, evt, 1, NULL);
|
||||||
evt[1].filter == EVFILT_READ);
|
doread = (n >= 1 && evt[0].ident == STDIN_FILENO &&
|
||||||
#else
|
evt[0].filter == EVFILT_READ) ||
|
||||||
if (counter++ > (20 * 60 * 10))
|
(n >= 2 && evt[1].ident == STDIN_FILENO &&
|
||||||
{
|
evt[1].filter == EVFILT_READ);
|
||||||
/*
|
if (n == -1)
|
||||||
* The reason for this timeout is that the select() method uses
|
{
|
||||||
* some CPU in waiting. The kqueue() method does not do that, so it
|
/*
|
||||||
* does not need the timeout.
|
* Perhaps kevent(2) doesn't work on this fstype,
|
||||||
*/
|
* use select(2) instead. Never use kevent again, assuming all
|
||||||
endwin ();
|
* active ttyrecs are on the same fstype.
|
||||||
printf ("Exiting due to 20 minutes of inactivity.\n");
|
*/
|
||||||
exit (-23);
|
close(kq);
|
||||||
}
|
kq = -2;
|
||||||
FD_ZERO (&readfs);
|
}
|
||||||
FD_SET (STDIN_FILENO, &readfs);
|
}
|
||||||
n = select (1, &readfs, NULL, NULL, &w);
|
if (n == -1)
|
||||||
doread = n >= 1 && FD_ISSET (0, &readfs);
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
if (counter++ > (20 * 60 * 10))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The reason for this timeout is that the select() method uses
|
||||||
|
* some CPU in waiting. The kqueue() method does not do that, so it
|
||||||
|
* does not need the timeout.
|
||||||
|
*/
|
||||||
|
endwin ();
|
||||||
|
printf ("Exiting due to 20 minutes of inactivity.\n");
|
||||||
|
exit (-23);
|
||||||
|
}
|
||||||
|
FD_ZERO (&readfs);
|
||||||
|
FD_SET (STDIN_FILENO, &readfs);
|
||||||
|
n = select (1, &readfs, NULL, NULL, &w);
|
||||||
|
doread = n >= 1 && FD_ISSET (0, &readfs);
|
||||||
|
}
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
{
|
{
|
||||||
printf("select()/kevent() failed.\n");
|
printf("select()/kevent() failed.\n");
|
||||||
|
|
Loading…
Reference in New Issue