[vlc-commits] contrib: live555: set the MSG_NOSIGNAL flag when writing to sockets

Rémi Denis-Courmont git at videolan.org
Tue Jun 30 15:43:41 CEST 2015


vlc/vlc-2.2 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 21 20:46:09 2015 +0300| [19273afc1e6cbbecac98108b6ede581f33ffcff4] | committer: Jean-Baptiste Kempf

contrib: live555: set the MSG_NOSIGNAL flag when writing to sockets

So that the LibVLC application does not get killed by "Broken pipe".

(cherry picked from commit ecfd0b797211e80004833e3de55f5de07e1e9d79)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=19273afc1e6cbbecac98108b6ede581f33ffcff4
---

 contrib/src/live555/live555-nosignal.patch |  141 ++++++++++++++++++++++++++++
 contrib/src/live555/rules.mak              |    1 +
 2 files changed, 142 insertions(+)

diff --git a/contrib/src/live555/live555-nosignal.patch b/contrib/src/live555/live555-nosignal.patch
new file mode 100644
index 0000000..424b168
--- /dev/null
+++ b/contrib/src/live555/live555-nosignal.patch
@@ -0,0 +1,141 @@
+Copyright (C) 2015 Rémi Denis-Courmont
+
+Licensed under the terms of the GNU LGPL version 2.1 or later.
+
+diff -ru live555.orig/groupsock/GroupsockHelper.cpp live555/groupsock/GroupsockHelper.cpp
+--- live555.orig/groupsock/GroupsockHelper.cpp	2015-05-21 20:34:45.854307019 +0300
++++ live555/groupsock/GroupsockHelper.cpp	2015-05-21 20:36:36.003306022 +0300
+@@ -30,6 +30,9 @@
+ #define initializeWinsockIfNecessary() 1
+ #endif
+ #include <stdio.h>
++#ifndef MSG_NOSIGNAL
++# define MSG_NOSIGNAL 0
++#endif
+ 
+ // By default, use INADDR_ANY for the sending and receiving interfaces:
+ netAddressBits SendingInterfaceAddr = INADDR_ANY;
+@@ -337,7 +340,7 @@
+ 		    unsigned char* buffer, unsigned bufferSize) {
+   do {
+     MAKE_SOCKADDR_IN(dest, address.s_addr, port.num());
+-    int bytesSent = sendto(socket, (char*)buffer, bufferSize, 0,
++    int bytesSent = sendto(socket, (char*)buffer, bufferSize, MSG_NOSIGNAL,
+ 			   (struct sockaddr*)&dest, sizeof dest);
+     if (bytesSent != (int)bufferSize) {
+       char tmpBuf[100];
+diff -ru live555.orig/liveMedia/RTPInterface.cpp live555/liveMedia/RTPInterface.cpp
+--- live555.orig/liveMedia/RTPInterface.cpp	2015-05-21 20:34:45.855307019 +0300
++++ live555/liveMedia/RTPInterface.cpp	2015-05-21 20:38:10.383305167 +0300
+@@ -23,6 +23,9 @@
+ #include "RTPInterface.hh"
+ #include <GroupsockHelper.hh>
+ #include <stdio.h>
++#ifndef MSG_NOSIGNAL
++# define MSG_NOSIGNAL 0
++#endif
+ 
+ ////////// Helper Functions - Definition //////////
+ 
+@@ -339,7 +339,7 @@
+ #endif
+ 
+ Boolean RTPInterface::sendDataOverTCP(int socketNum, u_int8_t const* data, unsigned dataSize, Boolean forceSendToSucceed) {
+-  int sendResult = send(socketNum, (char const*)data, dataSize, 0/*flags*/);
++  int sendResult = send(socketNum, (char const*)data, dataSize, MSG_NOSIGNAL);
+   if (sendResult < (int)dataSize) {
+     // The TCP send() failed - at least partially.
+ 
+@@ -353,7 +353,7 @@
+       fprintf(stderr, "sendDataOverTCP: resending %d-byte send (blocking)\n", numBytesRemainingToSend); fflush(stderr);
+ #endif
+       makeSocketBlocking(socketNum, RTPINTERFACE_BLOCKING_WRITE_TIMEOUT_MS);
+-      sendResult = send(socketNum, (char const*)(&data[numBytesSentSoFar]), numBytesRemainingToSend, 0/*flags*/);
++      sendResult = send(socketNum, (char const*)(&data[numBytesSentSoFar]), numBytesRemainingToSend, MSG_NOSIGNAL);
+       if ((unsigned)sendResult != numBytesRemainingToSend) {
+ 	// The blocking "send()" failed, or timed out.  In either case, we assume that the
+ 	// TCP connection has failed (or is 'hanging' indefinitely), and we stop using it
+diff -ru live555.orig/liveMedia/RTSPClient.cpp live555/liveMedia/RTSPClient.cpp
+--- live555.orig/liveMedia/RTSPClient.cpp	2015-05-21 20:34:45.855307019 +0300
++++ live555/liveMedia/RTSPClient.cpp	2015-05-21 20:39:54.327304226 +0300
+@@ -24,6 +24,9 @@
+ #include "Locale.hh"
+ #include <GroupsockHelper.hh>
+ #include "ourMD5.hh"
++#ifndef MSG_NOSIGNAL
++# define MSG_NOSIGNAL 0
++#endif
+ 
+ ////////// RTSPClient implementation //////////
+ 
+@@ -497,7 +500,7 @@
+       delete[] origCmd;
+     }
+ 
+-    if (send(fOutputSocketNum, cmd, strlen(cmd), 0) < 0) {
++    if (send(fOutputSocketNum, cmd, strlen(cmd), MSG_NOSIGNAL) < 0) {
+       char const* errFmt = "%s send() failed: ";
+       unsigned const errLength = strlen(errFmt) + strlen(request->commandName());
+       char* err = new char[errLength];
+@@ -939,7 +942,7 @@
+     char tmpBuf[2*RTSP_PARAM_STRING_MAX];
+     snprintf((char*)tmpBuf, sizeof tmpBuf,
+              "RTSP/1.0 405 Method Not Allowed\r\nCSeq: %s\r\n\r\n", cseq);
+-    send(fOutputSocketNum, tmpBuf, strlen(tmpBuf), 0);
++    send(fOutputSocketNum, tmpBuf, strlen(tmpBuf), MSG_NOSIGNAL);
+   }
+ }
+ 
+diff -ru live555.orig/liveMedia/RTSPServerSupportingHTTPStreaming.cpp live555/liveMedia/RTSPServerSupportingHTTPStreaming.cpp
+--- live555.orig/liveMedia/RTSPServerSupportingHTTPStreaming.cpp	2015-05-21 20:34:45.857307019 +0300
++++ live555/liveMedia/RTSPServerSupportingHTTPStreaming.cpp	2015-05-21 20:39:44.568304314 +0300
+@@ -24,6 +24,9 @@
+ #include <sys/stat.h>
+ #endif
+ #include <time.h>
++#ifndef MSG_NOSIGNAL
++# define MSG_NOSIGNAL 0
++#endif
+ 
+ RTSPServerSupportingHTTPStreaming*
+ RTSPServerSupportingHTTPStreaming::createNew(UsageEnvironment& env, Port rtspPort,
+@@ -140,7 +143,7 @@
+ 	       lastModifiedHeader(streamName),
+ 	       numTSBytesToStream);
+       // Send the response now, because we're about to add more data (from the source):
+-      send(fClientOutputSocket, (char const*)fResponseBuffer, strlen((char*)fResponseBuffer), 0);
++      send(fClientOutputSocket, (char const*)fResponseBuffer, strlen((char*)fResponseBuffer), MSG_NOSIGNAL);
+       fResponseBuffer[0] = '\0'; // We've already sent the response.  This tells the calling code not to send it again.
+       
+       // Ask the media source to deliver - to the TCP sink - the desired data:
+@@ -234,7 +237,7 @@
+ 	   playlistLen);
+ 
+   // Send the response header now, because we're about to add more data (the playlist):
+-  send(fClientOutputSocket, (char const*)fResponseBuffer, strlen((char*)fResponseBuffer), 0);
++  send(fClientOutputSocket, (char const*)fResponseBuffer, strlen((char*)fResponseBuffer), MSG_NOSIGNAL);
+   fResponseBuffer[0] = '\0'; // We've already sent the response.  This tells the calling code not to send it again.
+ 
+   // Then, send the playlist.  Because it's large, we don't do so using "send()", because that might not send it all at once.
+diff -ru live555.orig/liveMedia/TCPStreamSink.cpp live555/liveMedia/TCPStreamSink.cpp
+--- live555.orig/liveMedia/TCPStreamSink.cpp	2015-05-21 20:34:45.857307019 +0300
++++ live555/liveMedia/TCPStreamSink.cpp	2015-05-21 20:39:34.599304405 +0300
+@@ -20,6 +20,9 @@
+ 
+ #include "TCPStreamSink.hh"
+ #include "RTSPCommon.hh" // for "ignoreSigPipeOnSocket()"
++#ifndef MSG_NOSIGNAL
++# define MSG_NOSIGNAL 0
++#endif
+ 
+ TCPStreamSink* TCPStreamSink::createNew(UsageEnvironment& env, int socketNum) {
+   return new TCPStreamSink(env, socketNum);
+@@ -51,7 +54,7 @@
+   // First, try writing data to our output socket, if we can:
+   if (fOutputSocketIsWritable && numUnwrittenBytes() > 0) {
+     int numBytesWritten
+-      = send(fOutputSocketNum, (const char*)&fBuffer[fUnwrittenBytesStart], numUnwrittenBytes(), 0);
++      = send(fOutputSocketNum, (const char*)&fBuffer[fUnwrittenBytesStart], numUnwrittenBytes(), MSG_NOSIGNAL);
+     if (numBytesWritten < (int)numUnwrittenBytes()) {
+       // The output socket is no longer writable.  Set a handler to be called when it becomes writable again.
+       fOutputSocketIsWritable = False;
diff --git a/contrib/src/live555/rules.mak b/contrib/src/live555/rules.mak
index 7d08bb8..7057b8d 100644
--- a/contrib/src/live555/rules.mak
+++ b/contrib/src/live555/rules.mak
@@ -41,6 +41,7 @@ live555: $(LIVE555_FILE) .sum-live555
 	rm -Rf live
 	$(UNPACK)
 	chmod -R u+w live
+	(cd live && patch -fp1) < $(SRC)/live555/live555-nosignal.patch
 	cd live && sed -e 's%cc%$(CC)%' -e 's%c++%$(CXX)%' -e 's%LIBRARY_LINK =.*ar%LIBRARY_LINK = $(AR)%' -i.orig config.$(LIVE_TARGET)
 	cd live && sed -i.orig -e s/"libtool -s -o"/"ar cr"/g config.macosx*
 	cd live && sed -i.orig \



More information about the vlc-commits mailing list