$NetBSD: patch-ab,v 1.1.1.1 2006/06/03 23:29:24 rh Exp $

--- upnp/src/genlib/net/sock.c.orig	2006-02-23 07:38:03.000000000 +1000
+++ upnp/src/genlib/net/sock.c
@@ -49,6 +49,10 @@
 #include <unistd.h>
 #include "unixutil.h"
 
+#ifndef	MSG_NOSIGNAL
+#define	MSG_NOSIGNAL	0
+#endif
+
 /************************************************************************
 *	Function :	sock_init
 *
@@ -223,6 +227,15 @@ sock_read_write( IN SOCKINFO * info,
         }
     }
 
+#ifdef SO_NOSIGPIPE
+    {
+	int old;
+	int set = 1;
+	socklen_t olen = sizeof(old);
+	getsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, &olen);
+	setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set));
+#endif
+
     if( bRead ) {
         // read data
         numBytes = recv( sockfd, buffer, bufsize, MSG_NOSIGNAL );
@@ -235,6 +248,9 @@ sock_read_write( IN SOCKINFO * info,
                 send( sockfd, buffer + bytes_sent, byte_left,
                       MSG_DONTROUTE | MSG_NOSIGNAL );
             if( num_written == -1 ) {
+#ifdef SO_NOSIGPIPE
+	        setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, olen);
+#endif
                 return num_written;
             }
 
@@ -245,6 +261,11 @@ sock_read_write( IN SOCKINFO * info,
         numBytes = bytes_sent;
     }
 
+#ifdef SO_NOSIGPIPE
+	setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, olen);
+    }
+#endif
+
     if( numBytes < 0 ) {
         return UPNP_E_SOCKET_ERROR;
     }
