The most simplistic example.This example simply responds with a text containing the current timestamp.
#include <ehs.h>
#include <iostream>
#include <cstdlib>
#include "common.h"
using namespace std;
int main(int argc, char ** argv)
{
cout << getEHSconfig() << endl;
if (argc != 2 && argc != 3) {
cout << "Usage: " << basename(argv[0]) << " <port> [threaded]" << endl;
return 0;
}
EHSServerParameters oSP;
oSP["port"] = argv[1];
if (2 < argc) {
cout << "Starting in threaded mode" << endl;
oSP["mode"] = "threadpool";
if (!strcmp(argv[2], "pool")) {
oSP["mode"] = "threadpool";
oSP["threadcount"] = 200;
}
if (!strcmp(argv[2], "single")) {
oSP["mode"] = "singlethreaded";
}
if (!strcmp(argv[2], "perrequest")) {
oSP["mode"] = "onethreadperrequest";
}
} else {
cout << "Starting in single threaded mode" << endl;
oSP["mode"] = "singlethreaded";
}
if (5 == argc) {
oSP["https"] = 1;
oSP["certificate"] = argv[3];
oSP["passphrase"] = argv[4];
}
try {
kbdio kbd;
cout << "Press q to terminate ..." << endl;
if (2 < argc) {
usleep(300000);
} else {
}
}
} catch (exception &e) {
cerr << "ERROR: " << e.what() << endl;
}
return 0;
}
EHS provides HTTP server functionality to a child class.
void StopServer()
Shuts down this instance.
void StartServer(EHSServerParameters ¶ms)
Starts up this instance.
bool ShouldTerminate() const
Retrieve the server's exception status.
void HandleData(int timeout=0)
Dispatches incoming data.