diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-11-28 17:49:56 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-11-28 17:49:56 +0000 |
commit | f820514c542a093ae7ff2d7db431e6499126014d (patch) | |
tree | 77c8d1b77675d5d4b3e01bde3eb10e573384771e /lib/libcurses/tty/lib_twait.c | |
parent | 6a1dbf2ca7f6d392c63cfb7febcbfd18a8330bb7 (diff) |
update to ncurses-5.0-19991127
Diffstat (limited to 'lib/libcurses/tty/lib_twait.c')
-rw-r--r-- | lib/libcurses/tty/lib_twait.c | 83 |
1 files changed, 64 insertions, 19 deletions
diff --git a/lib/libcurses/tty/lib_twait.c b/lib/libcurses/tty/lib_twait.c index 5a7cffeae2b..0d330245f48 100644 --- a/lib/libcurses/tty/lib_twait.c +++ b/lib/libcurses/tty/lib_twait.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_twait.c,v 1.1 1999/01/18 19:10:27 millert Exp $ */ +/* $OpenBSD: lib_twait.c,v 1.2 1999/11/28 17:49:54 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -42,6 +42,10 @@ ** comments, none of the original code remains - T.Dickey). */ +#ifdef __BEOS__ +#include <OS.h> +#endif + #include <curses.priv.h> #if USE_FUNC_POLL @@ -59,28 +63,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("$From: lib_twait.c,v 1.32 1998/06/06 22:44:14 tom Exp $") +MODULE_ID("$From: 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; } @@ -106,18 +114,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; @@ -135,6 +144,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 @@ -162,10 +205,10 @@ retry: } #endif - returntime = _nc_gettime(); + returntime = _nc_gettime(FALSE); if (milliseconds >= 0) - milliseconds -= returntime-starttime; + milliseconds -= (returntime - starttime); #if PRECISE_GETTIME /* @@ -205,6 +248,8 @@ retry: count++; } } +#elif defined(__BEOS__) + result = 1; /* redundant, but simple */ #elif HAVE_SELECT if ((mode & 2) && (fd = SP->_mouse_fd) >= 0 |