开发者

Boost ASIO async_accept compilation fails

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 s开发者_C百科tarted!
        return false;

    this->listening = didStart;
    return didStart;
}

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

}


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

acceptor->async_accept(*tempNewSocket, ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