Hi,
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.
Pigeon.
>From be69879a629f05e1ab5466436bd1dfbb7772376c Mon Sep 17 00:00:00 2001
From: Pigeon <[EMAIL PROTECTED]>
Date: Sat, 9 Jun 2007 11:38:40 +1000
Subject: [PATCH] Get send not to raise SIGPIPE.
---
src/Network/jpg-httpd.cxx | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/Network/jpg-httpd.cxx b/src/Network/jpg-httpd.cxx
index f28b4c8..0f8cc63 100644
--- a/src/Network/jpg-httpd.cxx
+++ b/src/Network/jpg-httpd.cxx
@@ -43,6 +43,8 @@
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
+#include <sys/socket.h>
+
#include "jpg-httpd.hxx"
//[Leidson<]
@@ -130,7 +132,7 @@ void HttpdImageChannel :: foundTerminator( void ) {
return;
}
- if( send( ( char * ) szResponse, strlen( szResponse ) ) <= 0 ) {
+ if( send( ( char * ) szResponse, strlen( szResponse ), MSG_NOSIGNAL ) <= 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" );
@@ -148,9 +150,18 @@ void HttpdImageChannel :: foundTerminator( void ) {
break;
}
- nBytesSent = send( ( char * ) JpgFactory -> data() + nStep, nBlockSize );
+ errno = 0;
+ nBytesSent = send( ( char * ) JpgFactory -> data() + nStep, nBlockSize, MSG_NOSIGNAL );
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;
--
1.5.0.6
-------------------------------------------------------------------------
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