0

I have one problem with my server (based on ASIO & Boost::Thread)

In line :

this->connection->thread = boost::shared_ptr<boost::thread>(new boost::thread(worker, this->connection));

I got error :

Core/CCore.cpp: In member function 'void CCore::handle_accept(const boost::system::error_code&)':

Core/CCore.cpp:71:163: error: no matching function for call to 'bind(, CCore* const, boost::arg<1> (&)())'

Full error code : http://pastebin.com/PaftWzbx

CCore definition & acceptor:

class CCore
{
public:
       CCore(boost::asio::io_service *io_service, const boost::asio::ip::tcp::endpoint &endpoint);
       bool failed;
private:
        void handle_accept( const boost::system::error_code& error );
        boost::asio::io_service *io_service;
        boost::asio::ip::tcp::endpoint endpoint;
        boost::asio::ip::tcp::acceptor *acceptor;
        boost::shared_ptr<CConnection> connection;
};

void CCore::handle_accept(const boost::system::error_code& error) 
{
    if (error) {
        // accept failed
        //LOG(ERROR, "Acceptor failed: " << error.message());
        return;
    }

    //LOG(INFO, "Accepted connection from " << this->connection->endpoint.address().to_string() << ":" << this->connection->endpoint.port());

    this->connection->thread = boost::shared_ptr<boost::thread>(new boost::thread(worker, this->connection));

    this->connection = boost::shared_ptr<CConnection>(new CConnection());
    this->connection->master_io_service = this->io_service;
    this->acceptor->async_accept(*(this->connection->socket), this->connection->endpoint, boost::bind(CCore::handle_accept, this, boost::asio::placeholders::error));
}
class CConnection {
  public:
    CConnection(void);
    boost::asio::io_service io_service;
    boost::shared_ptr<boost::asio::ip::tcp::socket> socket;
    boost::asio::ip::tcp::endpoint endpoint;
    boost::shared_ptr<boost::thread> thread;
    boost::asio::io_service *master_io_service;
    bool close;
};
void worker(boost::shared_ptr<CConnection> connection) 
{
    boost::asio::ip::tcp::socket &socket = *(connection->socket);
    boost::asio::socket_base::non_blocking_io make_non_blocking(true);
    socket.io_control(make_non_blocking);

    char acBuffer[1024];
    std::string line("");

    while ( connection->close == false ) {

    } // while connection not to be closed
}

Does anyone know solution how to fix that error ? Thanks.

Kacper Fałat
  • 633
  • 3
  • 9
  • 17
  • post a [sscce](http://sscce.org). I'd like to see the definition of `class CCore` and the implementation of `CCore::handle_accept()` at the very least. – Sam Miller May 31 '13 at 20:20
  • Posted CCore definitions & accpetor. – Kacper Fałat May 31 '13 at 20:28
  • now your question makes less sense, you removed the `class CConnection` definition. Please make a [sscce](http://sscce.org) so we can understand your problem. I [tried to make one](http://coliru.stacked-crooked.com/view?id=635bc33dd68507435a205a6b6338f85a-c056299b5afab84f40636e0111d56983) using your code snippets, it compiles just fine. – Sam Miller May 31 '13 at 20:32
  • Ymmm, sorry, I added it again. – Kacper Fałat May 31 '13 at 20:34

1 Answers1

1

Since handle_accept is a member function of CCore, you need to change boost::bind first parameter from this:

boost::bind(CCore::handle_accept, ...

to this:

boost::bind(&CCore::handle_accept, ...

Hope this helps

Neurogeek
  • 146
  • 2