[cp-patches] RFC: native/jni/native-lib/cpnet.c: SIGPIPE options.

Ito Kazumitsu kaz at maczuka.gcd.org
Thu Jan 18 16:00:29 UTC 2007


Hi,

This is to fix the bug #30488.

ChangeLog

2007-01-18  Ito Kazumitsu  <kaz at maczuka.gcd.org>

	* native/jni/native-lib/cpnet.c(SOCKET_NOSIGNAL): Deleted,
	(setsockopt_NOSIGPIPE): New function,
	(cpnet_send): Corrected the option setting to send(),
	(cpnet_sendTo): Corrected the option setting to sendto().

-------------- next part --------------
cvs diff: Diffing classpath/native/jni/native-lib
Index: classpath/native/jni/native-lib/cpnet.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/cpnet.c,v
retrieving revision 1.5
diff -u -r1.5 cpnet.c
--- classpath/native/jni/native-lib/cpnet.c	17 Sep 2006 07:31:43 -0000	1.5
+++ classpath/native/jni/native-lib/cpnet.c	16 Jan 2007 22:03:17 -0000
@@ -55,14 +55,6 @@
 
 #define SOCKET_DEFAULT_TIMEOUT -1 /* milliseconds */
 
-#if defined (HAVE_MSG_NOSIGNAL)
-#define SOCKET_NOSIGNAL MSG_NOSIGNAL
-#elif defined (HAVE_SO_NOSIGPIPE)
-#define SOCKET_NOSIGNAL SO_NOSIGPIPE
-#else
-#error "No suitable flag found to ommit a SIGPIPE on signal errors with send()."
-#endif
-
 static int socketTimeouts[FD_SETSIZE];
 
 static jint waitForWritable(jint fd)
@@ -249,6 +241,15 @@
   return 0;
 }
 
+#if defined (HAVE_MSG_NOSIGNAL)
+#elif defined (HAVE_SO_NOSIGPIPE)
+static int setsockopt_NOSIGPIPE (int fd)
+{
+  int setToTrue = 1;
+  return setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &setToTrue, sizeof(setToTrue));
+}
+#endif
+
 jint cpnet_send (JNIEnv *env UNUSED, jint fd, jbyte *data, jint len, jint *bytes_sent)
 {
   ssize_t ret;
@@ -256,7 +257,17 @@
   if (waitForWritable(fd) < 0)
     return ETIMEDOUT;
 
-  ret = send(fd, data, len, SOCKET_NOSIGNAL);
+#if defined (HAVE_MSG_NOSIGNAL)
+  ret = send(fd, data, len, MSG_NOSIGNAL);
+#elif defined (HAVE_SO_NOSIGPIPE)
+  ret = setsockopt_NOSIGPIPE(fd);
+  if (ret == 0) ret = send(fd, data, len, 0);
+#else
+  /* We want SIGPIPE to be omitted. But this configuration does not have an
+   * option for that.
+   */
+  ret = send(fd, data, len, 0);
+#endif
   if (ret < 0)
     return errno;
 
@@ -272,8 +283,24 @@
   if (waitForWritable(fd) < 0)
     return ETIMEDOUT;
 
-  ret = sendto(fd, data, len, SOCKET_NOSIGNAL, (struct sockaddr *)addr->data,
+#if defined (HAVE_MSG_NOSIGNAL)
+  ret = sendto(fd, data, len, MSG_NOSIGNAL, (struct sockaddr *)addr->data,
+	       addr->len);
+#elif defined (HAVE_SO_NOSIGPIPE)
+  ret = setsockopt_NOSIGPIPE(fd);
+  if (ret == 0)
+  {
+    ret = sendto(fd, data, len, 0, (struct sockaddr *)addr->data,
+	       addr->len);
+  }
+#else
+  /* We want SIGPIPE to be omitted. But this configuration does not have an
+   * option for that.
+   */
+  ret = sendto(fd, data, len, 0, (struct sockaddr *)addr->data,
 	       addr->len);
+#endif
+
   if (ret < 0)
     return errno;
 


More information about the Classpath-patches mailing list