| 1 | /* |
| 2 | * Copyright (c) 1983 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * %sccs.include.redist.c% |
| 6 | */ |
| 7 | |
| 8 | #ifndef lint |
| 9 | static char sccsid[] = "@(#)wwrint.c 3.9 (Berkeley) %G%"; |
| 10 | #endif /* not lint */ |
| 11 | |
| 12 | #include "ww.h" |
| 13 | #include <fcntl.h> |
| 14 | |
| 15 | /* |
| 16 | * Tty input interrupt handler. |
| 17 | * (1) Read input into buffer (wwib*). |
| 18 | * (2) Set the interrupt flag if anything is read. |
| 19 | * Currently, the last is used to get out of the blocking |
| 20 | * select() in wwiomux(). |
| 21 | * To avoid race conditions, we only modify wwibq in here, except |
| 22 | * when the buffer is empty; and everywhere else, we only change wwibp. |
| 23 | * It should be completely safe. |
| 24 | */ |
| 25 | wwrint() |
| 26 | { |
| 27 | register n; |
| 28 | |
| 29 | if (wwibp == wwibq) |
| 30 | wwibp = wwibq = wwib; |
| 31 | wwnread++; |
| 32 | (void) fcntl(0, F_SETFL, FNDELAY|wwnewtty.ww_fflags); |
| 33 | n = read(0, wwibq, wwibe - wwibq); |
| 34 | (void) fcntl(0, F_SETFL, wwnewtty.ww_fflags); |
| 35 | if (n > 0) { |
| 36 | wwibq += n; |
| 37 | wwnreadc += n; |
| 38 | wwsetintr(); |
| 39 | } else if (n == 0) |
| 40 | wwnreadz++; |
| 41 | else |
| 42 | wwnreade++; |
| 43 | } |