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: email@hidden
- Date: Wed, 31 Oct 2018 09:00:32 -0700
TCP will give up on a write operation after the number of retries is
exceeded, but this can take a long time (15? minutes). There are socket
options to adjust this. Also, if the write() is not blocking, you need
some other way to get signaled, via select(), kqueue() or another
read/write attempt. Also if they are concerned with liveliness, they
probably want to enable TCP KEEP ALIVE option to let it periodically
probe.
Tim
On 2018-10-30 16:40, Jens Alfke wrote:
> A co-worker is struggling with handling online/offline transitions in some
> networking code in a Xamarin (i.e. Mono, i.e. .NET) app for iOS. The code
> maintains a TCP socket to a server. If the device goes offline or into
> Airplane Mode, the code needs to close the socket, so that the higher levels
> of the app know it's not online anymore.
>
> The behavior he's reporting is that, when the device is put into Airplane
> Mode, the socket acts as though it's still connected. It doesn't close, and
> (obviously) doesn't receive any data, but most strangely the socket doesn't
> fail after data is written to it. 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?) But he swears this
> isn't happening -- it's like the writes go to /dev/null.
>
> I've never seen this, but I've mostly been using NSURLSession or at least
> NSStream, not POSIX socket APIs, so the behavior may be different. My first
> guess was that Mono is doing something sketchy; he looked into the source
> code and found that it uses send() instead of write() to write to the TCP
> socket; is that kosher?
>
> The workaround he's adopting is to run a SCNetworkReachability notifier, and
> to close the socket and go into offline mode when notified that the host is
> unreachable. I'm uncomfortable with this, since I know Reachability can be
> unreliable and this usage doesn't go along with the best practices, i.e.
> using it just as a trigger to connect, not disconnect.
>
> So what's the deal with Airplane Mode? I would assume that it takes down all
> network interfaces, which would close all sockets. But it doesn't. Even so, I
> would assume that writing to a TCP socket would cause an error pretty soon;
> but apparently it doesn't.
>
> Any advice?
>
> --Jens
> _______________________________________________
> 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
_______________________________________________
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