summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/backgroundwriter.c14
-rw-r--r--tools/backgroundwriter.h4
2 files changed, 15 insertions, 3 deletions
diff --git a/tools/backgroundwriter.c b/tools/backgroundwriter.c
index 26e1f34b..6dae8e99 100644
--- a/tools/backgroundwriter.c
+++ b/tools/backgroundwriter.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: backgroundwriter.c,v 1.1 2006-06-03 10:04:27 phintuka Exp $
+ * $Id: backgroundwriter.c,v 1.2 2006-06-11 10:19:50 phintuka Exp $
*
*/
@@ -21,6 +21,7 @@
//#define DISABLE_DISCARD
//#define LOG_DISCARDS
+#define MAX_OVERFLOWS_BEFORE_DISCONNECT 500 // ~ 1 second
cBackgroundWriter::cBackgroundWriter(int fd, int Size)
: m_RingBuffer(Size, sizeof(stream_tcp_header_t))
@@ -33,6 +34,8 @@ cBackgroundWriter::cBackgroundWriter(int fd, int Size)
m_DiscardStart = 0;
m_DiscardEnd = 0;
+ m_BufferOverflows = 0;
+
LOGDBG("cBackgroundWriter initialized (buffer %d kb)", Size/1024);
Start();
@@ -196,12 +199,19 @@ int cBackgroundWriter::Put(const uchar *Header, int HeaderCount,
LOCK_THREAD;
if(m_RingBuffer.Free() < HeaderCount+DataCount) {
- LOGMSG("cXinelibServer: TCP buffer overflow !");
+ //LOGMSG("cXinelibServer: TCP buffer overflow !");
+ if(m_BufferOverflows++ > MAX_OVERFLOWS_BEFORE_DISCONNECT) {
+ LOGMSG("cXinelibServer: Too many TCP buffer overflows, dropping client");
+ m_RingBuffer.Clear();
+ m_Active = false;
+ return 0;
+ }
return -HeaderCount-DataCount;
}
int n = m_RingBuffer.Put(Header, HeaderCount) +
m_RingBuffer.Put(Data, DataCount);
if(n == HeaderCount+DataCount) {
+ m_BufferOverflows = 0;
m_PutPos += n;
return n;
}
diff --git a/tools/backgroundwriter.h b/tools/backgroundwriter.h
index 619b2a29..d49ee133 100644
--- a/tools/backgroundwriter.h
+++ b/tools/backgroundwriter.h
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: backgroundwriter.h,v 1.1 2006-06-03 10:04:27 phintuka Exp $
+ * $Id: backgroundwriter.h,v 1.2 2006-06-11 10:19:50 phintuka Exp $
*
*/
@@ -29,6 +29,8 @@ class cBackgroundWriter : public cThread {
uint64_t m_DiscardStart;
uint64_t m_DiscardEnd;
+ int m_BufferOverflows;
+
protected:
virtual void Action(void);