Re: [Cppcms-users] Design decision
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-10-04 19:00:15
|
Just few words, booster::aio::io_service::post is used to execute something in the event loop "later" i.e. you give a callback and it would executed in the dispatch queue of the event loop, it is also important that it is thread safe. Post used for two reasons: 1. Make sure that the handler is not called right now but rather put into queue - it is very useful to prevent accidential recursions 2. When you need to execute something on non-thread safe class withing the event loop thread, as post is thread safe. i.e. if some event driven object like asyncrchonous app., aio socket etc. runs withing the event loop and you want to for example send something to socket form another thread, you can't do it directly as socket objects, application objects are not thread safe, so you POST the callback and you know that it would be called in the event loop rather than the thread In your case the callback of the "on_readable()" is already called from the event loop, so you don't really need to post() anything as you are already in the event loop, As SSE::handle should be called from the event loop and you are in the event loop the callback of "on_readable()" than instead: this->get_io_service().post(std::bind(&SSE::handle,this,....) You just call handle(something,ip) ... If you still want to post() (you can but not have to), once again, lambda: this->get_io_service().post([=,this]() { handler(something,ip) }); How to do it with bind? As I said before read : http://www.boost.org/doc/libs/1_51_0/libs/bind/bind.html Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ ----- Original Message ----- > From: Christian Gmeiner <chr...@gm...> > > I have looked quite deeply into post(..) usages, but I don't get it :/ > I have seen binder's - > what is the concept behind them? > > thanks > --- > Christian Gmeiner MSc > |