Boost logo

Boost Users :

Subject: [Boost-users] weird boost::asio problems opening acceptor
From: andrew.marlow_at_[hidden]
Date: 2010-10-05 05:55:45


I have a server where there must be only one instance of it for a given
machine on a given port number. Here is the code I used to try to make
that happen:

boost::asio::io_service ios;
boost::asio::ip::tcp::endpoint primaryEndpoint(boost::asio::ip::tcp::v4(),
primaryPort);
std::auto_ptr<boost::asio::ip::tcp::acceptor> primaryAcceptor;

try
{
    primaryAcceptor.reset(new boost::asio::ip::tcp::acceptor(ios,
primaryEndpoint));
    primaryAcceptor->open(primaryEndpoint.protocol());
 
primaryAcceptor->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
    primaryAcceptor->bind(primaryEndpoint);
}
catch(std::exception& ex)
{
    std::cout << "Error: Cannot obtain port " << primaryPort
                          << ", " << ex.what() << ", server must be
already running." << std::endl;
}

It always prints the error. The error is 'Already open'. The exception
gets thrown from the call to open. What am I doing wrong please? If don't
do the open etc then I can run up a second instance and it will have the
port also. It is as if SO_REUSEADDR is true. I always thought that
SO_REUSEADDR was false by default. When I run it in the debugger and
breakpoint before the call to open , the process has the port open for
listening, as revealed by 'netstat -a'. It is as if it has already done
the open with SO_REUSEADDR set to true.

I am using boost version 1.42.0 on Windoze-XP compiled with Visual Studio
2005 (don't laugh....).

Regards,

Andrew Marlow

___________________________________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is prohibited.

Please refer to http://www.bnpparibas.co.uk/en/information/legal_information.asp?Code=ECAS-845C5H for additional disclosures.



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