[hxcommon] CR - handle connection closure by the server

[hxcommon] CR - handle connection closure by the server

Henry Ping ping at real.com
Thu Jul 24 19:42:06 PDT 2003


This is to fix HC issue#474.

Currently, the server closes the connection after sending alert, the client 
receives SIGPIPE in write() on Unix and exits abruptly. After some research 
on the net, the proper fix is to ignore the SIGPIPE and check the return 
code from write() which we already have and exits the program gracefully.

If there is no objection, I will check this in to both HEAD and Kittyhawk 
tomorrow morning.

-->Henry
-------------- next part --------------
? a
? common_netio.dsp
? common_netio.dsw
? dbg32
? Makefile
? Umakefil.upp
Index: platform/unix/unix_net.cpp
===================================================================
RCS file: /cvs/common/netio/platform/unix/unix_net.cpp,v
retrieving revision 1.2
diff -u -w -4 -r1.2 unix_net.cpp
--- platform/unix/unix_net.cpp	20 Feb 2003 15:14:09 -0000	1.2
+++ platform/unix/unix_net.cpp	25 Jul 2003 01:31:04 -0000
@@ -52,8 +52,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <signal.h>
 #include <assert.h>
 #include "hxcom.h"
 #include "hxbuffer.h"
 #include "timebuff.h"
@@ -109,17 +110,26 @@
 	m_anDNSPipe[1] = nInvalidPipe;
 	m_nChildProcID = 0;
 	m_szPipeIP[0]  = '\0';
 
-	
 	read_pending = FALSE;
 	m_lRefCount	    = 0;
 	m_pInBuffer = new char[TCP_BUF_SIZE];
 
 	m_bReuseAddr = FALSE;
 	m_bReusePort = FALSE;
 	m_pAsyncHost = NULL;
         
+        // When the connection is closed by the server, SIGPIPE will be thrown 
+        // in next write() and terminates the program abruptly.
+        //
+        // In order to gracefully exists the program, it's recommended to:
+        // - ignore the SIGPIPE and
+        // - checks the return code(errno) from write()
+        // 
+        // for read(), it simply returns 0 when the connection is closed.
+        sigignore(SIGPIPE);
+
 #ifdef _UNIX_THREADS_SUPPORTED
         m_pResolver  = NULL;
 #endif        
 }

-------------- next part --------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe at common.helixcommunity.org
For additional commands, e-mail: dev-help at common.helixcommunity.org


More information about the Common-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.