libfast - FastCGI Application Server w/ Templates¶
libfast is a small library built around libfcgi and ClearSilver. It wraps these libraries properly and integrates session management and a MVC-like architecture. It targets embedded systems or servers where processing power and footprint is limited and should work with any FastCGI capable webserver.
Architecture¶
A web application based on libfast has a global and a session context:- Global context
- inter-session data
- database connections (source:src/libstrongswan/database/database.h)
- ...
- Session context (source:src/libfast/context.h)
- per-session data
- controllers (source:src/libfast/controller.h)
- filters (source:src/libfast/filter.h)
libfast automatically creates and manages a session for each connecting user and allocates a private session context. In that context, a defined set of controllers and filters are allocated. These instances are per session, so you might save session-specific data in them.
The session context is synchronized, only one thread enters a session. The global context is accessed by all sessions, so you'll need to write global objects thread-save.
Building a web application¶
Here a small example how to set up a web application:
dispatcher_t *dispatcher; your_global_context_implementation_t *global; global = initialize_your_global_context(); dispatcher = dispatcher_create(NULL, FALSE, 180, (context_constructor_t)your_session_context_create, global); dispatcher->add_controller(dispatcher, your_controller1_create, param1); dispatcher->add_controller(dispatcher, your_controller2_create, param2); dispatcher->run(dispatcher, 20); dispatcher->waitsignal(dispatcher); dispatcher->destroy(dispatcher); global->destroy();
Have a look at the manager (source:src/manager) for a more complete example.