Boost logo

Boost Users :

From: Vjekoslav Brajkovic (balkan_at_[hidden])
Date: 2008-07-03 16:12:20


Hi.

         I am experiencing some issues with boost::bind and I was hoping if
anybody is willing to help me. The example is really simple:

First I have a function:

void com_client::handle_init(
         const std::string& host,
         const command_t command) {

     boost::asio::ip::tcp::resolver resolver(connection_.socket().io_service());
     boost::asio::ip::tcp::resolver::query query(host, service_);
     boost::asio::ip::tcp::resolver::iterator endpoint_iterator;
     endpoint_iterator = resolver.resolve(query);
     boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;

     connection_.socket().async_connect(endpoint,
             boost::bind(
                     &com_client::handle_connect,
                     this,
                     2,
                     boost::asio::placeholders::error,
                     ++endpoint_iterator)
     );

}

After successful handshake, this function is called:

void com_client::handle_connect(
                 command_t command,
                 const boost::system::error_code& e,
                 boost::asio::ip::tcp::resolver::iterator endpoint_iterator) {
         if (!e) {

                 rLog(com_client_control_, "Connection established with remote end-point %s.",
                                 connection_.socket().remote_endpoint().address().to_string().c_str());

                 command_ = DEPOSIT_CHUNK;
                 connection_.async_write(command_,
                                                 boost::bind(
                                                 &com_client::handle_write_cmd,
                                                 this,
                                                 boost::asio::placeholders::error)
                                 );

         } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {

                 connection_.socket().close();
                 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
                 connection_.socket().async_connect(endpoint, boost::bind(
                                 &com_client::handle_connect, this,
                                 boost::asio::placeholders::error, ++endpoint_iterator));
         } else {
                 std::cerr << e.message() << std::endl;
         }
}

This issue is when I modify the code such that

     connection_.socket().async_connect(endpoint,
             boost::bind(
                     &com_client::handle_connect,
                     this,
                     //2,
                     boost::asio::placeholders::error,
                     ++endpoint_iterator)
     );

void com_client::handle_connect(
         //command_t command,
         const boost::system::error_code& e,
         boost::asio::ip::tcp::resolver::iterator endpoint_iterator) {

one of the arguments is removed code compiles.

And also:

enum command_t {
     DEPOSIT_CHUNK = 2,
     DETRIEVE_CHUNK = 4,
     HEARTBEAT = 16
};

I was hoping if somebody could explain this. I've attached g++ output.

-V



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