vdr-plugin-streamdev/server/component.c

50 lines
1.2 KiB
C
Raw Normal View History

2004-12-30 23:43:55 +01:00
/*
* $Id: component.c,v 1.3.2.1 2009/02/13 10:39:42 schmirl Exp $
2004-12-30 23:43:55 +01:00
*/
#include "server/component.h"
#include "server/connection.h"
cServerComponent::cServerComponent(const char *Protocol, const char *ListenIp,
uint ListenPort, int Type, int IpProto):
2005-05-09 22:22:29 +02:00
m_Protocol(Protocol),
m_Listen(Type, IpProto),
2005-05-09 22:22:29 +02:00
m_ListenIp(ListenIp),
m_ListenPort(ListenPort)
{
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
cServerComponent::~cServerComponent()
{
2004-12-30 23:43:55 +01:00
}
2005-05-09 22:22:29 +02:00
bool cServerComponent::Initialize(void)
{
2004-12-30 23:43:55 +01:00
if (!m_Listen.Listen(m_ListenIp, m_ListenPort, 5)) {
2005-05-09 22:22:29 +02:00
esyslog("Streamdev: Couldn't listen (%s) %s:%d: %m",
m_Protocol, m_ListenIp, m_ListenPort);
2004-12-30 23:43:55 +01:00
return false;
}
isyslog("Streamdev: Listening (%s) on port %d", m_Protocol, m_ListenPort);
return true;
}
2005-05-09 22:22:29 +02:00
void cServerComponent::Destruct(void)
{
2004-12-30 23:43:55 +01:00
m_Listen.Close();
}
2005-05-09 22:22:29 +02:00
cServerConnection *cServerComponent::Accept(void)
{
cServerConnection *client = NewClient();
if (client->Accept(m_Listen)) {
isyslog("Streamdev: Accepted new client (%s) %s:%d", m_Protocol,
client->RemoteIp().c_str(), client->RemotePort());
return client;
} else {
esyslog("Streamdev: Couldn't accept (%s): %m", m_Protocol);
delete client;
2004-12-30 23:43:55 +01:00
}
return NULL;
}