views:

143

answers:

1

Man... thought using ASIO in Boost was going to be easy and intuitive. :P

I am starting to get it finally but I am having some trouble. Here's a snippet. I am having several compiler errors on the async_accept line. What am I doing wrong? :P

I've based my code off of this page: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html

Errors:

Error 1 error C2780: 'void boost::asio::basic_socket_acceptor::async_accept(boost::asio::basic_socket &,boost::asio::ip::basic_endpoint &,AcceptHandler)' : expects 3 arguments - 2 provided e:\schoolcode\senior project\cplusplusport\cplusplusport\alexsocket.cpp 36

Error 2 error C2784: 'void boost::asio::basic_socket_acceptor::async_accept(boost::asio::basic_socket &,AcceptHandler)' : could not deduce template argument for 'boost::asio::basic_socket &' from 'boost::asio::ip::tcp::socket *' e:\schoolcode\senior project\cplusplusport\cplusplusport\alexsocket.cpp 36

bool TestSocket::StartListening(int port)
{
    bool didStart = false;

    if (!this->listening)
    {
        //try to listen
        acceptor = new tcp::acceptor(this->myService, tcp::endpoint(tcp::v4(), port));
        didStart = true; //probably change?
        tcp::socket* tempNewSocket = new tcp::socket(this->myService);
        acceptor->async_accept(tempNewSocket, boost::bind(&TestSocket::NewConnection, this, tempNewSocket, boost::asio::placeholders::error) );
    }
    else //already started!
        return false;

    this->listening = didStart;
    return didStart;
}

void TestSocket::NewConnection(tcp::socket* s, const boost::system::error_code& error)
{

}
+2  A: 

async_accept expects a reference to the socket, not a pointer, so try

acceptor->async_accept(*tempNewSocket, ...
Éric Malenfant
omg I am so dumb! Thank you!!! :D
bobber205