|
Boost Users : |
Subject: Re: [Boost-users] tcp::acceptor works differently on windows than linux.
From: Igor R (boost.lists_at_[hidden])
Date: 2009-03-06 07:38:52
> I'm writting a multiplatform app which uses a tcp::acceptor.
> Thread one does:
> Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â std::cout<<"Oh but I interupted: "<<std::endl;
> Â Â Â Â Â Â Â Â Â Â _myTCPAcceptor->close();
> Â Â Â Â Â Â Â Â Â Â std::cout<<"Done interupting "<<std::endl;
> Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â Â std::cout<<"About to join "<<std::endl;
> Â Â Â Â Â Â Â Â _myAcceptorThread->join();
> Â Â Â Â Â Â Â Â std::cout<<"Join complete"<<std::endl;
> Thread two does:
>
> {
> Â Â Â Â Â Â boost::system::error_code ec;
> Â Â Â Â Â Â boost::asio::socket_base::non_blocking_io command(false);
> Â Â Â Â Â Â _mySocket.io_control(command,ec);
>
> Â Â Â Â Â Â boost::system::error_code ec1;
> Â Â Â Â Â Â std::cout<<"About to accept "<<std::endl;
> Â Â Â Â Â Â _myTCPAcceptor->accept(_mySocket,ec1);
> Â Â Â Â Â Â std::cout<<boost::system::system_error(ec1).what()<<std::endl;
> Â Â Â Â Â Â std::cout<<"done with the accept"<<std::endl;
> }
According to the reference:
http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/reference/ip__tcp/acceptor.html
acceptor object is not threadsafe. This means you should not access it
this way, and if you do, the behaviour is undefined.
To cancel acceptor you could use async_accept() and then post close()
to the same thread, using io_service.post().
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