Re: [Cppcms-users] Can I create an asynchronous socket connection from within an asynchronously mou
Brought to you by:
artyom-beilis
From: Dietrich M. <die...@gm...> - 2012-10-19 17:14:30
|
Actually the problem was that I used multiple sockets in a vector. So I eventually iterated over them and the buffer might have been copied around. The socket could not be copied as it had to be stored as a shared_ptr. Finally I solved the issue by moving the sockets to a vector of unique_ptr and the problem was gone. Thanks for you help anyway! On Thu, Oct 18, 2012 at 1:53 PM, Artyom Beilis <art...@ya...> wrote: > > > From: Dietrich Müller <die...@gm...> > >To: cpp...@li... > >Sent: Friday, October 12, 2012 6:32 PM > >Subject: [Cppcms-users] Can I create an asynchronous socket connection > from within an asynchronously mounted application? > > > > > >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)); > >} > > > > Where buf's content resides? The memory areas pointed by buff should > remain valid untill asynchronous write > operation is cimpleted. > > Also if you want any help, show the full code > > > > >//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. > > > What is shared from this? I assume you try to make application with > shared_from_this? You can't. Because > it is not created with shared_ptr, also if application exists all the time > than you don't need to care > about shared from this stuff and use ordinary this. > > >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. > > > > If you use asynchronous application than its thread and the event loop > threads are the same. > > > **Next Time** > > Show the full code. > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.com/ > CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_sfd2d_oct > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |