October 29, 2007

What is Boost.Asio, and why we should use it

Writing portable networking code in ะก++ is problem with long history, and was developed many libraries, that tried to solve this problem. But i could say, that Boost.Asio is the best implementation between existing. On the base of Boost.Asio already exists some number of libraries and applications (libpion, libtorrent), and development of some new is in progress. Beside this, on the base of Boost.Asio i had projected and developed a filtering subsystem for web-filtering product SKVT "Dozor-Jet" aka WebBoss.
Boost.Asio has following main features:
  • ability to write cross-platform networking code, working on the most of existing platforms - Windows, Unix-like, Tru64, QNX, etc..
  • supports both IPv4 and IPv6
  • support for TCP & UDP
  • support for asynchronous operations
  • provide std::iostream compatible interfaces
  • support for SSL connections
  • support for delayed operations (timers)
For me, main advantage of Boost.Asio (besides cross-platform work) is, that on each platform, it use most effective strategy (epoll on Linux 2.6, kqueue on FreeBSD/MacOSX, Overlapped IO on MS Windows), and that, library allow to use different strategies - synchronous and asynchronous work with sockets, usage of streaming input/output, compatible with std::iostream. And these strategies could be mixed in one application, for example, accept connections in async mode, and than run thread, which will do input/output in sync mode (test-otpc.cpp example).
For demonstration of Boost.Asio's features i wrote (some of parts was adopted from Boost.Asio examples) several examples, implementing different data handling strategies (more examples could be found on the home page of Boost.Asio). I had used these examples for selecting appropriate data handling strategies for my own applications. All these examples implements "stupid" web-server, that read request and return back single page, independent on address, that was specified in request. Currently published following examples (all sources include file common.h):
  • test-mcmt.cpp - implements data handling strategy Many Connections/Many Threads - it run several threads, each of them accept connections and perform input/output in async mode;
  • test-otpc.cpp - implements strategy One Thread per Connection - one thread accepts connections in async mode, and than run thread, in which input/output performed in sync mode (code, performing this is in files test-otpc-conn.cpp & test-otpc-conn.hpp);
  • test-otpc-tp.cpp - almost same as test-otpc.cpp, but instead of dedicated thread for every connection, used pool of threads, implemented by threadpool library
To build examples (all sources are here) you need boost 1.35, that currently you can take from boost svn trunk, but i hope, that release of version 1.35 will be in near future, so you will not need to fetch and compile it manually.
I think, that on the base of this note it will possible to write more complete article, but this is future task, but now you can ask me about boost.asio directly :-)

October 25, 2007

Release of new boost.asio version

Several minutes ago come mail, that new version (0.38) of wonderful library boost.asio was released. In new release there is lot of new features and bugfixes, so we can wait for a release of boost 1.35 in near future and will use asio out of box.
P.S. I hope, that i find time during next week to write more detailed text about boost.asio and it's usage

October 8, 2007

Open source-related

Had finished today a small utility for implementing support of Google Safe Browsing API in Squid - squid-gsb. Documentation and build instructions you can find on my home page. As i'm "lazy", then for development i had used many things from Boost. In principle, it's possible to rewrite all without Boost, but in this case i'll need to think how to implement this in cross-platform way.

October 2, 2007

work/windows related

Last three work days i spend working on unusual (for me) things - program for MS Windows. As programming language was used a language of windows shell - cmd.exe, and task was - building a system for building external libraries for our new projects. This systems should be fully automatic and extensible. Main idea of this system was created long ago, and i only had to program it. For comparison, i need to say, that such system, but for our Unix developers, was written on unix shell in half day, including debugging scripts for concrete libraries (compiling of boost take a long time).
One day i spend installing VMWare Server, MS Windows, Visual Studio and other work utilities. Was also installed MinGW and mercurial. Main part of work had started yesterday morning.
Skeleton of main script was written quickly - in memory still exists knowledge, obtained at time, when i was admin of large windows network at university with 1500 users. But main problems was with batch build in Visual C++ - texts on MSDN doesn't helps in some cases, and only after some tries, i had found, that better not to try to build libraries with vcbuild, as described on MSDN, but with devenv, and this also require to play with the order of command-line switches and so on. Bad handling of errors, doesn't allow properly understand what error and in which switch was made.
Second problem for me was, that changing project parameters, often require run of devenv and edit parameters via dialog boxes. But run of devenv in virtual machine is too slow also on modern equipment.
At the end, after 1.5 work day (for windows, number of required libraries much more than for unix) all was ready. Was some small problems with naming of boost libraries under windows, but and this problem was resolved.
But in general, after usage of developer-friendly (at least for me) Unix development tools for a long time, usage of development and building tools under windows, leave me in strange and so comfortable feeling.