• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: In airplane mode, socket writes unexpectedly don't fail
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >In airplane mode, socket writes unexpectedly don't fail (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: In airplane mode, socket writes unexpectedly don't fail
  • Next by Date: Re: In airplane mode, socket writes unexpectedly don't fail
  • Previous by thread: Re: In airplane mode, socket writes unexpectedly don't fail
  • Next by thread: Re: In airplane mode, socket writes unexpectedly don't fail
  • Index(es):
    • Date
    • Thread