boost::Asio async_accept not throwing exception
Hi,
I have modified the sample program provided in the asio samples, just to
accept a connection like this
void TCPServer::StartAccept()
{
try
{
TCPConnection::Pointer
NewConnection=TCPConnection::Create(Acceptor.io_service());
Acceptor.async_accept(NewConnection->socket(),boost::bind(&TCPServer::HandleAccept,this,
NewConnection,boost::asio::placeholders::error));
}
catch(std::exception& e)
{
cout<<"exception"<
Acceptor.async_accept(NewConnection->socket(),boost::bind(&TCPServer::HandleAccept,this, NewConnection,boost::asio::placeholders::error)); } catch(std::exception& e) { cout<<"exception"<
Another program is already listening on the port "13" (A service version of the same program). When this new program tries to listen (async_accept) on port "13", no exception is thrown!.
How can I check weather the port is already open?
async_XXX functions do not throw, they guarantee that the completion handler will always be invoked. So what you should check is the error_code in your completion handler.
Yes, error checking is also performed in the accept handler
(HandleAccept function). The code never reaches the async_accept
handler. Normally, when trying to listen on a port the asyn_accept
handler must be called with the error set if some error occurs. But
this is not happening! I am running the same version of the program as
a service in the first phase, then trying to debug a command line
version of the same program from Visual Studio.
What could be the reason?
Thanks,
Lloyd
On 11/22/10, Igor R
Acceptor.async_accept(NewConnection->socket(),boost::bind(&TCPServer::HandleAccept,this, NewConnection,boost::asio::placeholders::error)); } catch(std::exception& e) { cout<<"exception"<
Another program is already listening on the port "13" (A service version of the same program). When this new program tries to listen (async_accept) on port "13", no exception is thrown!.
How can I check weather the port is already open?
async_XXX functions do not throw, they guarantee that the completion handler will always be invoked. So what you should check is the error_code in your completion handler. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks, I shall post it in ASIO list.
On 11/22/10, Igor R
Yes, error checking is also performed in the accept handler (HandleAccept function). The code never reaches the async_accept handler.
Well, then maybe it's a bug. I believe it's worth cross-posting this question to asio-users. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 11/21/2010 12:12 PM, Lloyd Kanakkassery wrote:
Another program is already listening on the port "13" (A service version of the same program). When this new program tries to listen (async_accept) on port "13", no exception is thrown!.
How can I check weather the port is already open?
Thanks, Lloyd
Do not call async_accept directly, rather do something like try { acceptor_.open( (endpoint.protocol)() ); acceptor_.set_option( boost::asio::ip::tcp::acceptor::reuse_address( true ) ); acceptor_.bind( endpoint ); acceptor_.listen(); } ... acceptor_.async_accept( ... ); If the port is already open, it will throw. HtH, Cheers, Rutger
participants (3)
-
Igor R
-
Lloyd Kanakkassery
-
Rutger ter Borg