[Mono-list] Patch for MSG_NOSIGNAL

Jaroslaw Kowalski jarek@atm.com.pl
Mon, 10 Jun 2002 20:19:06 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C210BC.1231E0F0
Content-Type: text/plain;
	charset="iso-8859-2"
Content-Transfer-Encoding: 7bit

Hi all!

I've prepared a patch that prevents SIGPIPE from being raised while
reading/writing from/to a closed socket. It uses MSG_NOSIGNAL technique that
has been discussed some time ago.

Can you please verify it and commit to CVS?

Regards,

Jarek


------=_NextPart_000_0013_01C210BC.1231E0F0
Content-Type: application/octet-stream;
	name="MSG_NOSIGNAL.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="MSG_NOSIGNAL.patch"

? docs/Makefile=0A=
? docs/Makefile.in=0A=
? mono/os/unix/.deps=0A=
Index: ChangeLog=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mono/ChangeLog,v=0A=
retrieving revision 1.98=0A=
diff -u -r1.98 ChangeLog=0A=
--- ChangeLog	30 May 2002 10:16:22 -0000	1.98=0A=
+++ ChangeLog	10 Jun 2002 18:12:20 -0000=0A=
@@ -1,3 +1,7 @@=0A=
+2002-06-10  Jaroslaw Kowalski <jarek@atm.com.pl>=0A=
+=0A=
+	* configure.in: added checks for MSG_NOSIGNAL=0A=
+=0A=
 2002-05-30  Daniel Morgan <danmorg@sc.rr.com>=0A=
 =0A=
 	* doc/ado-net: update the ado-net web page on go-mono.com=0A=
Index: acconfig.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mono/acconfig.h,v=0A=
retrieving revision 1.16=0A=
diff -u -r1.16 acconfig.h=0A=
--- acconfig.h	30 Apr 2002 19:30:06 -0000	1.16=0A=
+++ acconfig.h	10 Jun 2002 18:12:20 -0000=0A=
@@ -1,5 +1,6 @@=0A=
 #undef HAVE_INET_PTON=0A=
 #undef HAVE_INET_ATON=0A=
+#undef HAVE_MSG_NOSIGNAL=0A=
 #undef HAVE_SOL_IP=0A=
 #undef HAVE_SOL_TCP=0A=
 #undef HAVE_IP_PKTINFO=0A=
Index: configure.in=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mono/configure.in,v=0A=
retrieving revision 1.80=0A=
diff -u -r1.80 configure.in=0A=
--- configure.in	18 May 2002 17:41:44 -0000	1.80=0A=
+++ configure.in	10 Jun 2002 18:12:21 -0000=0A=
@@ -183,6 +183,21 @@=0A=
 	dnl *****************************=0A=
 	AC_CHECK_LIB(socket, socket, LIBS=3D"$LIBS -lsocket")=0A=
 =0A=
+	dnl *******************************=0A=
+	dnl *** Checks for MSG_NOSIGNAL ***=0A=
+	dnl *******************************=0A=
+	AC_MSG_CHECKING(for MSG_NOSIGNAL)=0A=
+	AC_TRY_COMPILE([#include <sys/socket.h>], [=0A=
+		int f =3D MSG_NOSIGNAL;=0A=
+	], [=0A=
+		# Yes, we have it...=0A=
+		AC_MSG_RESULT(yes)=0A=
+		AC_DEFINE(HAVE_MSG_NOSIGNAL)=0A=
+	], [=0A=
+		# We'll have to use signals=0A=
+		AC_MSG_RESULT(no)=0A=
+	])=0A=
+=0A=
 	dnl *****************************=0A=
 	dnl *** Checks for SOL_IP     ***=0A=
 	dnl *****************************=0A=
Index: mono/io-layer/ChangeLog=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mono/mono/io-layer/ChangeLog,v=0A=
retrieving revision 1.53=0A=
diff -u -r1.53 ChangeLog=0A=
--- mono/io-layer/ChangeLog	8 Jun 2002 17:57:49 -0000	1.53=0A=
+++ mono/io-layer/ChangeLog	10 Jun 2002 18:12:22 -0000=0A=
@@ -1,3 +1,8 @@=0A=
+2002-06-10  Jaroslaw Kowalski <jarek@atm.com.pl>=0A=
+=0A=
+	* sockets.c: Prevent SIGPIPE from being raised when writing to=0A=
+	a closed socket.=0A=
+=0A=
 2002-06-08  Jeffrey Stedfast  <fejj@ximian.com>=0A=
 =0A=
 	* mono-mutex.c (mono_once): New convenience function for my=0A=
Index: mono/io-layer/sockets.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mono/mono/io-layer/sockets.c,v=0A=
retrieving revision 1.12=0A=
diff -u -r1.12 sockets.c=0A=
--- mono/io-layer/sockets.c	8 Jun 2002 17:57:49 -0000	1.12=0A=
+++ mono/io-layer/sockets.c	10 Jun 2002 18:12:22 -0000=0A=
@@ -23,6 +23,10 @@=0A=
 #endif=0A=
 #include <unistd.h>=0A=
 =0A=
