Date: Tuesday, January 10, 2006 @ 11:25:13
  Author: gilles
    Path: /cvsroot/carob/carob/include

Modified: SystemDependantDefs.hpp (1.1 -> 1.2)

Made socket options more 'transparent' trying to automatically define it 
depending on system defs, throwing an error if we cannot get rid of sigpipes


-------------------------+
 SystemDependantDefs.hpp |   52 ++++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 17 deletions(-)


Index: carob/include/SystemDependantDefs.hpp
diff -u carob/include/SystemDependantDefs.hpp:1.1 
carob/include/SystemDependantDefs.hpp:1.2
--- carob/include/SystemDependantDefs.hpp:1.1   Mon Jan  9 18:37:52 2006
+++ carob/include/SystemDependantDefs.hpp       Tue Jan 10 11:25:13 2006
@@ -36,26 +36,44 @@
 const int SOCKET_CREATION_DOMAIN          = PF_INET;
 // const int SOCKET_CREATION_DOMAIN          = PF_INET6;  //for IPv6
 
-////////////////////////////
-// Config: *nix (default) //
-////////////////////////////
+/**
+ * In Carob, we want to recover from closed socket errors. So we will tell the
+ * system *not* to send sigpipes when writing on a closed socket.
+ * Solutions to this are system dependant:
+ * -> *nixes have MSG_NOSIGNAL flag for send() function
+ * -> MaxOS/X >= 10.1 and FreeBSD have a socket option SO_NOSIGPIPE
+ * -> ...
+ * 
+ * We try to set these options automatically. If the system do have the
+ * following flags, we will use it in this order:
+ * 1)SO_NOSIGPIPE
+ * 2)MSG_NOSIGNAL
+ * 3)...
+ * N) an error will be throw at compile time
+ */
 
-/** Socket options at socket level. Set just after socket creation. */
-const int SOCKET_SOL_OPTIONS              = SO_REUSEADDR;
-/** Send options. *nixes systems can use MSG_NOSIGNAL to avoid sigpipe when
-    socket is written/read while closed */
-const int SOCKET_SEND_FLAGS               = MSG_NOSIGNAL;
-
-///////////////////////////////////////////////////
-// Config: MacOS/X (ok?) - FreeBSD (to be tested) //
-///////////////////////////////////////////////////
-// #ifndef SO_NOSIGPIPE
-// Not present in 10.1.x kernel/headers
+// For MacOS/X 10.1.x, define this (undocumented/undeclared flag)
 // #define SO_NOSIGPIPE 0x1022
-// #endif
 
-// const int SOCKET_SOL_OPTIONS              = SO_REUSEADDR|SO_NOSIGPIPE;
-// const int SOCKET_SEND_FLAGS               = 0;
+#if !defined SO_NOSIGPIPE && !defined MSG_NOSIGNAL
+#error Cannot avoid sigpipe from beeing raised!
+#endif
+
+/**
+ * Socket options at socket level. Set just after socket creation.
+ */
+const int SOCKET_SOL_OPTIONS              = SO_REUSEADDR
+#ifdef SO_NOSIGPIPE //mac
+|SO_NOSIGPIPE
+#endif
+;
+
+/** Write options. Flag given for each send() on the socket */
+const int SOCKET_SEND_FLAGS               = 0
+#ifndef SO_NOSIGPIPE //*nix
+|MSG_NOSIGNAL
+#endif
+;
 
 }; //anonymous namespace
 #endif /*SYSTEMDEPENDANTDEFS_HPP_*/

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to