Main  /  Edit version 2  /  Edit version 3  /   /  Users Area

Difference "Event Loop" ver. 2 versus ver. 3

Content:

## Event Loop and Thread Pool interaction
CppCMS service has a simple design of a single event
The CppCMS service has a simple design of a single event
loop and a thread pool that handles actual user
application responses.
Every new incoming FastCGI, SCGI or HTTP request
is accepted by the CppCMS service and handled
by the fast and efficient CppCMS event loop that is
based on `epoll`, `kqueue`, `/dev/poll` or `select`
system calls.
On incoming request, special HTTP Context is created.
it prepares incoming request, reads all POST data and
parses it if required withing the central event loop.
On an incoming request, a special HTTP Context is created.
It prepares the incoming request, reads all POST data and
if required parses it within the central event loop.
Once the request is ready, it is checked against
Once the request is ready, it is checked against the
CppCMS applications pool to detect which
application object handles it.
If the application that handles it is synchronous
If the application that handles it is a synchronous
application, its execution is passed to the
_thread pool_. The user application prepares the response
and sends it synchronously to the client and the context
is destroyed completing the "requst/response" cycle.
is destroyed, completing the "requst/response" cycle.
If the application is asynchronous, the HTTP Context
remains inside the event loop's thread and it is handled by
the asynchronous application. This application
may decide to complete the response immediately
or postpone it implementing, for example, long polling.
or postpone it by implementing, for example, long polling.
## Integration with CppCMS Event Loop
There are several ways to interact with the event loop,
besides the obvious - implementing your own asynchronous
application:
1. Use `cppcms::service::get_io_service()` function
to access directly the event loop.
1. Use the `cppcms::service::get_io_service()` function
to access the event loop directly.
You can use any of [`booster::aio`](/cppcms_ref_v0_99/namespacebooster_1_1aio.html) classes there
You can use any of the [`booster::aio`](/cppcms_ref_v0_99/namespacebooster_1_1aio.html) classes there
and handle various asynchronous events.
2. You can post various operations for execution
in the event loop using `cppcms::service::post()`
from other threads.
This is especially important when you want to
do integration between synchronous and asynchronous
applications,
applications.
You should remember that most of CppCMS objects
You should remember that most of the CppCMS objects
including `http::context` are not thread safe
for access from multiple threads, so
if some operation should be executed on
objects running in the event loop, it must
be done by posting handlers for execution
in the event loop.
It is important to remember that
every operation executed in the event
loop should be _very fast_ and _never block_.

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0