Example of building async active object

Here's more complex example of building communicating objects on the top of Boost.Asio (Boost C++ Libraries). https://sourceforge.net/projects/asio-samples/ (the most complete projects are "nmea_client" and "echo_server"). The main concept of the described method is creation of active objects tied to boost::asio::io_service (where theirs activity is done by means of working threads tied to io_service::run method) with asio-like communication interface:

template <typename Handler>
void async_do_something(operation_parameters, Handler handler) {...}

or even (see ma::nmea::cyclic_read_session::async_read_some):

template <typename Handler, typename Data>
void async_do_something(Data data, Handler handler) {...}

The central point of the suggested method is ma::handler_storage class which is used for handler's "parking" until the active method's execution flow completes. Also ma::handler_storage helps to decouple header files from cpp-files which in theory must help with compilation time reduction.

Updated: there is "async_basics2" project in "asio-samples". It discovers creation of Boost.Asio-based active object without templates (in public area of active object) - only using plain old interfaces but with support of Asio-like completion handler guaranties and custom memory allocation. I am more than confident that this "traditional" approach is looked for by many of Asio-users.

Utilizing ConnectEx? with asio::windows::overlapped_ptr

As Windows users of Asio know: Asio uses select + additional internal thread to implement socket::async_connect member function.
Here's an example of simple wrapping (Windows) IOCP-based Winsock function ConnectEx? : https://sourceforge.net/projects/asio-samples/ (see project named "async_connect" at downloadable beta or SVN). This example provides free function async_connect that falls back into the socket::async_connect member function if ConnectEx? can not be located at run-time (version of Windows < Windows XP) or if Windows is not the target paltform (compile time fallback).

Topic revision: r21 - 25 Sep 2012 - 19:13:41 - MaratAbrarov?
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback