diff options
author | Frank Schmirler <schmirl@puter.linogate.de> | 2010-12-02 08:53:01 +0100 |
---|---|---|
committer | Frank Schmirler <schmirl@puter.linogate.de> | 2010-12-02 08:53:01 +0100 |
commit | 5e30711bfdb28085234a5ef6da4f4e44305ac3e4 (patch) | |
tree | d15809d23eeeed7fda55d9450b1af7c99d6eb5d6 /tools/select.c | |
download | vdr-plugin-streamdev-5e30711bfdb28085234a5ef6da4f4e44305ac3e4.tar.gz vdr-plugin-streamdev-5e30711bfdb28085234a5ef6da4f4e44305ac3e4.tar.bz2 |
Snapshot 2007-03-20
Diffstat (limited to 'tools/select.c')
-rw-r--r-- | tools/select.c | 49 |
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; +} |