[asio-users] basic_stream_socket::async_connect -- non-blockingconnect vs async connect
Brought to you by:
chris_kohlhoff
|
From: Chauhan, V. <Vik...@an...> - 2007-09-14 10:12:38
|
Hello all, I think I have found the reason for this. Actually, I had the following sequence of calls earlier : 1. tcp::socket::async_connect(peer_endpoint,connect_handler ). 2. io_service::run()=20 Logically, step 2 should precede step 1, but I could not do that as io_service::run() was failing as there was nothing registered to it.=20 Now, I have created an instance of "boost::asio::io_service::work " in the beginning of program. It helps the io_service to queue any aync calls. Hence now the sequence of calls is : 1. boost::asio::io_service::work(ioservice)=20 2. io_service::run()=20 3. tcp::socket::async_connect(peer_endpoint,connect_handler ). Thanks to those who may have tried to find out reasons for the problem. Regards, Vikas > -----Original Message----- > From: Chauhan, Vikas=20 > Sent: 12 September 2007 20:58 > To: asi...@li... > Cc: Sykes, Rob > Subject: [asio-users] basic_stream_socket::async_connect --=20 > non-blockingconnect vs async connect >=20 > Hello Chris et al, >=20 > I am trying to use "basic_stream_socket::async_connect" for=20 > non-blocking socket connect operation on Windows XP. > In case of connect failures, I have observed that this=20 > function is async but the connect functionality is still=20 > blocking. That is when connect operation fails, the=20 > "connect_handler" is getting called after the same duration=20 > as the time taken by "basic_stream_socket::connect" function=20 > to return. >=20 > Any comments? >=20 > I have implemented a similar functionality in my code (not=20 > using asio at the moment) using "select" API. Where I can=20 > retry non-blocking connect operation in less than 5 seconds. > However it is not possible using=20 > "basic_stream_socket::async_connect".=20 >=20 > It is very likely that this behaviour is due to lack of my=20 > knowledge of asio. Please advise me of possible way to=20 > achieve the desired functionality.=20 >=20 > Thanks in advance. >=20 > Regards, > Vikas >=20 >=20 >=20 |