Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!uwvax!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: Porting AT&T ioctl()'s to BSD??? Message-ID: <15231@mimsy.UUCP> Date: 2 Jan 89 23:11:28 GMT References: <7300002@fthood> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 45 In article <7300002@fthood> egray@fthood.UUCP writes: >I need the ability to flush the TTY input queue, output queue, or both >similar to what AT&T does with ioctl(fd, TCFLSH, n). I can't use >BSD's icotl(fd, TCIOFLUSH, 0) since it always flushed both queues. TIOCFLUSH actually does either or both, although I am unsure whether it is documented properly: #include #include #include foo() { int r = FREAD, w = FWRITE, rw = FREAD|FWRITE; ... ioctl(fd, TIOCFLUSH, (caddr_t)&r) ... /* flush input */ ... ioctl(fd, TIOCFLUSH, (caddr_t)&w) ... /* flush output */ ... ioctl(fd, TIOCFLUSH, (caddr_t)&rw) ... /* flush both */ In fact, ioctl(fd, TIOCFLUSH, (caddr_t)0) (with or without the cast to caddr_t or `char *') is illegal, and merely `happens to work' on a Vax running stock 4BSD. You should always pass the address of an `int' that is set to some combination of FREAD and FWRITE, or to 0 (which means the same as FREAD|FWRITE). >Also, I'd like a way to emulate AT&T's ioctl(fd, TCSBRK, 1) that waits >for the output of the queue to drain. I suspect BSD's select() could >be used? Not directly: select tells you when an I/O operation would not block (which is why select-for-read is true at EOF on pipes, for instance). The easiest thing to do is to wait for the POSIX tty driver in 4.4BSD (or whatever the next BSD will be called). If you really need to wait for the tty output queue to drain (which typically has no effect anyway if, e.g., one is logged in across a network), TIOCSETP does this, although it then also flushes pending input and sets the terminal interpretation modes; or, you can use TIOCOUTQ and select() timeouts together. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris