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;