Gorilla3D Primative Teachings

Joseph Says: STOP SPAMMING MY %$#@ING SITE $%#@!!!!!
Search

Modular C++ Web Server / Framework


Sunday, August 10, 2008

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

  1.  
  2. #include <stdio.h>
  3. #include "HttpModule.h"
  4.  
  5. class hello : public HttpModule {
  6. public:
  7. static char *get() {
  8. char *temp = "Hello World from a c++ sample";
  9. return temp;
  10. }
  11. };
  12.  
  13. // the class factories
  14. extern "C" HttpModule* create() {
  15. return new hello;
  16. }
  17.  
  18. extern "C" void destroy(HttpModule* p) {
  19. delete p;
  20. }
  21.  

Compile the dynamic lib
  1.  
  2. # compile into a shared library
  3. g++ -fPIC -c hello.cpp
  4. g++ -shared -o libhello.so hello.o
  5. # Using g++ on intel mac
  6. # g++ -dynamiclib -o libhello.so hello.o
  7.  


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.
  1.  
  2. module_map http_modules [] = {
  3. {"/helloworld", "./libhello.so"}
  4. };
  5.  


That correlates to http://localhost/helloworld and outputs "Hello World from a c++ sample"

Comments


J posted 44 days ago

Interesting. Where is the code? :-)


Add Comment