>     The problem was if a client connects and closes the connection for
> whatever reason while the jpg-httpd is sending the image (e.g. web
> browser refreshes when loading the first image), a SIGPIPE will be
> raised which isn't handled and causes FG to simply exits.
> 
>     The attached fix calls send with MSG_NOSIGNAL which tells the call
> not to raise SIGPIPE, and so we can handle the EPIPE.
> 
>     This patch works with both plib and osg branch.


    Patch redone, since MSG_NOSIGNAL seems to be a Linux only thing.


Pigeon.

diff --git a/src/Network/jpg-httpd.cxx b/src/Network/jpg-httpd.cxx
index 3deadf4..c94f472 100644
--- a/src/Network/jpg-httpd.cxx
+++ b/src/Network/jpg-httpd.cxx
@@ -44,6 +44,10 @@
 #include <Main/globals.hxx>
 #include <Main/renderer.hxx>
 
+#if defined(__linux__)
+#include <sys/socket.h>
+#endif
+
 #include "jpg-httpd.hxx"
 
 #define __MAX_HTTP_BLOCK_SIZE       4096
@@ -143,7 +147,12 @@ void HttpdImageChannel :: foundTerminator( void ) {
 		return;
 	    }
 
-	    if( send( ( char * ) szResponse, strlen( szResponse ) ) <= 0 )  {
+	    int flags = 0;
+#if defined(__linux__)
+	    flags = MSG_NOSIGNAL;
+#endif
+
+	    if( send( ( char * ) szResponse, strlen( szResponse ), flags ) <= 0 )  {
 	        SG_LOG( SG_IO, SG_DEBUG, "<<<<<<<<< Error to send HTTP response. Ignoring request.\n" );
 		buffer.remove();
 		SG_LOG( SG_IO, SG_DEBUG, "<<<<<<<<< End of image Transmission.\n" );
@@ -161,9 +170,18 @@ void HttpdImageChannel :: foundTerminator( void ) {
 		    break;
 		}
 
-		nBytesSent = send( ( char * ) JpgFactory -> data() + nStep, nBlockSize );
+		errno = 0;
+		nBytesSent = send( ( char * ) JpgFactory -> data() + nStep, nBlockSize, flags );
 
 		if( nBytesSent <= 0 )  {
+
+		    if( errno == EPIPE ) {
+			SG_LOG( SG_IO, SG_DEBUG, "<<<<<<<<< Error sending image. Aborting.\n" );
+			buffer.remove();
+			SG_LOG( SG_IO, SG_DEBUG, "<<<<<<<<< End of image Transmission.\n" );
+			return;
+		    }
+
   		    if( nTimeoutCount == __TIMEOUT_COUNT )  {
 		        SG_LOG( SG_IO, SG_DEBUG, "<<<<<<<<< Timeout reached. Exiting before end of image transmission.\n" );
 			nTimeoutCount = 0;
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Flightgear-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to