Date: Monday, December 4, 2006 @ 16:25:02
Author: marc
Path: /cvsroot/carob/carob
Modified: include/SystemDependantDefs.hpp (1.5 -> 1.6) src/JavaSocket.cpp
(1.59 -> 1.60)
Portability fixes: added missing #includes <sys/socket.h>. "make checkheaders"
now succeeds.
Finally rewrote SystemDependantDefs.hpp in a more flexible way. Needs to be
tested again on MacOSX and MINGW.
---------------------------------+
include/SystemDependantDefs.hpp | 47 +++++++++++++++++++++++++++++++-------
src/JavaSocket.cpp | 4 ++-
2 files changed, 42 insertions(+), 9 deletions(-)
Index: carob/include/SystemDependantDefs.hpp
diff -u carob/include/SystemDependantDefs.hpp:1.5
carob/include/SystemDependantDefs.hpp:1.6
--- carob/include/SystemDependantDefs.hpp:1.5 Tue Nov 28 17:07:55 2006
+++ carob/include/SystemDependantDefs.hpp Mon Dec 4 16:25:02 2006
@@ -16,12 +16,12 @@
* limitations under the License.
*
* Initial developer(s): Gilles Rayrat
- * Contributor(s):
+ * Contributor(s): Marc Herbert
*/
#ifndef SYSTEMDEPENDANTDEFS_HPP_
#define SYSTEMDEPENDANTDEFS_HPP_
-//TODO: Add #ifdefs for each supported archi
+// http://predef.sourceforge.net/ is interesting but quite outdated
namespace
{
@@ -33,16 +33,47 @@
* 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
+ * -> *nixes have MSG_NOSIGNAL flag for send(2/3) function
* -> MaxOS/X >= 10.1 and FreeBSD have no MSG_NOSIGNAL but a socket option
SO_NOSIGPIPE
+ * (check socket(7) and setsockopt(2))
* -> ...
*/
-/** Write options. Flag given for each send() on the socket */
-const int SOCKET_SEND_FLAGS = 0
-#if !defined SO_NOSIGPIPE && !defined __MINGW32__ //*nix
-|MSG_NOSIGNAL
+
+// --- MINGW32 ---
+
+// bare Windows has no signals anyway, let's do nothing (not even
+// including sys/socket.h)
+#if defined(__MINGW32__)
+# define MSG_NOSIGNAL 0
+# define CAROB_USE_SO_NOSIGPIPE 0
+
+// --- Mac OSX ----
+
+// no MSG_NOSIGNAL available but SO_NOSIGPIPE is
+//
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/setsockopt.2.html
+#elif defined(__APPLE__) && defined(__MACH__) // TODO: add FreeBSD & co here?
+ //
http://developer.apple.com/technotes/tn2002/tn2071.html#Section10
+# include <sys/socket.h>
+# define MSG_NOSIGNAL 0 // provide dummy value
+# define CAROB_USE_SO_NOSIGPIPE 1
+
+// --- Default case / fallback --- (OK for most unices?)
+
+// if MSG_NOSIGNAL is available, then we can safely skip the
setsockopt(SO_NOSIGPIPE) call
+#else
+# include <sys/socket.h>
+# if defined(MSG_NOSIGNAL)
+# define CAROB_USE_SO_NOSIGPIPE 0
+# else
+# error "Could not find either MSG_NOSIGNAL nor SO_NOSIGPIPE"
+ // Solaris provides neither and DOES sends a SIGPIPE (see
setsockopt(3SOCKET)
+ // We have a problem here...
+# endif
#endif
-;
+
+
+/** Write options. Flag given for each send() on the socket */
+const int SOCKET_SEND_FLAGS = MSG_NOSIGNAL;
}; //anonymous namespace
#endif /*SYSTEMDEPENDANTDEFS_HPP_*/
Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.59 carob/src/JavaSocket.cpp:1.60
--- carob/src/JavaSocket.cpp:1.59 Mon Dec 4 15:13:48 2006
+++ carob/src/JavaSocket.cpp Mon Dec 4 16:25:02 2006
@@ -28,6 +28,8 @@
#include <ws2tcpip.h>
#define __BYTE_ORDER BYTE_ORDER
#else
+ #include <sys/types.h> // socket(), send(), etc.
+ #include <sys/socket.h> // "
#include <netdb.h> // getaddrinfo() etc.
#include <netinet/tcp.h> // TCP_NODELAY etc.
#include <unistd.h> // sleep()
@@ -87,7 +89,7 @@
int opt_value = 1;
if (setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char*>(&opt_value), sizeof opt_value) == -1
-#if (defined(__MACH__) && defined(__APPLE__)) // quick & dirty fix for MacOSX
+#if CAROB_USE_SO_NOSIGPIPE
|| setsockopt(socket_fd, SOL_SOCKET, SO_NOSIGPIPE,
reinterpret_cast<char*>(&opt_value), sizeof (opt_value) ==
-1)
#endif
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits