Boost logo

Boost Users :

Subject: Re: [Boost-users] async_send handler problem
From: Alexander Carôt (Alexander_Carot_at_[hidden])
Date: 2013-12-16 12:51:54


>>You can create an explicit thread an invoke io_service::run() there,
>> as you've shown above. No need to inherit thread,
>> boost::thread/std::thread object accepts the thread procedure as a
>> parameter.
>> In general, it's quite hard to tell what the problem is without seeing
>> your code. If you can't make a small self-contained sample that
>> reproduces the issue, try posting your real code.

Allright -- I tried to simplify things as much as possible. My app is a
music live music streamer, which sends and receives UDP audio data. I will
start with the sender first. Please note that any network related data
(io_service, endpoint, socket etc.) is all defined within a struct called
dFC, which belongs to a class called sj - hence I address them via
sj->dFC->...

I have an audio callback thread, which sends a UDP packet in a time
interval of 10.8 ms:

--------------
static int callback( const void *inputBuffer, void *outputBuffer, unsigned
long framesPerBuffer,void *data ){
  
  sj::callbackdata *my;
  my = (sj::callbackdata *) data;
 

  
  ///SENDER
  if (my->streaming) my->mySender->sendIt(buffer);

  ///FURTHER STUFF WITHOUT RELEVANCE FOR NOW ...
}

-------------

>From this function I call the class mySender, which contains the
async_send command and the handler:

------------
void sender::sendHandler(const boost::system::error_code&
error,std::size_t bytes_transferred){
  cout << "TRIGGER !" << endl;
}

        
void sender::sendIt(char *charBuffer){
        
  cout << "SENDING" << endl;

  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 so
that the console output looks like this:

SENDING
TRIGGER
SENDING

SENDING

SENDING

SENDING

SENDING

SENDING

...

I believe I am not using the io_service correctly. Can you help ?

Thanks

Alex


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