[Xorp-cvs] SF.net SVN: xorp:[11553] trunk/xorp/libcomm

bms_fbsd at users.sourceforge.net bms_fbsd at users.sourceforge.net
Tue Sep 22 09:40:52 PDT 2009


Revision: 11553
          http://xorp.svn.sourceforge.net/xorp/?rev=11553&view=rev
Author:   bms_fbsd
Date:     2009-09-22 16:40:51 +0000 (Tue, 22 Sep 2009)

Log Message:
-----------
Add a SO_NOSIGPIPE wrapper to libcomm, for use on the BSDs.
On Linux, we should be using MSG_NOSIGNAL where possible (already).

Disabling SIGPIPE signal disposition in the I/O paths is measurably
faster (there's no tedious detour through the kernel signal code),
and simplifies C++ error handling.

Modified Paths:
--------------
    trunk/xorp/libcomm/comm_api.h
    trunk/xorp/libcomm/comm_sock.c
    trunk/xorp/libcomm/comm_user.c

Modified: trunk/xorp/libcomm/comm_api.h
===================================================================
--- trunk/xorp/libcomm/comm_api.h	2009-09-21 22:53:57 UTC (rev 11552)
+++ trunk/xorp/libcomm/comm_api.h	2009-09-22 16:40:51 UTC (rev 11553)
@@ -174,6 +174,13 @@
 extern int	comm_keepalive_present(void);
 
 /**
+ * Test whether the underlying system has SO_NOSIGPIPE support.
+ *
+ * @return XORP_OK on success, otherwise XORP_ERROR.
+ */
+extern int	comm_nosigpipe_present(void);
+
+/**
  * Test whether the underlying system has IP_ONESBCAST support.
  *
  * @return XORP_OK on success, otherwise XORP_ERROR.
@@ -834,6 +841,15 @@
 extern int	comm_set_keepalive(xsock_t sock, int val);
 
 /**
+ * Set/reset the SO_NOSIGPIPE option on a socket.
+ *
+ * @param sock the socket whose option we want to set/reset.
+ * @param val if non-zero, the option will be set, otherwise will be reset.
+ * @return XORP_OK on success, otherwise XORP_ERROR.
+ */
+extern int	comm_set_nosigpipe(xsock_t sock, int val);
+
+/**
  * Set/reset the SO_REUSEADDR option on a socket.
  *
  * Note: If the OS doesn't support this option, then XORP_ERROR is returned.

Modified: trunk/xorp/libcomm/comm_sock.c
===================================================================
--- trunk/xorp/libcomm/comm_sock.c	2009-09-21 22:53:57 UTC (rev 11552)
+++ trunk/xorp/libcomm/comm_sock.c	2009-09-22 16:40:51 UTC (rev 11553)
@@ -901,6 +901,29 @@
 }
 
 int
+comm_set_nosigpipe(xsock_t sock, int val)
+{
+#ifdef SO_NOSIGPIPE
+    if (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE,
+		   XORP_SOCKOPT_CAST(&val), sizeof(val)) < 0) {
+	_comm_set_serrno();
+	XLOG_ERROR("Error %s SO_NOSIGPIPE on socket %d: %s",
+		   (val)? "set": "reset",  sock,
+		   comm_get_error_str(comm_get_last_error()));
+	return (XORP_ERROR);
+    }
+
+    return (XORP_OK);
+#else /* ! SO_NOSIGPIPE */
+    UNUSED(sock);
+    UNUSED(val);
+    XLOG_WARNING("SO_NOSIGPIPE Undefined!");
+
+    return (XORP_ERROR);
+#endif /* ! SO_NOSIGPIPE */
+}
+
+int
 comm_set_reuseaddr(xsock_t sock, int val)
 {
 #ifdef SO_REUSEADDR

Modified: trunk/xorp/libcomm/comm_user.c
===================================================================
--- trunk/xorp/libcomm/comm_user.c	2009-09-21 22:53:57 UTC (rev 11552)
+++ trunk/xorp/libcomm/comm_user.c	2009-09-22 16:40:51 UTC (rev 11553)
@@ -173,6 +173,16 @@
 }
 
 int
+comm_nosigpipe_present(void)
+{
+#ifdef SO_NOSIGPIPE
+    return XORP_OK;
+#else
+    return XORP_ERROR;
+#endif
+}
+
+int
 comm_onesbcast_present(void)
 {
 #ifdef IP_ONESBCAST


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Xorp-cvs mailing list