Asio, run-time polymorphism

Hello. I have some experience with http protocol and i have question/suggestion about implementing this protocol using asio library. Http/1.1 supports "protocol upgrades": during persistent connection client ot server can ask remote peer to upgrade protocol (push additional protocol(s) in protocol stack just before HTTP). After successful upgrading client can continue to send http-requests to server over new protocol stack. See "Upgrading to TLS Within HTTP/1.1" (http://www.faqs.org/rfcs/rfc2817.html) for examples. Currently asio doesn't allow me to implement this facility (to transform socket using simple transport protocol, like TCP, to SSL-socket in run-time). Another problem. HTTP/1.1 supports transfer-encoded bodies of packets, i.e. bodies transformed for transmission between sender and recipient (compressed, chunked etc.). Such transfer-encoded bodies are always chunked, splitted to chunks, each chunk have header with his size, zero sized chunk signals end of body. In some step of my program i would like to eliminate difference between plain bodies (reading/writing to socket) and transfer-encoded bodies (reading/writing to chain of filters). In other words i'm talking about some infrastructure like boost::iostreams but built on top of asio dispatcher. Async analogue of boost::iostreams which allows me to create async chains of filters in run-time. For example, it can be done with non-templated versions of functions async_read, async_write, handler parameter of this functions will have type like boost::function<void (asio::error, size_T)>. SSL class could be implemented as such async filter and would allow attaching at run-time.

Hi, --- stas garifulin <s.garifulin@drweb.com> wrote: <snip>
In other words i'm talking about some infrastructure like boost::iostreams but built on top of asio dispatcher. Async analogue of boost::iostreams which allows me to create async chains of filters in run-time. For example, it can be done with non-templated versions of functions async_read, async_write, handler parameter of this functions will have type like boost::function<void (asio::error, size_T)>. SSL class could be implemented as such async filter and would allow attaching at run-time.
Dynamic chaining of filters is something I consider beyond the scope of asio. Of course, it could be implemented as a library on top of asio. However, I am planning to add virtual wrapper stream templates that could be used to allow runtime polymorphism with streams. It might look something like: template < typename Const_Buffers, typename Mutable_Buffers, typename Handler> class polymorphic_stream_base { public: virtual size_t read_some(const Mutable_Buffers& bufs) = 0; virtual void async_read_some(const Mutable_Buffers& bufs, Handler handler) = 0; virtual size_t write_some(const Const_Buffers& bufs) = 0; virtual void async_write_some(const Const_Buffers& bufs, Handler handler) = 0; }; template < typename Stream, typename Const_Buffers, typename Mutable_Buffers, typename Handler> class polymorphic_stream : public polymorphic_stream_base<...> { ... }; This might be used to accomplish the same sort of thing as you describe. Cheers, Chris

Asio samples lacks a multithreaded server implementation: where can I find an example/tutorial about that? I need to write a multithreaded http server: I'm running multiple calls to io_service::run from a pool of threads but it looks that if my session object takes a lot of time to generate the http response the server block any accept operation until the session has finished... plz help, thanks

I need to write a multithreaded http server: I'm running multiple calls to io_service::run from a pool of threads but it looks that if my session object takes a lot of time to generate the http response the server block any accept operation until the session has finished...
Just to expand your possible options, have you looked into the C Apache Portable Runtime (APR) library? Granted it's not very boost or C++ like, but it has quite a robust multithreaded API for handling all sorts of things you'll want to do for writing a HTTP server (that you could then wrap in C++ classes). Trent.

Just to expand your possible options, have you looked into the C Apache Portable Runtime (APR) library? Granted it's not very boost or C++ like, but it has quite a robust multithreaded API for handling all sorts of things you'll want to do for writing a HTTP server (that you could then wrap in C++ classes).
Thanks for the suggestion but asio is a requirement of the project Bye
participants (4)
-
berserker_r
-
Christopher Kohlhoff
-
stas garifulin
-
Trent Nelson