blob: 77229c8e373f0b7adb2e483a9b44a2d2340e6be1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#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;
time_t st, et;
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);
st = time_ms();
ms = TimeoutMs;
while (ms > 0 && (res = ::select(m_MaxFiled + 1, &m_Rfds, &m_Wfds, NULL,
&tv)) == -1 && errno == EINTR) {
et = time_ms();
ms -= et - st;
tv.tv_usec = (ms % 1000) * 1000;
tv.tv_sec = ms / 1000;
st = et;
}
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;
}
|