Boost logo

Boost Users :

Subject: Re: [Boost-users] async_send handler problem
From: Igor R (boost.lists_at_[hidden])
Date: 2013-12-16 13:24:01


> --------------
> static int callback( const void *inputBuffer, void *outputBuffer, unsigned
> long framesPerBuffer,void *data ){
<...>
> if (my->streaming) my->mySender->sendIt(buffer);

<...>

> void sender::sendIt(char *charBuffer){
<...>
> sj->dFC->s->async_send_to(boost::asio::buffer(charBuffer, sj->dFC->sendBytes), *sj->dFC->e,
> boost::bind(&sender::sendHandler,this,
> boost::asio::placeholders::error,
> boost::asio::placeholders::bytes_transferred));
> sj->dFC->io_service.run();
> }
> -----------------
>
> The good news are that it works - the bad news are: It works only once

It looks like you call io_service::run() "ad hoc", just to process the
handler of the previous async_send_to (note that it blocks until this
handler is dispatched), so every time you call async_send_to - you
call io_service::run() again. Thus, you have to call
io_service::reset() prior to any subsequent call to run():
http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/io_service/run/overload1.html

But please note that this is untypical usage of io_service -- you
actually simulate a blocking, synchronous operation.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net