summaryrefslogtreecommitdiff
path: root/net/libupnp/patches/patch-ab
blob: 6b842a793d9efedb1dc6c3f12d8837e286ef86fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$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;
     }