Commit | Line | Data |
---|---|---|
60de5df9 | 1 | /* |
46e9ea25 KB |
2 | * Copyright (c) 1983 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
87f529ec | 5 | * %sccs.include.redist.c% |
60de5df9 EW |
6 | */ |
7 | ||
46e9ea25 | 8 | #ifndef lint |
87f529ec | 9 | static char sccsid[] = "@(#)wwrint.c 3.9 (Berkeley) %G%"; |
46e9ea25 KB |
10 | #endif /* not lint */ |
11 | ||
78b88f48 EW |
12 | #include "ww.h" |
13 | #include <fcntl.h> | |
78b88f48 EW |
14 | |
15 | /* | |
16 | * Tty input interrupt handler. | |
17 | * (1) Read input into buffer (wwib*). | |
16078900 | 18 | * (2) Set the interrupt flag if anything is read. |
78b88f48 EW |
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; | |
16078900 | 38 | wwsetintr(); |
78b88f48 EW |
39 | } else if (n == 0) |
40 | wwnreadz++; | |
41 | else | |
42 | wwnreade++; | |
78b88f48 | 43 | } |