Speeding up ASIO async_accept compilation

Man ... the thought of using ASIO in Boost was simple and intuitive .: P

I am starting to receive, finally, but I have problems. Here is a snippet. I have several compiler errors in the async_accept line. What am I doing wrong ?: P

I based my code on 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 raise :: ASIO :: basic_socket_acceptor :: async_accept (raise :: ASIO :: basic_socket & amp ;, raise :: ASIO :: IP :: basic_endpoint &, AcceptHandler)': expects 3 arguments - 2 subject to e: \ schoolcode \ senior project \ cplusplusport \ cplusplusport \ alexsocket.cpp 36

Error 2 of error C2784: 'void raise :: ASIO :: basic_socket_acceptor :: async_accept (raise :: ASIO :: basic_socket &, AcceptHandler)': the template argument for "Raise :: ASIO :: basic_socket & amp;" failed 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)
{

}
+3
source share
1 answer

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

acceptor->async_accept(*tempNewSocket, ...
+3
source

Source: https://habr.com/ru/post/1749145/


All Articles