[Mono-devel-list] Socket Send/ReceiveTimeouts
sessler at in.tum.de
Thu Apr 3 05:17:07 EST 2003
> I'm sorry, is it correct that this code closes the socket
> on send or receive timeout? If so I don't think that's
> right. I believe that on systems that do support setting of
> SO_RCVTIMEO and SO_SNDTIMEO the way to go is obviously to
> employ these options. On systems that do not support these
> I would call select or poll with appropriate timeout just
> before send/recv.
I don't know how other systems work with these settings, but from what
i tested, the ms .net framework closes the socket, after a timeout
A solution would be to try to set these settings and if a Exception is
thrown, use my code. But this would result in different behaivour on
different mono plattforms which sould at least be documented if not
> Additionally, although I didn't analyze the code carefully
> enough, it looks like it might be a subject to race conditions.
I hope not. These are the scenarios that i considered:
1. Timeout apears while socket is waiting:
- timeout method closes the socket, Exception is thrown, everything is
2. Timeout apears after the internal socket method returned.
2.1 the DisableTimeout method is first to lock the timer object
- the timeout is disabled, and a TimeoutActive is set to false (this is
set to true in the InitTimeout methods)
- then the OnTimeout method acquires the lock and because TimeoutActive
is false, the socket will not be closed
- the method returns correct
2.2 the OnTimeout method is first to lock the timer object
- the OnTimeout method closes the socket
- then the DisableTimeout method acquires the lock and because the
socket is closed, the method will throw a SocketException
3. The Timeout apears after the send/receive returned
- timeout is disabled everything is fine.
If i missed something please tell me.
The only downside is 2.2 where you got the result, but have to throw it
away. I found know way to perhibit this. At least it returns a correct
(Exception and socket closed/value and sockte open) to the upper level.
More information about the Mono-devel-list