From: Trond Norbye Date: Tue, 6 Jan 2009 14:46:41 +0000 (+0100) Subject: Test for a working SO_SNDTIMEO and SO_RCVTIMEO during configure X-Git-Tag: 0.26~26^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ceab093459cec94d6d40f48ade93efa3a74c06a1;p=m6w6%2Flibmemcached Test for a working SO_SNDTIMEO and SO_RCVTIMEO during configure --- diff --git a/config/setsockopt.m4 b/config/setsockopt.m4 new file mode 100644 index 00000000..f1115d3a --- /dev/null +++ b/config/setsockopt.m4 @@ -0,0 +1,53 @@ +dnl --------------------------------------------------------------------------- +dnl Macro: SETSOCKOPT_TEST +dnl --------------------------------------------------------------------------- +AC_LANG(C) +AC_RUN_IFELSE([ + AC_LANG_PROGRAM([ +#include +#include +#include +#include + ], [ + int sock = socket(AF_INET, SOCK_STREAM, 0); + struct timeval waittime; + + waittime.tv_sec= 0; + waittime.tv_usec= 500; + + if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, + &waittime, (socklen_t)sizeof(struct timeval)) == -1) { + if (errno == ENOPROTOOPT) { + return 1; + } + } + return 0; + ]) + ], AC_DEFINE(HAVE_SNDTIMEO, 1, [Define to 1 if you have a working SO_SNDTIMEO])) + +AC_RUN_IFELSE([ + AC_LANG_PROGRAM([ +#include +#include +#include +#include + ], [ + int sock = socket(AF_INET, SOCK_STREAM, 0); + struct timeval waittime; + + waittime.tv_sec= 0; + waittime.tv_usec= 500; + + if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, + &waittime, (socklen_t)sizeof(struct timeval)) == -1) { + if (errno == ENOPROTOOPT) { + return 1; + } + } + return 0; + ]) + ], AC_DEFINE(HAVE_RCVTIMEO, 1, [Define to 1 if you have a working SO_RCVTIMEO])) + +dnl --------------------------------------------------------------------------- +dnl End Macro: SETSOCKOPT_TEST +dnl --------------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index 621ed0df..36f1162e 100644 --- a/configure.ac +++ b/configure.ac @@ -84,4 +84,7 @@ AC_TYPE_SIZE_T AC_SEARCH_LIBS(getopt_long, gnugetopt) AC_SEARCH_LIBS(socket, socket) AC_SEARCH_LIBS(gethostbyname, nsl) + +sinclude(config/setsockopt.m4) + AC_OUTPUT(Makefile clients/Makefile tests/Makefile docs/Makefile libmemcached/Makefile support/Makefile support/libmemcached.pc support/libmemcached.spec) diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index c5157629..ca354200 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -51,7 +51,7 @@ static memcached_return set_socket_options(memcached_server_st *ptr) if (ptr->type == MEMCACHED_CONNECTION_UDP) return MEMCACHED_SUCCESS; -#ifndef __sun +#ifdef HAVE_SNDTIMEO if (ptr->root->snd_timeout) { int error; @@ -64,7 +64,9 @@ static memcached_return set_socket_options(memcached_server_st *ptr) &waittime, (socklen_t)sizeof(struct timeval)); WATCHPOINT_ASSERT(error == 0); } +#endif +#ifdef HAVE_RCVTIMEO if (ptr->root->rcv_timeout) { int error;