Boost logo

Boost Users :

Subject: [Boost-users] [asio] Adding methods directly to the IO_Service for it to call.
From: Ryan (boost_at_[hidden])
Date: 2013-02-24 13:44:51


Boost Community,

I've created a basic class that wrapped the boost asio framework
receive/send functionality. My wrapper class gave the packet buffer to
whatever processing function that it was created with and when the function
was done sent any buffers it was given. This let me create classes that
processed data without any knowledge of the transport layer.

This concept has worked well since the asio sockets have an async_receive
and async_send. I was able to setup all of my classes and then call
io_service.run() to get everything going. I now have to receive data from
a customer dll and they only support polling. Is there a way to add to the
io_service a specific method to call once the io_service is running. I've
included the ReceiveProcessSend.hpp with a comment above the two
async_receive calls I need to replace. Also, below is a very basic example
of how I setup classes that I pass into the ReceiveProcessSend.

Any help on how to add calling methods to the io_service would be
really appreciated.

Ryan

class DoSomeProcessing
{
private:
  typedef std::vector<unsigned char> t_ucvector;
  typedef boost::shared_ptr<t_ucvector> t_boostVector;
  typedef std::list<t_boostVector> t_boostList;

public:
  t_boostList const processMessage(t_boostVector message,
t_ucvector::size_type messageSize)
  {
    t_boostList outputList;
    //Do processing here and create output buffer.
    return outputList;
  }

};

int main(int argc, char * argv[])
{
  DoSomeProcessing myProcess;

  ReceiveProcessSend::Arguments myArguments;

  boost::asio::io_service io_service;

  ReceiveProcessSend rps(
    io_service,
    boost::bind(&DoSomeProcessing::processMessage, &myProcess, _1, _2),
    myArguments);

  io_service.run();

  return 0;
}





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