Boost Users :
Subject: Re: [Boost-users] [asio] sync receive_from with timeout
From: Stephan Menzel (stephan.menzel_at_[hidden])
Date: 2009-03-04 11:51:59
> Just a small addition. Instead of sleep, you can use a condition variable
> and wait on it with timeout. So the if condition would be smth like:
> if(!timed_wait(cond, timeout))
Well, I just started to implement this and I still get some erratic behaviour. Also I think in order to be consistent this can't be modular enough. There's the condition variable as well as the mutex around it (one more to the one I already use to protect the socket) and the thread function that needs to be bound to this object. All feasable and yet way to much complexity within the app compared to socket.receive_from(buffer, timeout), which I just noticed as I am currently using the originally posted receive_with_timeout in 2 classes already. I don't think I want all that and the thread still needs to be created and paid for.
I think I'll look into io_service.post. When the object that socket belongs to is created I can start several threads and use them as a pool. Then I might just use a timer, kill the socket and reinstanciate it. I hope this will make the blocking read return. It shouldn't happen too often anyway.
In addition I'll also prepare to post this as a bug report to asio. Frankly I tend to consider the absence of such functionality a bug. If you offer sync IO you gotta include it. Don't get me wrong, asio is a phantastic lib but this needs to be done. IMHO either by including it or by removing sync IO entirely. Workarounds are not a solution.
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