10
Aug
Modular C++ Web Server / Framework
By Joseph Montanez
0 Comment

UPDATES:
Benchmark & Code Revision
Download the Source Code

I am working on a modular cpp web server to allow compile c++ shared / dynamic libraries. This way if anyone is ever wanting to challenge themselves, they can do so by writing a module for the deamon using the framework. Bare-Bone sample library

#include <stdio.h>
#include "HttpModule.h"

class hello : public HttpModule {
    public:
        static char *get() {
        	char *temp = "Hello World from a c++ sample";
        	return temp;
        }
};

// the class factories
extern "C" HttpModule* create() {
    return new hello;
}

extern "C" void destroy(HttpModule* p) {
    delete p;
}
Compile the dynamic lib
# compile into a shared library
g++ -fPIC -c hello.cpp
g++ -shared -o libhello.so hello.o
# Using g++ on intel mac
# g++ -dynamiclib -o libhello.so hello.o
How does one then use this library on the server, well... I'll eventually make a configuration file, but for now you ave to directly edit the webserver.
module_map http_modules [] = {
	{"/helloworld", "./libhello.so"}
};
That correlates to http://localhost/helloworld and outputs "Hello World from a c++ sample"

« Back to my notebook
Next Note > < Previous Note
Comment Pages: 1


esign