Re: In airplane mode, socket writes unexpectedly don't fail
Re: In airplane mode, socket writes unexpectedly don't fail
- Subject: Re: In airplane mode, socket writes unexpectedly don't fail
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Wed, 31 Oct 2018 08:14:28 +0000
On 30 Oct 2018, at 23:40, Jens Alfke <email@hidden> wrote:
> My knowledge of TCP tells me that if you write to a socket, but no ACK packet
> is received within ~15 seconds, the socket will be closed with an error (I
> think ECONNRESET?)
I can’t speak to how Xamarin works, but if it’s a simple wrapper around BSD
Sockets then the expected behaviour here is that the kernel will maintain the
TCP connection, retrying indefinitely. BSD Sockets was designed for a world
where computers used wired connections that were manually configured, and thus
the kernel does not automatically close a connection just because its source
address has been lost.
High-level APIs, like CFSocketStream, actively monitor the connection to see if
the source address goes invalid.
> I’m uncomfortable with this, since I know Reachability can be unreliable and
> this usage doesn’t go along with the best practices
It is, alas, a mistake to apply your high-level intuition to this low-level
problem. In this case there’s a specific reachability API you should be using,
namely `SCNetworkReachabilityCreateWithAddressPair`. Once the socket has
connected you should get the local and peer address (`getsockname` and
`getpeername`) and feed that into `SCNetworkReachabilityCreateWithAddressPair`.
I recommend that you debounce this signal. That is, closing the connection
only if reachability indicates a problem for a second or so. Without this
debounce you can end up closing the connection in situations where it might
have recovered.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden