4

I am developing in iOS.

The App call the function in library , and send the packet via wifi.

When the App is running , I push the power button(not home button) on iPhone 5C and push again to open it. But it crash...

And it did not show which line is error , it only show the error like the following picture:

enter image description here

How to analyse this crash log via above picture?

Thanks in advance.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
Martin
  • 2,813
  • 11
  • 43
  • 66

1 Answers1

3

As mentioned by Apple, in Avoiding Common Networking Mistakes, you need to handle or disable SIGPIPE:

Use POSIX sockets efficiently (if at all).

If you are using POSIX sockets directly:

  • Handle or disable SIGPIPE.

When a connection closes, by default, your process receives a SIGPIPE signal. If your program does not handle or ignore this signal, your program will quit immediately. You can handle this in one of two ways:

Ignore the signal globally with the following line of code:

signal(SIGPIPE, SIG_IGN);

Tell the socket not to send the signal in the first place with the following lines of code (substituting the variable containing your socket in place of sock):

int value = 1;
setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value));

For maximum compatibility, you should set this flag on each incoming socket immediately after calling accept in addition to setting the flag on the listening socket itself.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • I'll just mention that I've experienced a crash exactly like the one in the OP's picture despite having "signal(SIGPIPE, SIG_IGN)" in my program. I think it happened after my app had been suspended, or at least having been put in background, and then being activated again. Anyway now I've added the second technique as well, and have crossed my fingers. – RenniePet Mar 08 '17 at 14:10