You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.0 KiB

#ifndef TCP_SERVER_HPP
#define TCP_SERVER_HPP
#include "Logger.hpp"
#include "Connection.hpp"
#include "Poll.hpp"
#include <string>
template <typename T>
class TcpServer
{
public:
TcpServer ( const std::string host,
const std::string port,
const int maxClients = 5,
const int maxPendingQueueLen = 10 )
: m_connection(host, port)
, m_poll( &m_connection, maxClients)
, m_maxPendingQueueLen(maxPendingQueueLen)
{
TRACE;
}
virtual ~TcpServer()
{
TRACE;
}
bool start()
{
TRACE;
if ( !m_connection.bindToHost() )
return false;
if ( m_connection.listen( m_maxPendingQueueLen ) == -1 ) {
return false;
}
m_poll.startPolling();
return true;
}
void stop()
{
TRACE;
m_poll.stopPolling();
m_connection.closeConnection();
}
private:
TcpServer(const TcpServer&);
TcpServer& operator=(const TcpServer&);
Connection<T> m_connection;
Poll<T> m_poll;
const int m_maxPendingQueueLen;
};
#endif // TCP_SERVER_HPP