Added CVS id, Detabified, applied c-ares coding-style.
[platform/upstream/c-ares.git] / acinclude.m4
index 2d4aa91..214c005 100644 (file)
@@ -1,3 +1,126 @@
+dnl Check for how to set a socket to non-blocking state. There seems to exist
+dnl four known different ways, with the one used almost everywhere being POSIX
+dnl and XPG3, while the other different ways for different systems (old BSD,
+dnl Windows and Amiga).
+dnl
+dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
+dnl O_NONBLOCK define is found but does not work. This condition is attempted
+dnl to get caught in this script by using an excessive number of #ifdefs...
+dnl
+AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
+[
+  AC_MSG_CHECKING([non-blocking sockets style])
+
+  AC_TRY_COMPILE([
+/* headers for O_NONBLOCK test */
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+],[
+/* try to compile O_NONBLOCK */
+
+#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+# if defined(__SVR4) || defined(__srv4__)
+#  define PLATFORM_SOLARIS
+# else
+#  define PLATFORM_SUNOS4
+# endif
+#endif
+#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
+# define PLATFORM_AIX_V3
+#endif
+
+#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
+#error "O_NONBLOCK does not work on this platform"
+#endif
+  int socket;
+  int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
+],[
+dnl the O_NONBLOCK test was fine
+nonblock="O_NONBLOCK"
+AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
+],[
+dnl the code was bad, try a different program now, test 2
+
+  AC_TRY_COMPILE([
+/* headers for FIONBIO test */
+#include <unistd.h>
+#include <stropts.h>
+],[
+/* FIONBIO source test (old-style unix) */
+ int socket;
+ int flags = ioctl(socket, FIONBIO, &flags);
+],[
+dnl FIONBIO test was good
+nonblock="FIONBIO"
+AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
+],[
+dnl FIONBIO test was also bad
+dnl the code was bad, try a different program now, test 3
+
+  AC_TRY_COMPILE([
+/* headers for ioctlsocket test (cygwin?) */
+#include <windows.h>
+],[
+/* ioctlsocket source code */
+ int socket;
+ unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
+],[
+dnl ioctlsocket test was good
+nonblock="ioctlsocket"
+AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
+],[
+dnl ioctlsocket didnt compile!, go to test 4
+
+  AC_TRY_LINK([
+/* headers for IoctlSocket test (Amiga?) */
+#include <sys/ioctl.h>
+],[
+/* IoctlSocket source code */
+ int socket;
+ int flags = IoctlSocket(socket, FIONBIO, (long)1);
+],[
+dnl ioctlsocket test was good
+nonblock="IoctlSocket"
+AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
+],[
+dnl Ioctlsocket didnt compile, do test 5!
+  AC_TRY_COMPILE([
+/* headers for SO_NONBLOCK test (BeOS) */
+#include <socket.h>
+],[
+/* SO_NONBLOCK source code */
+ long b = 1;
+ int socket;
+ int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
+],[
+dnl the SO_NONBLOCK test was good
+nonblock="SO_NONBLOCK"
+AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
+],[
+dnl test 5 didnt compile!
+nonblock="nada"
+AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
+])
+dnl end of fifth test
+
+])
+dnl end of forth test
+
+])
+dnl end of third test
+
+])
+dnl end of second test
+
+])
+dnl end of non-blocking try-compile test
+  AC_MSG_RESULT($nonblock)
+
+  if test "$nonblock" = "nada"; then
+    AC_MSG_WARN([non-block sockets disabled])
+  fi
+])
 
 dnl We create a function for detecting which compiler we use and then set as
 dnl pendantic compiler options as possible for that particular compiler. The
@@ -146,3 +269,50 @@ AC_DEFUN([CARES_CHECK_CONSTANT], [
 ])
 
 
+dnl This macro determines how many parameters getservbyport_r takes
+AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
+  AC_MSG_CHECKING([how many arguments getservbyport_r takes])
+  AC_TRY_COMPILE(
+    [#include <netdb.h>],
+    [
+      int p1, p5;
+      char *p2, p4[4096];
+      struct servent *p3, *p6;
+      getservbyport_r(p1, p2, p3, p4, p5, &p6);
+    ], ac_func_getservbyport_r=6,
+    [AC_TRY_COMPILE(
+      [#include <netdb.h>],
+      [
+        int p1, p5;
+        char *p2, p4[4096];
+        struct servent *p3;
+        getservbyport_r(p1, p2, p3, p4, p5);
+      ], ac_func_getservbyport_r=5,
+      [AC_TRY_COMPILE(
+        [#include <netdb.h>],
+        [
+          int p1;
+          char *p2;
+          struct servent *p3;
+          struct servent_data p4;
+          getservbyport_r(p1, p2, p3, &p4);
+        ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
+      )]
+    )]
+  )
+if test $ac_func_getservbyport_r != "0" ; then
+  AC_MSG_RESULT($ac_func_getservbyport_r)
+  AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
+  AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to 
+getservbyport_r])
+  if test $ac_func_getservbyport_r = "4" ; then
+   AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to 
+getservbyport_r])
+  else
+   AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
+  fi
+else
+  AC_MSG_RESULT([not found])
+fi
+])
+