summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorschmirl <schmirl>2007-04-02 10:32:34 +0000
committerschmirl <schmirl>2007-04-02 10:32:34 +0000
commit525574f9b01275aaff3e1c923cc91404365d501e (patch)
tree0533e2aaecdd3e7a1fe26176d12895f9bd054bc0 /server
parentcd7d4e3588af2cc36c8366fc8d65d0627a372c32 (diff)
downloadvdr-plugin-streamdev-525574f9b01275aaff3e1c923cc91404365d501e.tar.gz
vdr-plugin-streamdev-525574f9b01275aaff3e1c923cc91404365d501e.tar.bz2
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
Diffstat (limited to 'server')
-rw-r--r--server/connection.h6
-rw-r--r--server/connectionHTTP.h8
-rw-r--r--server/connectionVTP.h8
-rw-r--r--server/server.c33
-rw-r--r--server/streamer.c9
-rw-r--r--server/streamer.h10
6 files changed, 55 insertions, 19 deletions
diff --git a/server/connection.h b/server/connection.h
index f68f84a..2df850e 100644
--- a/server/connection.h
+++ b/server/connection.h
@@ -1,5 +1,5 @@
/*
- * $Id: connection.h,v 1.3 2005/05/09 20:22:29 lordjaxom Exp $
+ * $Id: connection.h,v 1.4 2007/04/02 10:32:34 schmirl Exp $
*/
#ifndef VDR_STREAMDEV_SERVER_CONNECTION_H
@@ -69,6 +69,10 @@ public:
the connection shall be closed and removed by the server */
virtual bool Read(void);
+ /* Is polled regularely by the server. Returns true if the connection
+ needs to be terminated. */
+ virtual bool Abort(void) const = 0;
+
/* Will make the socket close after sending all queued output data */
void DeferClose(void) { m_DeferClose = true; }
diff --git a/server/connectionHTTP.h b/server/connectionHTTP.h
index d12c418..11e97b7 100644
--- a/server/connectionHTTP.h
+++ b/server/connectionHTTP.h
@@ -1,5 +1,5 @@
/*
- * $Id: connectionHTTP.h,v 1.3 2005/02/11 16:44:15 lordjaxom Exp $
+ * $Id: connectionHTTP.h,v 1.4 2007/04/02 10:32:34 schmirl Exp $
*/
#ifndef VDR_STREAMDEV_SERVERS_CONNECTIONHTTP_H
@@ -52,7 +52,13 @@ public:
virtual bool Command(char *Cmd);
bool CmdGET(const std::string &Opts);
+ virtual bool Abort(void) const;
virtual void Flushed(void);
};
+inline bool cConnectionHTTP::Abort(void) const
+{
+ return m_LiveStreamer && m_LiveStreamer->Abort();
+}
+
#endif // VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H
diff --git a/server/connectionVTP.h b/server/connectionVTP.h
index a8e76eb..c6ab223 100644
--- a/server/connectionVTP.h
+++ b/server/connectionVTP.h
@@ -2,9 +2,9 @@
#define VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H
#include "server/connection.h"
+#include "server/livestreamer.h"
class cTBSocket;
-class cStreamdevLiveStreamer;
class cLSTEHandler;
class cLSTCHandler;
class cLSTTHandler;
@@ -39,6 +39,7 @@ public:
virtual void Welcome(void);
virtual void Reject(void);
+ virtual bool Abort(void) const;
virtual void Detach(void);
virtual void Attach(void);
@@ -72,4 +73,9 @@ public:
__attribute__ ((format (printf, 3, 4)));
};
+inline bool cConnectionVTP::Abort(void) const
+{
+ return m_LiveStreamer && m_LiveStreamer->Abort();
+}
+
#endif // VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H
diff --git a/server/server.c b/server/server.c
index b00f70d..5db895e 100644
--- a/server/server.c
+++ b/server/server.c
@@ -1,5 +1,5 @@
/*
- * $Id: server.c,v 1.4 2006/11/10 11:52:41 schmirl Exp $
+ * $Id: server.c,v 1.5 2007/04/02 10:32:34 schmirl Exp $
*/
#include "server/server.h"
@@ -91,20 +91,29 @@ void cStreamdevServer::Action(void)
select.Add(s->Socket(), true);
}
- int result;
- while ((result = select.Select(100)) < 0 && errno == ETIMEDOUT) {
- if (!m_Active) break;
- }
+ int sel;
+ do
+ {
+ sel = select.Select(400);
+ if (sel < 0 && errno == ETIMEDOUT) {
+ // check for aborted clients
+ for (cServerConnection *s = m_Clients.First(); s; s = m_Clients.Next(s)) {
+ if (s->Abort())
+ sel = 0;
+ }
+ }
+ } while (sel < 0 && errno == ETIMEDOUT && m_Active);
- if (result < 0) {
- if (m_Active) // no exit was requested while polling
- esyslog("fatal error, server exiting: %m");
+ if (!m_Active)
+ break;
+ if (sel < 0) {
+ esyslog("fatal error, server exiting: %m");
break;
}
/* Ask all Server components to act on signalled sockets */
for (cServerComponent *c = m_Servers.First(); c; c = m_Servers.Next(c)){
- if (select.CanRead(c->Socket())) {
+ if (sel && select.CanRead(c->Socket())) {
cServerConnection *client = c->Accept();
m_Clients.Add(client);
@@ -125,11 +134,13 @@ void cStreamdevServer::Action(void)
for (cServerConnection *s = m_Clients.First(); s;) {
bool result = true;
- if (select.CanWrite(s->Socket()))
+ if (sel && select.CanWrite(s->Socket()))
result = s->Write();
- if (result && select.CanRead(s->Socket()))
+ if (sel && result && select.CanRead(s->Socket()))
result = s->Read();
+
+ result &= !s->Abort();
cServerConnection *next = m_Clients.Next(s);
if (!result) {
diff --git a/server/streamer.c b/server/streamer.c
index 582fc6a..63d2f60 100644
--- a/server/streamer.c
+++ b/server/streamer.c
@@ -1,5 +1,5 @@
/*
- * $Id: streamer.c,v 1.14 2005/05/09 20:22:29 lordjaxom Exp $
+ * $Id: streamer.c,v 1.15 2007/04/02 10:32:34 schmirl Exp $
*/
#include <vdr/ringbuffer.h>
@@ -40,6 +40,9 @@ void cStreamdevWriter::Action(void)
uchar *block = NULL;
int count, offset = 0;
m_Active = true;
+
+ sel.Clear();
+ sel.Add(*m_Socket, true);
while (m_Active) {
if (block == NULL) {
block = m_Streamer->Get(count);
@@ -47,9 +50,7 @@ void cStreamdevWriter::Action(void)
}
if (block != NULL) {
- sel.Clear();
- sel.Add(*m_Socket, true);
- if (sel.Select(500) == -1) {
+ if (sel.Select(15000) == -1) {
esyslog("ERROR: streamdev-server: couldn't send data: %m");
break;
}
diff --git a/server/streamer.h b/server/streamer.h
index c27677c..e557d55 100644
--- a/server/streamer.h
+++ b/server/streamer.h
@@ -1,5 +1,5 @@
/*
- * $Id: streamer.h,v 1.7 2005/03/12 12:54:19 lordjaxom Exp $
+ * $Id: streamer.h,v 1.8 2007/04/02 10:32:34 schmirl Exp $
*/
#ifndef VDR_STREAMDEV_STREAMER_H
@@ -29,6 +29,8 @@ protected:
public:
cStreamdevWriter(cTBSocket *Socket, cStreamdevStreamer *Streamer);
virtual ~cStreamdevWriter();
+
+ bool IsActive(void) const { return m_Active; }
};
// --- cStreamdevStreamer -----------------------------------------------------
@@ -52,6 +54,7 @@ public:
virtual void Start(cTBSocket *Socket);
virtual void Stop(void);
+ bool Abort(void) const;
void Activate(bool On);
int Receive(uchar *Data, int Length) { return m_RingBuffer->Put(Data, Length); }
@@ -65,5 +68,10 @@ public:
virtual void Attach(void) {}
};
+inline bool cStreamdevStreamer::Abort(void) const
+{
+ return m_Active && !m_Writer->IsActive();
+}
+
#endif // VDR_STREAMDEV_STREAMER_H