-
Notifications
You must be signed in to change notification settings - Fork 193
Description
Heya,
Disclaimer: I'm still figuring this stuff out, so it might be obvious for some of you. That would actually be cool, because then documenting it should be easy :)
I think we should document a recommended way to interrupt threads that are blocking on a recv
call.
Motivating context
I want to build a small tool that listens to a unix socket, connects to another one and forwards data in both directions. I've decided to have one thread per direction, i.e. downstream
recv
s from the connection made to us and writes to the one we connect to, while upstream
does the same thing but with the sockets flipped.
The situation I'm struggling with is that one of the connections is closed by the other end. (Since it's basically symmetrical at this point, I think we can consider them in one go). I obviously want the tool to be a good citizen, so the other socket should be gracefully closed immediately.
As far as I can tell, there's no way to wait for recv
or something else, so the only thing I can do is use throwTo
to interrupt the thread, right? (And then close the socket in an appropriate exception handler)
So I was looking for something in the documentation that tells me whether asynchronous exceptions are delivered while blocking on recv
but didn't find anything. I've considered using shutdown
on the socket instead, but that seems like a worse solution because it is socket-specific.
It seems to me that all applications that work with multiple sockets in a single context need something like this, so some guidance would be great. Could also be just a link to some existing explanation of course