|
Boost Users : |
Subject: [Boost-users] What is the effective way to use boost::asio::deadline_timer for udp socket receive_from?
From: jupiter (jupiter.hce_at_[hidden])
Date: 2017-04-12 11:17:41
Hi,
My program needs a sync udp socket send / receiver so I use the
deadline_timer as timeout for udp socket receive_from on Debian Jessie:
boost::asio::deadline_timer deadline(io_service,
boost::posix_time::seconds(2));
In checkDeadline function, when the timer expires, it calls socket.cancel,
otherwise calls the deadline.async_wait(checkDeadline); again.
Apparently when the program runs to socket.receive_from(), it is blocked
and the timer is never called because both socket.receive_from and the
timer in the same thread.
I've been thinking to run the timer in another thread, but I checked
Internet, there are comments said deadline_timer is not thread safe, please
correct me if I am wrong here. It will be a simple solution for me if I can
run timer on another thread. Anyone has other ideas to run the timer
effectively?
Appreciate your comments.
Thank you.
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