Boost logo

Boost Users :

Subject: Re: [Boost-users] async accept asio thread error
From: Gianni Ambrosio (gianni.ambrosio_at_[hidden])
Date: 2011-04-05 10:55:45


Il 4/5/2011 3:36 PM, Igor R ha scritto:
>> "The I/O operation has been aborted because of either a thread exit or an
>> application request"
> Perhaps the thread that invoked async. operation exited before the
> operation was completed?

I'm not an expert so I try to explain my scenario.
The server runs an async accept on a thread with basically the following
code:

    boost::asio::ip::tcp::endpoint endpoint =
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), iPort);
    acceptor.open(endpoint.protocol());
    
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
    acceptor.bind(endpoint);
    acceptor.listen();
    TcpSessionPtr connection(new TcpSession(io_service));
    acceptor.async_accept(connection->getSocket(),
boost::bind(&BoostTcpSocket::handleAccept, this, connection,
boost::asio::placeholders::error));

in the handleAccept() callback a new async accept is called to allow the
server to be able to accept other clients. Here is the code:

    TcpSessionPtr connection(new TcpSession(io_service));
    acceptor.async_accept(connection->getSocket(),
boost::bind(&BoostTcpSocket::handleAccept, this, connection,
boost::asio::placeholders::error));

So, it sounds reasonable that if the application ends an async accept
operation may be pending. Now, how could I cancel a pending operation?
Is there another way to solve the problem?

Regards
Gianni


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