[asio-users] async_connect calling handler befor connect completed?
Brought to you by:
chris_kohlhoff
From: Dimitri E. P. <dp...@e3...> - 2006-06-14 16:36:58
|
Hello All, I just started using asio and I am having some trouble with async_connect and async_handshake on windows ( XP sp2 ) using asio 0.3.6 . If I call async_handshake from the handler passed to async_connect I imediatelly get a 10057 ( WSAENOTCONN) error , if I sleep for a while and call async_handshake all is fine and Tls handshaking proceeds correctly. This is the code I am using: void StunSharedSecretRequest::Start(){ Debug::Output(LOG_INFO,"SharedSecret Connecting\n"); try { boost::asio::ipv4::tcp::endpoint endpoint(mStunServerPort,mStunServer); mTlsContext = new boost::asio::ssl::context(mCmd.GetDemuxer(), boost::asio::ssl::context::tlsv1_client); mTlsSocket = new boost::asio::ssl::stream<boost::asio::stream_socket>(mCmd.GetDemuxer(), *mTlsContext); mTlsSocket->lowest_layer().async_connect(endpoint,boost::bind(&StunSharedSecretRequest::ConnectCompleted,this,boost::asio::placeholders::error)); } catch(...) { mCmd.Post(boost::bind(OnFailed,this)); } } void StunSharedSecretRequest::ConnectCompleted(const boost::asio::error& error){ static CommandWrapper* tmr = 0; Debug::Output(LOG_INFO,"Tls Handshake\n"); if(!error){ // if this is calld as is , the HandshakeCompleted handler will be called with a 10057 error. // if I step though the code and wait a few seconds before running the next statement, everything is fine mTlsSocket->async_handshake(boost::asio::ssl::stream_base::client,boost::bind(&StunSharedSecretRequest::HandshakeCompleted, this,boost::asio::placeholders::error)); } } It seems that the async_connect handler is being called before the connection is actually established. When using async_connect do I have to set the socket as blocking or is it done automatically? I tried using: boost::asio::socket_base::non_blocking_io command(false); mTlsSocket->lowest_layer().io_control(command); but it didn't work ( got an error ) any clues on what i'm doing wrong?? Dimitri |