-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set timeout of a socket? #87
Comments
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 |
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]
|
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 |
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 JuliaLang/julia#13763 gets in, it will be an elegant solution to this general kind of situation. |
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
recv
in this wrapper though is blocking when EAGAIN is returned, which seems to defeat the purpose of setting rcvtimo.The text was updated successfully, but these errors were encountered: