aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/ncurses/tty/lib_twait.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ncurses/ncurses/tty/lib_twait.c')
-rw-r--r--contrib/ncurses/ncurses/tty/lib_twait.c81
1 files changed, 63 insertions, 18 deletions
diff --git a/contrib/ncurses/ncurses/tty/lib_twait.c b/contrib/ncurses/ncurses/tty/lib_twait.c
index 40bd2cd3044f..f095c9b53c0c 100644
--- a/contrib/ncurses/ncurses/tty/lib_twait.c
+++ b/contrib/ncurses/ncurses/tty/lib_twait.c
@@ -40,6 +40,10 @@
** comments, none of the original code remains - T.Dickey).
*/
+#ifdef __BEOS__
+#include <OS.h>
+#endif
+
#include <curses.priv.h>
#if USE_FUNC_POLL
@@ -57,28 +61,32 @@
# endif
#endif
-#ifdef __BEOS__
-/* BeOS select() only works on sockets. Use the tty hack instead */
-#include <socket.h>
-#define select check_select
-#endif
-
-MODULE_ID("$Id: lib_twait.c,v 1.32 1998/06/06 22:44:14 tom Exp $")
+MODULE_ID("$Id: lib_twait.c,v 1.34 1999/10/16 21:25:10 tom Exp $")
-static int _nc_gettime(void)
+static long _nc_gettime(bool first)
{
- int res;
+ long res;
#if HAVE_GETTIMEOFDAY
# define PRECISE_GETTIME 1
- struct timeval t;
- gettimeofday(&t, (struct timezone *)0);
- res = t.tv_sec*1000 + t.tv_usec/1000;
+ static struct timeval t0;
+ struct timeval t1;
+ gettimeofday(&t1, (struct timezone *)0);
+ if (first) {
+ t0 = t1;
+ }
+ res = (t1.tv_sec - t0.tv_sec) * 1000
+ + (t1.tv_usec - t0.tv_usec) / 1000;
#else
# define PRECISE_GETTIME 0
- res = time(0)*1000;
+ static time_t t0;
+ time_t t1 = time((time_t*)0);
+ if (first) {
+ t0 = t1;
+ }
+ res = (t1 - t0) * 1000;
#endif
- T(("time: %d msec", res));
+ T(("%s time: %ld msec", first ? "get" : "elapsed", res));
return res;
}
@@ -104,18 +112,19 @@ int result;
#if USE_FUNC_POLL
struct pollfd fds[2];
+#elif defined(__BEOS__)
#elif HAVE_SELECT
static fd_set set;
#endif
-int starttime, returntime;
+long starttime, returntime;
T(("start twait: %d milliseconds, mode: %d", milliseconds, mode));
#if PRECISE_GETTIME
retry:
#endif
- starttime = _nc_gettime();
+ starttime = _nc_gettime(TRUE);
count = 0;
@@ -133,6 +142,40 @@ retry:
}
result = poll(fds, count, milliseconds);
+#elif defined(__BEOS__)
+ /*
+ * BeOS's select() is declared in socket.h, so the configure script does
+ * not see it. That's just as well, since that function works only for
+ * sockets. This (using snooze and ioctl) was distilled from Be's patch
+ * for ncurses which uses a separate thread to simulate select().
+ *
+ * FIXME: the return values from the ioctl aren't very clear if we get
+ * interrupted.
+ */
+ result = 0;
+ if (mode & 1) {
+ bigtime_t d;
+ bigtime_t useconds = milliseconds * 1000;
+ int n, howmany;
+
+ if (useconds == 0) /* we're here to go _through_ the loop */
+ useconds = 1;
+
+ for (d = 0; d < useconds; d += 5000) {
+ n = 0;
+ howmany = ioctl(0, 'ichr', &n);
+ if (howmany >= 0 && n > 0) {
+ result = 1;
+ break;
+ }
+ if (useconds > 1)
+ snooze(5000);
+ milliseconds -= 5;
+ }
+ } else if (milliseconds > 0) {
+ snooze(milliseconds * 1000);
+ milliseconds = 0;
+ }
#elif HAVE_SELECT
/*
* select() modifies the fd_set arguments; do this in the
@@ -160,10 +203,10 @@ retry:
}
#endif
- returntime = _nc_gettime();
+ returntime = _nc_gettime(FALSE);
if (milliseconds >= 0)
- milliseconds -= returntime-starttime;
+ milliseconds -= (returntime - starttime);
#if PRECISE_GETTIME
/*
@@ -203,6 +246,8 @@ retry:
count++;
}
}
+#elif defined(__BEOS__)
+ result = 1; /* redundant, but simple */
#elif HAVE_SELECT
if ((mode & 2)
&& (fd = SP->_mouse_fd) >= 0