From eae4564cb7dea3ad9f5963814e82fd823267ff89 Mon Sep 17 00:00:00 2001 From: deadbeef Date: Fri, 26 May 2017 16:27:09 -0700 Subject: [PATCH] Disable SIGPIPE for sockets created on iOS. This can occur (and by default, terminates the process) for apps that don't use the "voip" UIBackgroundMode. We're already doing a similar thing on Linux (using MSG_NOSIGNAL for every packet sent). BUG=webrtc:7686 Review-Url: https://codereview.webrtc.org/2903313002 Cr-Commit-Position: refs/heads/master@{#18277} --- webrtc/base/physicalsocketserver.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/webrtc/base/physicalsocketserver.cc b/webrtc/base/physicalsocketserver.cc index a412703015..4ab33fb673 100644 --- a/webrtc/base/physicalsocketserver.cc +++ b/webrtc/base/physicalsocketserver.cc @@ -608,6 +608,15 @@ bool SocketDispatcher::Initialize() { ioctlsocket(s_, FIONBIO, &argp); #elif defined(WEBRTC_POSIX) fcntl(s_, F_SETFL, fcntl(s_, F_GETFL, 0) | O_NONBLOCK); +#endif +#if defined(WEBRTC_IOS) + // iOS may kill sockets when the app is moved to the background + // (specifically, if the app doesn't use the "voip" UIBackgroundMode). When + // we attempt to write to such a socket, SIGPIPE will be raised, which by + // default will terminate the process, which we don't want. By specifying + // this socket option, SIGPIPE will be disabled for the socket. + int value = 1; + ::setsockopt(s_, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value)); #endif ss_->Add(this); return true;