Ejemplo n.º 1
0
////////////////////////////////////////////////////////////////////////////////
/// Registers a client connection handler with the server.
///
/// @ErrorHandling Throws a std::runtime_error if either m_handler has already
/// been initialized or the passed function is null.
/// @pre m_handler must not be initialized.
/// @post Assigns the passed function to m_handler.
/// @param h The callback function to handle client connections.
///
/// @limitations This function can only be called once.
////////////////////////////////////////////////////////////////////////////////
void CTcpServer::RegisterHandler(ConnectionHandler h)
{
    Logger.Trace << hdr() << __PRETTY_FUNCTION__ << std::endl;

    if( !m_handler.empty() )
    {
        throw std::runtime_error(hdr() + "Cannot override client handler.");
    }

    if( h.empty() )
    {
        throw std::runtime_error(hdr() + "Cannot use null client handler.");
    }

    m_handler = h;

    Logger.Notice << hdr() << "Set client connection handler." << std::endl;
}