Test for a working SO_SNDTIMEO and SO_RCVTIMEO during configure
[awesomized/libmemcached] / config / setsockopt.m4
1 dnl ---------------------------------------------------------------------------
2 dnl Macro: SETSOCKOPT_TEST
3 dnl ---------------------------------------------------------------------------
4 AC_LANG(C)
5 AC_RUN_IFELSE([
6 AC_LANG_PROGRAM([
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <time.h>
10 #include <errno.h>
11 ], [
12 int sock = socket(AF_INET, SOCK_STREAM, 0);
13 struct timeval waittime;
14
15 waittime.tv_sec= 0;
16 waittime.tv_usec= 500;
17
18 if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
19 &waittime, (socklen_t)sizeof(struct timeval)) == -1) {
20 if (errno == ENOPROTOOPT) {
21 return 1;
22 }
23 }
24 return 0;
25 ])
26 ], AC_DEFINE(HAVE_SNDTIMEO, 1, [Define to 1 if you have a working SO_SNDTIMEO]))
27
28 AC_RUN_IFELSE([
29 AC_LANG_PROGRAM([
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <time.h>
33 #include <errno.h>
34 ], [
35 int sock = socket(AF_INET, SOCK_STREAM, 0);
36 struct timeval waittime;
37
38 waittime.tv_sec= 0;
39 waittime.tv_usec= 500;
40
41 if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
42 &waittime, (socklen_t)sizeof(struct timeval)) == -1) {
43 if (errno == ENOPROTOOPT) {
44 return 1;
45 }
46 }
47 return 0;
48 ])
49 ], AC_DEFINE(HAVE_RCVTIMEO, 1, [Define to 1 if you have a working SO_RCVTIMEO]))
50
51 dnl ---------------------------------------------------------------------------
52 dnl End Macro: SETSOCKOPT_TEST
53 dnl ---------------------------------------------------------------------------