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