From ba70704694e879246856d6bb98be3e3d01ab0156 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Mon, 24 Apr 2000 15:32:11 +0200 Subject: Improved replay progress display --- tools.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tools.c') diff --git a/tools.c b/tools.c index c43e610f..eb0a14a4 100644 --- a/tools.c +++ b/tools.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.6 2000/04/24 13:54:23 kls Exp $ + * $Id: tools.c 1.7 2000/04/24 15:01:35 kls Exp $ */ #define _GNU_SOURCE @@ -22,6 +22,17 @@ int SysLogLevel = 3; +bool DataAvailable(int filedes) +{ + fd_set set; + FD_ZERO(&set); + FD_SET(filedes, &set); + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 10000; + return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && FD_ISSET(filedes, &set); +} + void writechar(int filedes, char c) { write(filedes, &c, sizeof(c)); @@ -41,7 +52,13 @@ char readchar(int filedes) bool readint(int filedes, int &n) { - return read(filedes, &n, sizeof(n)) == sizeof(n); + return DataAvailable(filedes) && read(filedes, &n, sizeof(n)) == sizeof(n); +} + +void purge(int filedes) +{ + while (DataAvailable(filedes)) + readchar(filedes); } char *readline(FILE *f) -- cgit v1.2.3