diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2002-08-16 09:22:29 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2002-08-16 09:22:29 +0200 |
commit | 470415ad230d8455439edadb07dae0a21978783b (patch) | |
tree | 0b0b7fa67f2fde96efb5908a84cad768e84ed9f6 /tools.c | |
parent | 038766dccdcf4aa940a923e3170344611e826e87 (diff) | |
download | vdr-470415ad230d8455439edadb07dae0a21978783b.tar.gz vdr-470415ad230d8455439edadb07dae0a21978783b.tar.bz2 |
Using cPoller instead of NeedsData
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.69 2002/08/11 11:49:08 kls Exp $ + * $Id: tools.c 1.70 2002/08/16 08:52:01 kls Exp $ */ #include "tools.h" @@ -482,6 +482,42 @@ const char *DayDateTime(time_t t) return buffer; } +// --- cPoller --------------------------------------------------------------- + +cPoller::cPoller(int FileHandle, bool Out) +{ + numFileHandles = 0; + Add(FileHandle, Out); +} + +bool cPoller::Add(int FileHandle, bool Out) +{ + if (FileHandle >= 0) { + for (int i = 0; i < numFileHandles; i++) { + if (pfd[i].fd == FileHandle) + return true; + } + if (numFileHandles < MaxPollFiles) { + pfd[numFileHandles].fd = FileHandle; + pfd[numFileHandles].events = Out ? POLLOUT : POLLIN; + numFileHandles++; + return true; + } + esyslog("ERROR: too many file handles in cPoller"); + } + return false; +} + +bool cPoller::Poll(int TimeoutMs) +{ + if (numFileHandles) { + if (poll(pfd, numFileHandles, TimeoutMs) != 0) + return true; // returns true even in case of an error, to let the caller + // access the file and thus see the error code + } + return false; +} + // --- cFile ----------------------------------------------------------------- bool cFile::files[FD_SETSIZE] = { false }; |