summaryrefslogtreecommitdiff
path: root/tools/select.c
diff options
context:
space:
mode:
authorzwer <zwer@1f4bef6d-8e0a-0410-8695-e467da8aaccf>2006-01-24 13:13:39 +0000
committerzwer <zwer@1f4bef6d-8e0a-0410-8695-e467da8aaccf>2006-01-24 13:13:39 +0000
commit0d14897dfb0fe4310ccb2bb51a5960a03d5a5bc6 (patch)
tree7b65667843ea5db07766d23688f045d20140361c /tools/select.c
parente1dadf2dbdd2bcf65517310498ded03c821e463e (diff)
downloadvdr-plugin-ffnetdev-0d14897dfb0fe4310ccb2bb51a5960a03d5a5bc6.tar.gz
vdr-plugin-ffnetdev-0d14897dfb0fe4310ccb2bb51a5960a03d5a5bc6.tar.bz2
Im Projektarchiv verschoben
git-svn-id: svn://svn.berlios.de/ffnetdev/trunk@5 1f4bef6d-8e0a-0410-8695-e467da8aaccf
Diffstat (limited to 'tools/select.c')
-rw-r--r--tools/select.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/select.c b/tools/select.c
new file mode 100644
index 0000000..0ab5f9b
--- /dev/null
+++ b/tools/select.c
@@ -0,0 +1,49 @@
+#include "tools/select.h"
+
+#include <vdr/tools.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+cTBSelect::cTBSelect(void) {
+ Clear();
+}
+
+cTBSelect::~cTBSelect() {
+}
+
+int cTBSelect::Select(uint TimeoutMs) {
+ struct timeval tv;
+ ssize_t res;
+ int ms;
+
+ tv.tv_usec = (TimeoutMs % 1000) * 1000;
+ tv.tv_sec = TimeoutMs / 1000;
+
+ if (TimeoutMs == 0)
+ return ::select(m_MaxFiled + 1, &m_Rfds, &m_Wfds, NULL, &tv);
+
+ cTimeMs starttime;
+ ms = TimeoutMs;
+ while (ms > 0 && (res = ::select(m_MaxFiled + 1, &m_Rfds, &m_Wfds, NULL,
+ &tv)) == -1 && errno == EINTR) {
+ ms = TimeoutMs - starttime.Elapsed();
+ tv.tv_usec = (ms % 1000) * 1000;
+ tv.tv_sec = ms / 1000;
+ }
+ if (ms <= 0) {
+ errno = ETIMEDOUT;
+ return -1;
+ }
+ return res;
+}
+
+int cTBSelect::Select(void) {
+ ssize_t res;
+ while ((res = ::select(m_MaxFiled + 1, &m_Rfds, &m_Wfds, NULL, NULL)) == -1
+ && errno == EINTR)
+ ;
+ return res;
+}