+#ifndef HAVE_MSG_NOSIGNAL=0A=
+#include <signal.h>=0A=
+#endif=0A=
+=0A=
 #include <mono/io-layer/wapi.h>=0A=
 #include <mono/io-layer/wapi-private.h>=0A=
 #include <mono/io-layer/socket-private.h>=0A=
@@ -657,6 +661,9 @@=0A=
 int _wapi_recvfrom(guint32 handle, void *buf, size_t len, int =
recv_flags,=0A=
 		   struct sockaddr *from, socklen_t *fromlen)=0A=
 {=0A=
+#ifndef HAVE_MSG_NOSIGNAL=0A=
+	void (*old_sigpipe)(int);	// old SIGPIPE handler=0A=
+#endif=0A=
 	struct _WapiHandlePrivate_socket *socket_private_handle;=0A=
 	gboolean ok;=0A=
 	int ret;=0A=
@@ -675,8 +682,16 @@=0A=
 		return(SOCKET_ERROR);=0A=
 	}=0A=
 	=0A=
+#ifdef HAVE_MSG_NOSIGNAL=0A=
+	ret=3Drecvfrom(socket_private_handle->fd, buf, len, recv_flags | =
MSG_NOSIGNAL, from,=0A=
+		     fromlen);=0A=
+#else=0A=
+	old_sigpipe =3D signal(SIGPIPE, SIG_IGN);=0A=
 	ret=3Drecvfrom(socket_private_handle->fd, buf, len, recv_flags, from,=0A=
 		     fromlen);=0A=
+	signal(SIGPIPE, old_sigpipe);=0A=
+#endif=0A=
+=0A=
 	if(ret=3D=3D-1) {=0A=
 #ifdef DEBUG=0A=
 		g_message(G_GNUC_PRETTY_FUNCTION ": recv error: %s",=0A=
@@ -719,6 +734,9 @@=0A=
 =0A=
 int _wapi_send(guint32 handle, const void *msg, size_t len, int =
send_flags)=0A=
 {=0A=
+#ifndef HAVE_MSG_NOSIGNAL=0A=
+	void (*old_sigpipe)(int);	// old SIGPIPE handler=0A=
+#endif=0A=
 	struct _WapiHandlePrivate_socket *socket_private_handle;=0A=
 	gboolean ok;=0A=
 	int ret;=0A=
@@ -736,8 +754,14 @@=0A=
 		WSASetLastError(WSAENOTSOCK);=0A=
 		return(SOCKET_ERROR);=0A=
 	}=0A=
-	=0A=
+=0A=
+#ifdef HAVE_MSG_NOSIGNAL=0A=
+	ret=3Dsend(socket_private_handle->fd, msg, len, send_flags | =
MSG_NOSIGNAL);=0A=
+#else=0A=
+	old_sigpipe =3D signal(SIGPIPE, SIG_IGN);=0A=
 	ret=3Dsend(socket_private_handle->fd, msg, len, send_flags);=0A=
+	signal(SIGPIPE, old_sigpipe);=0A=
+#endif=0A=
 	if(ret=3D=3D-1) {=0A=
 #ifdef DEBUG=0A=
 		g_message(G_GNUC_PRETTY_FUNCTION ": send error: %s",=0A=
@@ -787,6 +811,9 @@=0A=
 int _wapi_sendto(guint32 handle, const void *msg, size_t len, int =
send_flags,=0A=
 		 const struct sockaddr *to, socklen_t tolen)=0A=
 {=0A=
+#ifndef HAVE_MSG_NOSIGNAL=0A=
+	void (*old_sigpipe)(int);	// old SIGPIPE handler=0A=
+#endif=0A=
 	struct _WapiHandlePrivate_socket *socket_private_handle;=0A=
 	gboolean ok;=0A=
 	int ret;=0A=
@@ -805,7 +832,13 @@=0A=
 		return(SOCKET_ERROR);=0A=
 	}=0A=
 	=0A=
+#ifdef HAVE_MSG_NOSIGNAL=0A=
+	ret=3Dsendto(socket_private_handle->fd, msg, len, send_flags | =
MSG_NOSIGNAL, to, tolen);=0A=
+#else=0A=
+	old_sigpipe =3D signal(SIGPIPE, SIG_IGN);=0A=
 	ret=3Dsendto(socket_private_handle->fd, msg, len, send_flags, to, =
tolen);=0A=
+	signal(SIGPIPE, old_sigpipe);=0A=
+#endif=0A=
 	if(ret=3D=3D-1) {=0A=
 #ifdef DEBUG=0A=
 		g_message(G_GNUC_PRETTY_FUNCTION ": send error: %s",=0A=

------=_NextPart_000_0013_01C210BC.1231E0F0--