> Like the title says, I'm trying to figure out the cleanest way to interrupt
> a blocking socket send() (in case it takes too long, for example). Can you
> simply do a close() on the descriptor in another thread and be done with it?
There are unavoidable race conditions involved with issuing a 'close'
in one thread when another thread might or might not be in a blocking
'send'. Your question, by the way, starts from a false premise. There is
no way you could possibly know that the other thread was in a blocking
send, since there is no atomic 'set this variable and block in send'
This is important because the thread could always be *about* to call
'send' when you close the socket. In this case, if another thread calls
'socket' and gets the same descriptor, original thread will wind up
calling 'send' on a different connection entirely! Ouch.
So, don't do that.
The easiest way to solve this problem is to have avoided it in the
first place. Don't do a blocking 'send' unless you want to block until
the 'send' can complete.