On Oct 23, 2008, at 2:51 PM, Greg wrote:
<snip>
Ideally there would be events directly on the socket to let you know about changes that may be relevant
I'm surprised by the current behavior of the sockets. I'm using asynchronous sockets and calling recv() or send() on them does not result in any serious error on errno after switching jumping networks, which is bizarre and the reason I started looking outside the BSD socket API in the first place. I'm curious as to why they don't do that...
This will fail eventually. I think there are a few reasons this isn't handled.
The first is simply that the entire stack wasn't designed for the dynamic environment we live in today. sockets were designed decades ago, and considering how old they are, they do a good job. If you don't give them a little leeway for being so old, sockets are pretty crappy.
The second reason is that returning an error immediately breaks a feature...or behavior that may have been more accidental than intentional. If you were to wait for a read, your tcp socket will maintain state indefinitely. If you picked up your laptop and took it home then back to work the next day, the remote side could send data on that connection and it would just work. Unless there are keepalives in use, maintaining a TCP socket requires no data transmission. If you try and send, the send will eventually timeout. Before it times out, you have the opportunity to get your device back in to a state where that send could succeed. If the stackwere to immediately detect the routing change for the socket and decide that the socket state was no longer valid, the behavior above would break. Depending on what's going on, that may or may not be a big deal.
Since the application using the socket is in a better place to know about whether or not the change in network state is a big deal and whether losing the current connection would totally suck or just be an excuse to try another connection, the application should be the one making the decision about how to handle these network change events.
-josh
|