From b9bd7be25730b33f1cc91bb171402b548af79d5b Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Tue, 1 Mar 2011 08:08:00 +0100 Subject: [PATCH] Detect the availability of MSG_NOSIGNAL/MSG_DONTWAIT --- configure.ac | 10 +++++++++ libmemcached/io.c | 4 ---- m4/socket_send_flags.m4 | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 m4/socket_send_flags.m4 diff --git a/configure.ac b/configure.ac index c7d63f87..07927c92 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,15 @@ AH_BOTTOM([ #define closesocket(a) close(a) #define get_socket_errno() errno #endif + +#ifndef HAVE_MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + +#ifndef HAVE_MSG_DONTWAIT +#define MSG_DONTWAIT 0 +#endif + #endif ]) @@ -144,6 +153,7 @@ AS_IF(test "x$ac_cv_header_winsock2_h" = "xyes", AM_CXXFLAGS="$AM_CXXFLAGS $NO_WERROR" ]) DETECT_EAGAIN +SOCKET_SEND_FLAGS AC_CONFIG_FILES([ Makefile diff --git a/libmemcached/io.c b/libmemcached/io.c index d3c5e4b6..dedcdaf9 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -619,11 +619,7 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, increment_udp_message_id(ptr); WATCHPOINT_ASSERT(ptr->fd != -1); -#if defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__) - sent_length= send(ptr->fd, local_write_ptr, write_length, 0); -#else sent_length= send(ptr->fd, local_write_ptr, write_length, MSG_NOSIGNAL|MSG_DONTWAIT); -#endif if (sent_length == SOCKET_ERROR) { ptr->cached_errno= get_socket_errno(); diff --git a/m4/socket_send_flags.m4 b/m4/socket_send_flags.m4 new file mode 100644 index 00000000..8251980d --- /dev/null +++ b/m4/socket_send_flags.m4 @@ -0,0 +1,49 @@ +dnl Copyright (C) 2011 Trond Norbye +dnl This file is free software; Trond Norbye +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl --------------------------------------------------------------------------- +dnl Macro: SOCKET_SEND_FLAGS +dnl --------------------------------------------------------------------------- + +AC_DEFUN([SOCKET_SEND_FLAGS], +[ + AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [ + AC_LANG_PUSH([C]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -I${srcdir}" + AC_TRY_LINK([ +#include + ], [ +int flags= MSG_NOSIGNAL; + ], + [ ac_cv_msg_nosignal=yes ], + [ ac_cv_msg_nosignal=no ]) + CFLAGS="$save_CFLAGS" + AC_LANG_POP + ]) + + AC_CACHE_CHECK([for MSG_DONTWAIT], [ac_cv_msg_dontwait], [ + AC_LANG_PUSH([C]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -I${srcdir}" + AC_TRY_LINK([ +#include + ], [ +int flags= MSG_DONTWAIT; + ], + [ ac_cv_msg_dontwait=yes ], + [ ac_cv_msg_dontwait=no ]) + CFLAGS="$save_CFLAGS" + AC_LANG_POP + ]) + + AS_IF([test "x$ac_cv_msg_nosignal" = "xyes"],[ + AC_DEFINE(HAVE_MSG_NOSIGNAL, 1, [Define to 1 if you have a MSG_NOSIGNAL])]) + AS_IF([test "x$ac_cv_msg_dontwait" = "xyes"],[ + AC_DEFINE(HAVE_MSG_DONTWAIT, 1, [Define to 1 if you have a MSG_DONTWAIT])]) +]) + +dnl --------------------------------------------------------------------------- +dnl End Macro: SOCKET_SEND_FLAGS +dnl ---------------------------------------------------------------------------