|
|
1.1 ! root 1: /* ! 2: * Code for various kinds of delays. Most of this is nonportable and ! 3: * requires various enhancements to the operating system, so it won't ! 4: * work on all systems. It is included in curses to provide a portable ! 5: * interface, and so curses itself can use it for function keys. ! 6: */ ! 7: ! 8: /* @(#) draino.c: 1.1 10/15/83 (1.10 3/6/83) */ ! 9: ! 10: #include "curses.ext" ! 11: #include <signal.h> ! 12: ! 13: #define NAPINTERVAL 100 ! 14: #define HZ 60 ! 15: ! 16: /* From early specs - this may change by 4.2BSD */ ! 17: struct _timeval { ! 18: long tv_sec; ! 19: long tv_usec; ! 20: }; ! 21: ! 22: /* ! 23: * Wait until the output has drained enough that it will only take ! 24: * ms more milliseconds to drain completely. ! 25: * Needs Berkeley TIOCOUTQ ioctl. Returns ERR if impossible. ! 26: */ ! 27: int ! 28: draino(ms) ! 29: int ms; ! 30: { ! 31: int ncthere; /* number of chars actually in output queue */ ! 32: int ncneeded; /* number of chars = that many ms */ ! 33: int rv; /* ioctl return value */ ! 34: ! 35: #ifdef TIOCOUTQ ! 36: # define _DRAINO ! 37: /* 10 bits/char, 1000 ms/sec, baudrate in bits/sec */ ! 38: ncneeded = baudrate() * ms / (10 * 1000); ! 39: for (;;) { ! 40: ncthere = 0; ! 41: rv = ioctl(cur_term->Filedes, TIOCOUTQ, &ncthere); ! 42: #ifdef DEBUG ! 43: fprintf(outf, "draino: rv %d, ncneeded %d, ncthere %d\n", ! 44: rv, ncneeded, ncthere); ! 45: #endif ! 46: if (rv < 0) ! 47: return ERR; /* ioctl didn't work */ ! 48: if (ncthere <= ncneeded) { ! 49: return 0; ! 50: } ! 51: napms(NAPINTERVAL); ! 52: } ! 53: #endif ! 54: ! 55: #ifdef TCSETAW ! 56: # define _DRAINO ! 57: /* ! 58: * USG simulation - waits until the entire queue is empty, ! 59: * then sets the state to what it already is (e.g. no-op). ! 60: * Unfortunately this only works if ms is zero. ! 61: */ ! 62: if (ms <= 0) { ! 63: ioctl(cur_term->Filedes, TCSETAW, cur_term->Nttyb); ! 64: return OK; ! 65: } ! 66: #endif ! 67: ! 68: #ifndef _DRAINO ! 69: /* No way to fake it, so we return failure. */ ! 70: /* Used #else to avoid warning from compiler about unreached stmt */ ! 71: return ERR; ! 72: #endif ! 73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.