mirror of
https://projects.vdr-developer.org/git/vdr-plugin-streamdev.git
synced 2023-10-10 17:16:51 +00:00
Close connection when client is gone. Fixes high CPU load problem (#201)
Modified Files: server/connection.h server/connectionHTTP.h server/connectionVTP.h server/server.c server/streamer.c server/streamer.h tools/select.c tools/select.h tools/source.c
This commit is contained in:
@@ -21,19 +21,21 @@ int cTBSelect::Select(uint TimeoutMs) {
|
||||
|
||||
tv.tv_usec = (TimeoutMs % 1000) * 1000;
|
||||
tv.tv_sec = TimeoutMs / 1000;
|
||||
memcpy(m_FdsResult, m_FdsQuery, sizeof(m_FdsResult));
|
||||
|
||||
if (TimeoutMs == 0)
|
||||
return ::select(m_MaxFiled + 1, &m_Rfds, &m_Wfds, NULL, &tv);
|
||||
return ::select(m_MaxFiled + 1, &m_FdsResult[0], &m_FdsResult[1], NULL, &tv);
|
||||
|
||||
cTimeMs starttime;
|
||||
ms = TimeoutMs;
|
||||
while (ms > 0 && (res = ::select(m_MaxFiled + 1, &m_Rfds, &m_Wfds, NULL,
|
||||
while (ms > 0 && (res = ::select(m_MaxFiled + 1, &m_FdsResult[0], &m_FdsResult[1], NULL,
|
||||
&tv)) == -1 && errno == EINTR) {
|
||||
ms = TimeoutMs - starttime.Elapsed();
|
||||
tv.tv_usec = (ms % 1000) * 1000;
|
||||
tv.tv_sec = ms / 1000;
|
||||
memcpy(m_FdsResult, m_FdsQuery, sizeof(m_FdsResult));
|
||||
}
|
||||
if (ms <= 0) {
|
||||
if (ms <= 0 || res == 0) {
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
@@ -42,8 +44,8 @@ int cTBSelect::Select(uint TimeoutMs) {
|
||||
|
||||
int cTBSelect::Select(void) {
|
||||
ssize_t res;
|
||||
while ((res = ::select(m_MaxFiled + 1, &m_Rfds, &m_Wfds, NULL, NULL)) == -1
|
||||
&& errno == EINTR)
|
||||
;
|
||||
do {
|
||||
memcpy(m_FdsResult, m_FdsQuery, sizeof(m_FdsResult));
|
||||
} while ((res = ::select(m_MaxFiled + 1, &m_FdsResult[0], &m_FdsResult[1], NULL, NULL)) == -1 && errno == EINTR);
|
||||
return res;
|
||||
}
|
||||
|
@@ -11,8 +11,8 @@ class cTBSelect {
|
||||
private:
|
||||
int m_MaxFiled;
|
||||
|
||||
fd_set m_Rfds;
|
||||
fd_set m_Wfds;
|
||||
fd_set m_FdsQuery[2];
|
||||
fd_set m_FdsResult[2];
|
||||
|
||||
public:
|
||||
cTBSelect(void);
|
||||
@@ -50,26 +50,26 @@ public:
|
||||
};
|
||||
|
||||
inline void cTBSelect::Clear(void) {
|
||||
FD_ZERO(&m_Rfds);
|
||||
FD_ZERO(&m_Wfds);
|
||||
FD_ZERO(&m_FdsQuery[0]);
|
||||
FD_ZERO(&m_FdsQuery[1]);
|
||||
m_MaxFiled = -1;
|
||||
}
|
||||
|
||||
inline bool cTBSelect::Add(int Filed, bool Output /* = false */) {
|
||||
if (Filed < 0) return false;
|
||||
FD_SET(Filed, Output ? &m_Wfds : &m_Rfds);
|
||||
FD_SET(Filed, &m_FdsQuery[Output ? 1 : 0]);
|
||||
if (Filed > m_MaxFiled) m_MaxFiled = Filed;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool cTBSelect::CanRead(int FileNo) const {
|
||||
if (FileNo < 0) return false;
|
||||
return FD_ISSET(FileNo, &m_Rfds);
|
||||
return FD_ISSET(FileNo, &m_FdsResult[0]);
|
||||
}
|
||||
|
||||
inline bool cTBSelect::CanWrite(int FileNo) const {
|
||||
if (FileNo < 0) return false;
|
||||
return FD_ISSET(FileNo, &m_Wfds);
|
||||
return FD_ISSET(FileNo, &m_FdsResult[1]);
|
||||
}
|
||||
|
||||
#endif // TOOLBOX_SELECT_H
|
||||
|
@@ -61,11 +61,11 @@ bool cTBSource::TimedWrite(const void *Buffer, size_t Length, uint TimeoutMs) {
|
||||
cTimeMs starttime;
|
||||
ms = TimeoutMs;
|
||||
offs = 0;
|
||||
sel.Clear();
|
||||
sel.Add(m_Filed, true);
|
||||
while (Length > 0) {
|
||||
int b;
|
||||
|
||||
sel.Clear();
|
||||
sel.Add(m_Filed, true);
|
||||
if (sel.Select(ms) == -1)
|
||||
return false;
|
||||
|
||||
@@ -90,11 +90,11 @@ bool cTBSource::SafeWrite(const void *Buffer, size_t Length) {
|
||||
int offs;
|
||||
|
||||
offs = 0;
|
||||
sel.Clear();
|
||||
sel.Add(m_Filed, true);
|
||||
while (Length > 0) {
|
||||
int b;
|
||||
|
||||
sel.Clear();
|
||||
sel.Add(m_Filed, true);
|
||||
if (sel.Select() == -1)
|
||||
return false;
|
||||
|
||||
@@ -128,9 +128,9 @@ ssize_t cTBSource::ReadUntil(void *Buffer, size_t Length, const char *Seq,
|
||||
|
||||
cTimeMs starttime;
|
||||
ms = TimeoutMs;
|
||||
sel.Clear();
|
||||
sel.Add(m_Filed, false);
|
||||
while (m_LineBuffer.size() < BUFSIZ) {
|
||||
sel.Clear();
|
||||
sel.Add(m_Filed, false);
|
||||
|
||||
if (sel.Select(ms) == -1)
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user