Index: configure.ac
===================================================================
RCS file: /repository/curl/configure.ac,v
retrieving revision 1.27
diff -u -r1.27 configure.ac
--- configure.ac	27 Nov 2003 09:52:13 -0000	1.27
+++ configure.ac	2 Dec 2003 09:59:32 -0000
@@ -332,6 +332,18 @@
 ])
 
 dnl **********************************************************************
+dnl Check for MSG_NOSIGNAL
+dnl **********************************************************************
+AC_MSG_CHECKING(for MSG_NOSIGNAL)
+AC_TRY_COMPILE([#include <sys/socket.h>],
+ [ int f = MSG_NOSIGNAL; ],
+ [ AC_MSG_RESULT(yes)
+   AC_DEFINE(HAVE_MSG_NOSIGNAL, 1,
+             [Define this symbol if you have MSG_NOSIGNAL]) ],
+ [ AC_MSG_RESULT(no)]
+)
+
+dnl **********************************************************************
 dnl Check for the random seed preferences 
 dnl **********************************************************************
 
Index: lib/setup.h
===================================================================
RCS file: /repository/curl/lib/setup.h,v
retrieving revision 1.35
diff -u -r1.35 setup.h
--- lib/setup.h	6 Nov 2003 07:21:32 -0000	1.35
+++ lib/setup.h	2 Dec 2003 09:59:33 -0000
@@ -116,6 +116,15 @@
 #endif
 #endif
 
+#ifdef HAVE_MSG_NOSIGNAL
+/* If we have the MSG_NOSIGNAL define, we make sure to use that in the forth
+   argument to send() and recv() */
+#define SEND_4TH_ARG MSG_NOSIGNAL
+#else
+#define SEND_4TH_ARG 0
+#endif
+
+
 /* Below we define four functions. They should
    1. close a socket
    2. read from a socket
@@ -139,14 +148,14 @@
 
 #if !defined(__GNUC__) || defined(__MINGW32__)
 #define sclose(x) closesocket(x)
-#define sread(x,y,z) recv(x,y,z,0)
-#define swrite(x,y,z) (size_t)send(x,y,z,0)
+#define sread(x,y,z) recv(x,y,z, SEND_4TH_ARG)
+#define swrite(x,y,z) (size_t)send(x,y,z, SEND_4TH_ARG)
 #undef HAVE_ALARM
 #else
      /* gcc-for-win is still good :) */
 #define sclose(x) close(x)
-#define sread(x,y,z) recv(x,y,z,0)
-#define swrite(x,y,z) send(x,y,z,0)
+#define sread(x,y,z) recv(x,y,z, SEND_4TH_ARG)
+#define swrite(x,y,z) send(x,y,z, SEND_4TH_ARG)
 #define HAVE_ALARM
 #endif
 
@@ -171,12 +180,12 @@
 
 #ifdef __BEOS__
 #define sclose(x) closesocket(x)
-#define sread(x,y,z) (ssize_t)recv(x,y,z,0)
-#define swrite(x,y,z) (ssize_t)send(x,y,z,0)
+#define sread(x,y,z) (ssize_t)recv(x,y,z, SEND_4TH_ARG)
+#define swrite(x,y,z) (ssize_t)send(x,y,z, SEND_4TH_ARG)
 #else
 #define sclose(x) close(x)
-#define sread(x,y,z) recv(x,y,z,0)
-#define swrite(x,y,z) send(x,y,z,0)
+#define sread(x,y,z) recv(x,y,z, SEND_4TH_ARG)
+#define swrite(x,y,z) send(x,y,z, SEND_4TH_ARG)
 #endif
 
 #define HAVE_ALARM
Index: lib/transfer.c
===================================================================
RCS file: /repository/curl/lib/transfer.c,v
retrieving revision 1.185
diff -u -r1.185 transfer.c
--- lib/transfer.c	24 Nov 2003 07:15:37 -0000	1.185
+++ lib/transfer.c	2 Dec 2003 09:59:33 -0000
@@ -1457,7 +1457,7 @@
   * different ports! */
   data->state.allow_port = TRUE;
 
-#if defined(HAVE_SIGNAL) && defined(SIGPIPE)
+#if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL)
   /*************************************************************
    * Tell signal handler to ignore SIGPIPE
    *************************************************************/
@@ -1473,7 +1473,7 @@
 
 CURLcode Curl_posttransfer(struct SessionHandle *data)
 {
-#if defined(HAVE_SIGNAL) && defined(SIGPIPE)
+#if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL)
   /* restore the signal handler for SIGPIPE before we get back */
   if(!data->set.no_signal)
     signal(SIGPIPE, data->state.prev_signal);
