Set timeout of a socket?
Normally I'd use zmq_setsockopt with rcvtimeo if I only want to wait a fixed amount of time for a socket to receive. The implementation of recvin this wrapper though is blocking when EAGAIN is returned, which seems to defeat the purpose of setting rcvtimo.
Wouldn't it be more Julian to use a timer task?
Would you mind elaborating? How would I create a task that is willing to wait up to say 1sec to recv from a socket s?
Hmm, I guess it is pretty awkward; all the solutions I can come up with involve one task killing another task after a timeout.
Ya, that was my experience as well.
On Mon, Aug 10, 2015 at 7:46 PM, Steven G. Johnson <[email protected]
wrote:
Hmm, I guess it is pretty awkward; all the solutions I can come up with involve one task killing another task after a timeout.
— Reply to this email directly or view it on GitHub https://github.com/JuliaLang/ZMQ.jl/issues/87#issuecomment-129659072.
Well i'm not sure this is the most elegant, but something like this would work if you don't mind a blocked task sticking around indefinitely.
s = Socket()
c= Channel()
@async put!((c, :received), recv(s))
@async sleep(1); put!(c, (nothing, :timedout))
data, status = take!(c)
the blocked task will finish when the Channel is closed, so it shouldn't really be necessary to use the timeout feature in this way. I'm assuming you want this for some form of heartbeat / status indication? For that, I think you can instead create a worker loop that does all of the handling for the channel and have it tickle a local watchdog counter variable whenever it wakes up.
I did end up using a solution along those lines in Requests.jl. I still think it's kinda confusing for a ZMQ wrapper to allow setting rvctimeo but then to not actually timeout, but given that Julia has ways around this it's not a pressing issue for me anymore.
I agree that it would be nice to timeout if you explicitly requested it. Shouldn't be too hard to implement.
Jon,
Could you post your solution.
just what I posted earlier
thanks
Once some form of https://github.com/JuliaLang/julia/issues/13763 gets in, it will be an elegant solution to this general kind of situation.