classPiiHttpServer
#include <PiiHttpServer.h>
A HTTP server.
Description
This class holds an application-wide registry of HTTP servers. The servers can be created and accessed with user-defined names.
Constructors and destructor
|
( )
|
Public member functions
|
( )
Returns the network server that manages incoming connections. |
|
|
( )
Returns the protocol instance that parses requests to this server and communicates with the clients. |
|
|
bool
|
( )
A shorthand for networkServer()->start(). |
|
void
|
(
A shorthand for networkServer()->stop(). |
Static public member functions
|
static PiiHttpServer *
|
Adds a new server to the list of HTTP servers using the given
|
|
static PiiHttpServer *
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Same as addServer("", address). |
|
static PiiHttpServer *
|
Creates a new instance of PiiHttpServer at the given address. |
|
static void
|
Removes the server called |
|
static PiiHttpServer *
|
Returns the server called |
Function details
-
~PiiHttpServer
() -
PiiNetworkServer * networkServer
()Returns the network server that manages incoming connections.
-
PiiHttpProtocol * protocol
()Returns the protocol instance that parses requests to this server and communicates with the clients.
-
bool start
()A shorthand for networkServer()->start().
-
void stop
(- PiiNetwork::StopMode mode = PiiNetwork::WaitClients
A shorthand for networkServer()->stop().
-
Adds a new server to the list of HTTP servers using the given
serverNameand the binding addressaddress.I there already exists a server with the same name, the old one will be destroyed. If there are no servers, the first one will be set as the default server.
// Create a HTTPS server (0.0.0.0 binds to all network interfaces) PiiHttpFileSystemHandler handler("/var/www/securehtml"); PiiHttpServer* server = PiiHttpServer::addServer("secure", "ssl://0.0.0.0:443/"); server->protocol()->addHandler("/", &handler); // Create another server that uses the same handler, but // communicates through a local socket. server = PiiHttpServer::addServer("local", "local:///tmp/http.sock"); server->protocol()->addHandler("/", &handler);
This function is thread-safe.
Parameters
- serverName
-
the name of the server. The server instance can be later retrieved with server(). If
serverNameis empty, the new server will become the default server. - address
-
the low level protocol and the address to bind the server to. The address may be either an IPv4 address (tcp://123.123.123.123:80 or ssl://0.0.0.0:443), an IPv6 address (tcp://[2001:db8::1428:57ab]:80 or ssl://[::1]:443), or the name of a local socket (local:///tmp/server.sock on Linux, local://\\.\pipe\socket on Windows). Network addresses must contain a port number and no trailing slash. The server currently supports
tcp,ssl, andlocalconnections.
Returns
a pointer to a new PiiHttpServer instance, or zero if the address is not valid. The pointer is still owned by PiiHttpServer; one should not delete it.
-
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Same as addServer("", address).
-
Creates a new instance of PiiHttpServer at the given address.
See addServer() for valid addresses. This function does not add the new server to the server list, and the caller is responsible for deleting the server.
This function is thread-safe.
-
Removes the server called
serverNamefrom the list of HTTP servers.This function is thread-safe.
-
Returns the server called
serverName.The server must have been previously added with addServer(). If
serverNameis empty, the default server will be returned.This function is thread-safe.
Add a note
Not a single note added yet. Be the first, add yours.