
Hi, i am currently trying to implement something very simple: i have some network code (using boost/asio) which waits for data on a tcp connection (tcp::socket). Now i want this waiting operation to have a timeout. I did not find timeout capability in boost/asio so i tried to implement a timer class using boost/thread. Now there are two problems: a) the boost::thread object representing the thread that should be interrupted after a given time is not necessarily available. i looked at the namespace this_thread but found no possibility to gain access to a reference to the current thread. b) the interrupt() method only works when the interrupted thread is at one of the predefined interruption points. In my example however, that thread is held up in a boost/asio method. I suppose i could resolve b) by using asynchronous receives but that would take some serious restructuring and problem a) would still remain. What i really want is just a timeout version of the synchronous receive in boost/asio. Any ideas? Dominik

Look at asio::deadline_timer.
i am currently trying to implement something very simple: i have some network code (using boost/asio) which waits for data on a tcp connection (tcp::socket). Now i want this waiting operation to have a timeout. I did not find timeout capability in boost/asio so i tried to implement a timer class using boost/thread.

Thanks, i already did :) I could use deadline_timer to perform an asynchronous wait and have it call a given method when the timer expires. But i still need a way to interrupt the thread that is currently waiting for the tcp data, and since that thread object would not be available in the callback method i don't see how i could do that. Igor R wrote:
Look at asio::deadline_timer.
i am currently trying to implement something very simple: i have some network code (using boost/asio) which waits for data on a tcp connection (tcp::socket). Now i want this waiting operation to have a timeout. I did not find timeout capability in boost/asio so i tried to implement a timer class using boost/thread.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Dominik Steenken wrote:
Thanks, i already did :) I could use deadline_timer to perform an asynchronous wait and have it call a given method when the timer expires. But i still need a way to interrupt the thread that is currently waiting for the tcp data, and since that thread object would not be available in the callback method i don't see how i could do that.
I wonder what you want the interrupted thread to do, you could close the socket from the timeout handler. Using an synchronous wait, on an event that might not happen, to block a thread isn't the way I would use boost:asio, the point of async operations is that one thread can have multiple events pending. If you are doing synchronous waits for data from the socket, then switching to asynchronous i/o may well help you here.
Igor R wrote:
Look at asio::deadline_timer.
i am currently trying to implement something very simple: i have some network code (using boost/asio) which waits for data on a tcp connection (tcp::socket). Now i want this waiting operation to have a timeout. I did not find timeout capability in boost/asio so i tried to implement a timer class using boost/thread.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Bill Somerville

ok, i suppose you're right. I thought i could maybe avoid having to restructure my code but oh well. Thanks, Dominik Bill Somerville wrote:
Dominik Steenken wrote:
Thanks, i already did :) I could use deadline_timer to perform an asynchronous wait and have it call a given method when the timer expires. But i still need a way to interrupt the thread that is currently waiting for the tcp data, and since that thread object would not be available in the callback method i don't see how i could do that.
I wonder what you want the interrupted thread to do, you could close the socket from the timeout handler. Using an synchronous wait, on an event that might not happen, to block a thread isn't the way I would use boost:asio, the point of async operations is that one thread can have multiple events pending. If you are doing synchronous waits for data from the socket, then switching to asynchronous i/o may well help you here.
Igor R wrote:
Look at asio::deadline_timer.
i am currently trying to implement something very simple: i have some network code (using boost/asio) which waits for data on a tcp connection (tcp::socket). Now i want this waiting operation to have a timeout. I did not find timeout capability in boost/asio so i tried to implement a timer class using boost/thread.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Bill Somerville
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Bill Somerville
-
Dominik Steenken
-
Igor R