[Cppcms-users] Can I create an asynchronous socket connection from within an asynchronously mounted
Brought to you by:
artyom-beilis
From: Dietrich M. <die...@gm...> - 2012-10-12 16:32:40
|
Hello, I try to create a socket connection from within my application and I seem to fail. I tried to setup the code like in this boost asio sample for an asynchronous http client ( http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/example/http/client/async_client.cpp) without the resolving part. Btw this resolver is pretty useful. Can it be integrated into booster aio? *//the call socket->async_connect(endpoint, std::bind(&ClassX::onConnected, this, std::placeholders::_1)); //the first callback void ClassX::onConnected(const booster::system::error_code &e) { if(!e) //print some member of ClassX //... //and write something to the socket socket->async_write(buff, std::bind(&ClassX::onWritten, this, std::placeholders::_1)); } //onWritten callback //onRead callback *Now the problem is that as soon as I access a class member in any callback, the result is a segmentation fault. If I pass *shared_from_this()* and not *this *I get a assertion error in * enable_shared_from_this.h:56* that *p.get() == this* is not true. I think the problems are related to some synchronisation issues between the main and the application thread, as the synchronous calls work. Please give me some advice how I correctly use the socket in my application. greetings |