Main application class for stand-alone tntnet web application. More...

#include <tnt/tntnet.h>

Public Member Functions

 Tntnet ()
 Create a Tntnet object with default configuration.
 Tntnet (const Tntnet &t)
 Copy constructor.
Tntnetoperator= (const Tntnet &t)
 Assignment.
void init (const TntConfig &config)
 Load server configuration from a TntConfig object.
void listen (const std::string &ipaddr, unsigned short int port)
 Set up a listener for the specified ip address and port.
void listen (unsigned short int port)
 Set up a listener for the specified port which listens on all local interfaces.
void sslListen (const std::string &certificateFile, const std::string &keyFile, const std::string &ipaddr, unsigned short int port)
 Set up a ssl listener for the specified ip address and port.
void sslListen (const std::string &certificateFile, const std::string &keyFile, unsigned short int port)
 Set up a ssl listener for the specified port which listens on all local interfaces.
void run ()
 Start all needed threads and the application loop.
unsigned getMinThreads () const
 Get the minimum number of worker threads.
void setMinThreads (unsigned n)
 Set the minimum number of worker threads.
unsigned getMaxThreads () const
 Get the maximum number of worker threads.
void setMaxThreads (unsigned n)
 Set the maximum number of worker threads.

Static Public Member Functions

static void shutdown ()
 Request all Tntnet instances to shut down.
static bool shouldStop ()
 Tells whether a shutdown request was initiated.

URL mapping

Add a mapping from a url to a component

The matching url's are specified using a regular expression. The mapping target may contain back references to the expression using $1, $2 and so on.

Parameters
urlThe path requested by the client. The path includes everything between the domain name and the get parameters. It always begins with a '/'.
ciThe identifier for the component to which the url is mapped. The first method simply passes the string to the CompIdent constructor.
MappingmapUrl (const std::string &url, const std::string &ci)
MappingmapUrl (const std::string &url, const Compident &ci)
void mapUrl (const std::string &url, const std::string &pathinfo, const std::string &ci)
MappingmapUrl (const std::string &url, const Maptarget &ci)
MappingvMapUrl (const std::string &vhost, const std::string &url, const Maptarget &ci)
void setAppName (const std::string &appname)
 Set the app name.
const std::string & getAppName () const
 Get the app name – for details see setAppName()
void setAccessLog (const std::string &logfile_path)
 Enable access logging.

Detailed Description

Main application class for stand-alone tntnet web application.

The Tntnet class is used to compile a web application into a simple executable. The compiled program then works as a webserver, handling the server requests for the web application. This is the alternative to compiling it into a shared library and using the tntnet program to handle the server requests.

This is the minimal set of things you have to include in your code to create a standalone tntnet web application:

  • The instantiation of a Tntnet object
  • A call to listen and/or sslListen
  • One or more calls to mapUrl or vMapUrl
  • A call to run()

Example:

#include <iostream>
#include <tnt/tntnet.h>
int main()
{
try
{
app.listen(8000);
app.mapUrl("^/$", "index");
app.mapUrl("^/(.*)$", "$1");
app.mapUrl("^/.*$", "404");
app.run();
}
catch(const std::exception& e)
{
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}

Constructor & Destructor Documentation

tnt::Tntnet::Tntnet ( )

Create a Tntnet object with default configuration.

For information on the default configuration options, see TntConfig.

tnt::Tntnet::Tntnet ( const Tntnet t)

Copy constructor.

Both instances will point to the same implementation.

Member Function Documentation

const std::string& tnt::Tntnet::getAppName ( ) const

Get the app name – for details see setAppName()

unsigned tnt::Tntnet::getMaxThreads ( ) const

Get the maximum number of worker threads.

unsigned tnt::Tntnet::getMinThreads ( ) const

Get the minimum number of worker threads.

void tnt::Tntnet::init ( const TntConfig config)

Load server configuration from a TntConfig object.

void tnt::Tntnet::listen ( const std::string &  ipaddr,
unsigned short int  port 
)

Set up a listener for the specified ip address and port.

An empty string means listening on all interfaces – you can simply use the listen() method with one parameter to do that though.

This method solely does the setup, the actual listening starts in run().

void tnt::Tntnet::listen ( unsigned short int  port)
inline

Set up a listener for the specified port which listens on all local interfaces.

As the above method, this doesn't start the actual listening.

Mapping& tnt::Tntnet::mapUrl ( const std::string &  url,
const std::string &  ci 
)
Mapping& tnt::Tntnet::mapUrl ( const std::string &  url,
const Compident ci 
)
void tnt::Tntnet::mapUrl ( const std::string &  url,
const std::string &  pathinfo,
const std::string &  ci 
)
Mapping& tnt::Tntnet::mapUrl ( const std::string &  url,
const Maptarget &  ci 
)
Tntnet& tnt::Tntnet::operator= ( const Tntnet t)

Assignment.

Both instances will point to the same implementation.

void tnt::Tntnet::run ( )

Start all needed threads and the application loop.

If no listeners were set up through listen or sslListen, a default listener is instantiated. It listens on all local interfaces on either port 80 (when the program is executed as root) or port 8000 (other users).

void tnt::Tntnet::setAccessLog ( const std::string &  logfile_path)

Enable access logging.

The used log format is the common logfile format (CLF), the same format Apache uses for its access logs.

Parameters
logfile_pathThe path to the log file.
void tnt::Tntnet::setAppName ( const std::string &  appname)

Set the app name.

The app name is used for the session cookie name if the web application is linked directly to a stand-alone executable. The name of the session cookie then is "tntnet." plus the library name of the web application. Since there is no library name if the application is run through the Tntnet application class, this applications name is used instead.

Setting the app name explicitely reduces potential conflicts if multiple tntnet application servers are run on the same host on different ports.

void tnt::Tntnet::setMaxThreads ( unsigned  n)

Set the maximum number of worker threads.

void tnt::Tntnet::setMinThreads ( unsigned  n)

Set the minimum number of worker threads.

static bool tnt::Tntnet::shouldStop ( )
static

Tells whether a shutdown request was initiated.

static void tnt::Tntnet::shutdown ( )
static

Request all Tntnet instances to shut down.

void tnt::Tntnet::sslListen ( const std::string &  certificateFile,
const std::string &  keyFile,
const std::string &  ipaddr,
unsigned short int  port 
)

Set up a ssl listener for the specified ip address and port.

See listen() for more information.

void tnt::Tntnet::sslListen ( const std::string &  certificateFile,
const std::string &  keyFile,
unsigned short int  port 
)
inline

Set up a ssl listener for the specified port which listens on all local interfaces.

See listen() for more information.

Mapping& tnt::Tntnet::vMapUrl ( const std::string &  vhost,
const std::string &  url,
const Maptarget &  ci 
)

The documentation for this class was generated from the following file: