|
Boost Users : |
Subject: Re: [Boost-users] async accept asio thread error
From: Gianni Ambrosio (gianni.ambrosio_at_[hidden])
Date: 2011-04-06 03:49:41
Il 4/5/2011 8:32 PM, Igor R ha scritto:
>> 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));
> Do you mean that the above code runs not in io_service::run() thread?
> When does this thread exit, just after it executes the above code?
>
No, I'm sorry I forgot one line at the end:
thread = boost::thread(boost::bind(&boost::asio::io_service::run,
&io_service));
thread is a boost::thread member variable of the TcpSocket class I'm
trying to implement.
io_service and acceptor are also member variables of TcpSocket class.
> You can close() your acceptor, but its destructor closes it anyway.
Yes, you are right in fact in the TcpSocket destructor I already call:
if (acceptor.is_open()) acceptor.close();
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