Skip to content
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

Open
malmaud opened this issue Aug 8, 2015 · 12 comments · May be fixed by #217
Open

Set timeout of a socket? #87

malmaud opened this issue Aug 8, 2015 · 12 comments · May be fixed by #217

Comments

@malmaud
Copy link

malmaud commented Aug 8, 2015

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.

@stevengj
Copy link
Contributor

Wouldn't it be more Julian to use a timer task?

@malmaud
Copy link
Author

malmaud commented Aug 10, 2015

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?

@stevengj
Copy link
Contributor

Hmm, I guess it is pretty awkward; all the solutions I can come up with involve one task killing another task after a timeout.

@malmaud
Copy link
Author

malmaud commented Aug 11, 2015

Ya, that was my experience as well.

On Mon, Aug 10, 2015 at 7:46 PM, Steven G. Johnson <notifications@github.com

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
#87 (comment).

@malmaud
Copy link
Author

malmaud commented Aug 14, 2015

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)

@vtjnash
Copy link
Contributor

vtjnash commented Oct 7, 2015

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.

@malmaud
Copy link
Author

malmaud commented Oct 7, 2015

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.

@stevengj
Copy link
Contributor

stevengj commented Oct 7, 2015

I agree that it would be nice to timeout if you explicitly requested it. Shouldn't be too hard to implement.

@dmiljkovic
Copy link

Jon,

Could you post your solution.

@malmaud
Copy link
Author

malmaud commented Nov 4, 2015

just what I posted earlier

@dmiljkovic
Copy link

thanks

@malmaud
Copy link
Author

malmaud commented Nov 5, 2015

Once some form of JuliaLang/julia#13763 gets in, it will be an elegant solution to this general kind of situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants