CppCMS — C++ Web Framework

来源:互联网 发布:python黑帽子原码 编辑:程序博客网 时间:2024/06/05 02:47
Event Loop:
程序中设置两个线程,一个负责程序本身运行(主线程),另一个负责主线程与其它进程的通信(主要是各种I/O操作)

cppcms::service::post()
将一个执行句柄放在事件循环队列,该函数是线程安全的

cppcms::http::response
this class represents all HTTP/CGI response related API, generation of output content and HTTP headers

cppcms::http::context Class Reference
context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information

CGI(Common Gateway Interface)
通用网关接口,可以让一个客户端,从网页浏览器向执行在网络服务器上的程序请求数据。CGI描述了服务器和请求处理程序之间传输数据的一种标准。

http::response& cppcms::http::context::response()
Get an interface to HTTP response


void cppcms::http::response::set_content_header(std::string const & content_type)
This function set HTTP Content-Type header, but unlike contet_type function it also adds current locale charset encoding (unless localization.disable_charset_in_content_type set to true in configuration)

void cppcms::http::response::content_length(unsigned long long len) 

Set HTTP Header Content-Length


std::ostream& cppcms::http::response::out()

Request an output stream to write the body of HTTP response after writing headers.

Note:
it triggers saving changes in the session, so further changes will have no effect.
it triggers writing all headers to output stream, such that changing any header or adding cookies will have no effect.
it is impossible to change an io_mode after calling this function.

std::basic_ostream<char, std::char_traits<char>> &std::basic_ostream<char, std::char_traits<char>>::write(const char* _Str, streamsize _Count)
etc: cout.write(...);

void cppcms::http::context::async_flush_output ( handler const & h ) 
Send all pending data to user, when operation is complete call handler h with status.
Note: if the status is operation_aborted, you can't use this connection any more, the peer gone.

void cppcms::http::context::async_complete_response()

Send all pending output data to the client and finalize the connection. Note, you can't use this object for communication any more.


json
  This namespace includes all JSON parsing and formatting related classes and functions. 
 
cppcms::json::value Class Reference
This class is central representation of json objects.

bool cppcms::json::value::load(std::istream& in,bool full,int *line_number = 0)
Read a value from std::istream.
returns true if the value was read successfully, otherwise returns false to indicate a syntax error.

template<typename T >
T cppcms::json::value::get(std::string const& path) const
inline Get an object of type T from the path path. Throws bad_value_cast if such path does not exists of conversion can't be done

cppcms::applications_pool& cppcms::service::applications_pool()

Get a cppcms::applications_pool instance of this service

cppcms::applications_pool Class Reference

Application pool is the central class that holds user created applications.

void cppcms::applications_pool::mount(booster::intrusive_ptr<application> app)

Mount an asynchronous application app for processing of any incoming requests. Application would receive PATH_INFO CGI variable for URL matching.
This member function is thread safe.

void cppcms::service::run()

Start the central even loop of CppCMS service. By default, it also install signal handlers on POSIX platforms to handle SIGINT, SIGTERM and SIGUSR1 signals or uses SetConsoleCtrlHandler on Windows platforms waiting on C, BREAK, CLOSE and SHUTDOWN events.
This even call service::shutdown function that stops the main event loop and shutdowns the service properly.
If you want to disable these handlers, you may set service.disable_global_exit_handling option to true.

void cppcms::application::attach(application* app,std::string const& regex,int part)
Register an application app as child and mount it into url_dispatcher calling dispatcher().mount(regex,*app,part);
Ownership of app is transfered to parent.

url_dispatcher& cppcms::application::dispatcher()

Get a dispatched class – class that responsible on mapping between URLs and a member functions of application class.
This member function is application specific and not Connection specific.

template<typename C>
void cppcms::url_dispatcher::assign(std::string const & regex,void(C::*)() member,C* object)
This template function is a shortcut to assign(regex,callback). It allows assignment of member function of an object with signature void handler() as simple as assign(expr,&bar::foo,this);
In addition to calling member function it calls object->init() before call and object->clean() after the call of the C is derived from cppcms::application




requests,responses,sessions, cache

原创粉丝点击