1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)wwrint.c 3.6 (Berkeley) 02/21/88"; 15 #endif /* not lint */ 16 17 #include "ww.h" 18 #include <fcntl.h> 19 #include <sys/signal.h> 20 21 /* 22 * Tty input interrupt handler. 23 * (1) Read input into buffer (wwib*). 24 * (2) Set the interrupt flag if anything is read. 25 * Currently, the last is used to get out of the blocking 26 * select() in wwiomux(). 27 * To avoid race conditions, we only modify wwibq in here, except 28 * when the buffer is empty; and everywhere else, we only change wwibp. 29 * It should be completely safe. 30 */ 31 wwrint() 32 { 33 register n; 34 35 if (wwibp == wwibq) 36 wwibp = wwibq = wwib; 37 wwnread++; 38 (void) fcntl(0, F_SETFL, FNDELAY|wwnewtty.ww_fflags); 39 n = read(0, wwibq, wwibe - wwibq); 40 (void) fcntl(0, F_SETFL, wwnewtty.ww_fflags); 41 if (n > 0) { 42 wwibq += n; 43 wwnreadc += n; 44 wwsetintr(); 45 } else if (n == 0) 46 wwnreadz++; 47 else 48 wwnreade++; 49 } 50