summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2002-08-16 09:22:29 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2002-08-16 09:22:29 +0200
commit470415ad230d8455439edadb07dae0a21978783b (patch)
tree0b0b7fa67f2fde96efb5908a84cad768e84ed9f6 /tools.c
parent038766dccdcf4aa940a923e3170344611e826e87 (diff)
downloadvdr-470415ad230d8455439edadb07dae0a21978783b.tar.gz
vdr-470415ad230d8455439edadb07dae0a21978783b.tar.bz2
Using cPoller instead of NeedsData
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/tools.c b/tools.c
index 40aad70a..f5545c34 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.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 };