From 8229c3fa752c7fca3760245da4e23ba67acdee33 Mon Sep 17 00:00:00 2001 From: Rob Arnold Date: Fri, 8 Jul 2011 17:22:48 -0700 Subject: [PATCH] Update libuv to revision ee599ec1141cc48f895de1f9d148033babdf9c2a --- mk/rt.mk | 4 +- src/rt/libuv/.gitignore | 15 + src/rt/libuv/AUTHORS | 5 + src/rt/libuv/LIBUV_REVISION | 2 +- src/rt/libuv/LICENSE | 3 + src/rt/libuv/config-mingw.mk | 38 +- src/rt/libuv/config-unix.mk | 92 +- src/rt/libuv/{ => doc}/desired-api.md | 0 src/rt/libuv/include/ares.h | 582 ++ src/rt/libuv/include/ares_version.h | 24 + src/rt/libuv/include/eio.h | 356 + src/rt/libuv/{ev => include}/ev.h | 4 +- src/rt/libuv/{ => include}/ngx-queue.h | 0 src/rt/libuv/{ => include}/tree.h | 0 src/rt/libuv/{ => include}/uv-unix.h | 40 +- src/rt/libuv/{ => include}/uv-win.h | 52 +- src/rt/libuv/{ => include}/uv.h | 200 +- src/rt/libuv/msvs/c-ares.vcxproj | 179 + src/rt/libuv/msvs/libuv-benchmark.vcxproj | 19 +- src/rt/libuv/msvs/libuv-test.vcxproj | 20 +- src/rt/libuv/msvs/libuv.sln | 10 + src/rt/libuv/msvs/libuv.vcxproj | 45 +- src/rt/libuv/src/ares/AUTHORS | 37 + src/rt/libuv/src/ares/CHANGES | 1198 +++ src/rt/libuv/src/ares/CMakeLists.txt | 22 + src/rt/libuv/src/ares/NEWS | 21 + src/rt/libuv/src/ares/README | 60 + src/rt/libuv/src/ares/README.cares | 13 + src/rt/libuv/src/ares/README.msvc | 118 + src/rt/libuv/src/ares/README.node | 21 + src/rt/libuv/src/ares/RELEASE-NOTES | 25 + src/rt/libuv/src/ares/TODO | 23 + src/rt/libuv/src/ares/ares__close_sockets.c | 66 + src/rt/libuv/src/ares/ares__get_hostent.c | 263 + src/rt/libuv/src/ares/ares__read_line.c | 71 + src/rt/libuv/src/ares/ares__timeval.c | 111 + src/rt/libuv/src/ares/ares_cancel.c | 63 + src/rt/libuv/src/ares/ares_data.c | 190 + src/rt/libuv/src/ares/ares_data.h | 65 + src/rt/libuv/src/ares/ares_destroy.c | 105 + src/rt/libuv/src/ares/ares_dns.h | 90 + src/rt/libuv/src/ares/ares_expand_name.c | 193 + src/rt/libuv/src/ares/ares_expand_string.c | 75 + src/rt/libuv/src/ares/ares_fds.c | 62 + src/rt/libuv/src/ares/ares_free_hostent.c | 39 + src/rt/libuv/src/ares/ares_free_string.c | 25 + src/rt/libuv/src/ares/ares_gethostbyaddr.c | 292 + src/rt/libuv/src/ares/ares_gethostbyname.c | 515 + src/rt/libuv/src/ares/ares_getnameinfo.c | 426 + src/rt/libuv/src/ares/ares_getopt.c | 122 + src/rt/libuv/src/ares/ares_getopt.h | 53 + src/rt/libuv/src/ares/ares_getsock.c | 72 + src/rt/libuv/src/ares/ares_init.c | 1665 +++ src/rt/libuv/src/ares/ares_ipv6.h | 78 + src/rt/libuv/src/ares/ares_library_init.c | 132 + src/rt/libuv/src/ares/ares_library_init.h | 39 + src/rt/libuv/src/ares/ares_llist.c | 86 + src/rt/libuv/src/ares/ares_llist.h | 42 + src/rt/libuv/src/ares/ares_mkquery.c | 195 + src/rt/libuv/src/ares/ares_nowarn.c | 59 + src/rt/libuv/src/ares/ares_nowarn.h | 24 + src/rt/libuv/src/ares/ares_options.c | 253 + src/rt/libuv/src/ares/ares_parse_a_reply.c | 258 + src/rt/libuv/src/ares/ares_parse_aaaa_reply.c | 256 + src/rt/libuv/src/ares/ares_parse_mx_reply.c | 170 + src/rt/libuv/src/ares/ares_parse_ns_reply.c | 182 + src/rt/libuv/src/ares/ares_parse_ptr_reply.c | 208 + src/rt/libuv/src/ares/ares_parse_srv_reply.c | 179 + src/rt/libuv/src/ares/ares_parse_txt_reply.c | 201 + src/rt/libuv/src/ares/ares_private.h | 351 + src/rt/libuv/src/ares/ares_process.c | 1296 +++ src/rt/libuv/src/ares/ares_query.c | 183 + src/rt/libuv/src/ares/ares_rules.h | 144 + src/rt/libuv/src/ares/ares_search.c | 322 + src/rt/libuv/src/ares/ares_send.c | 134 + src/rt/libuv/src/ares/ares_setup.h | 191 + src/rt/libuv/src/ares/ares_strcasecmp.c | 66 + src/rt/libuv/src/ares/ares_strcasecmp.h | 30 + src/rt/libuv/src/ares/ares_strdup.c | 42 + src/rt/libuv/src/ares/ares_strdup.h | 26 + src/rt/libuv/src/ares/ares_strerror.c | 56 + src/rt/libuv/src/ares/ares_timeout.c | 80 + src/rt/libuv/src/ares/ares_version.c | 11 + src/rt/libuv/src/ares/ares_writev.c | 79 + src/rt/libuv/src/ares/ares_writev.h | 36 + src/rt/libuv/src/ares/bitncmp.c | 59 + src/rt/libuv/src/ares/bitncmp.h | 26 + .../src/ares/config_cygwin/ares_config.h | 510 + .../src/ares/config_darwin/ares_config.h | 510 + .../src/ares/config_freebsd/ares_config.h | 510 + .../libuv/src/ares/config_linux/ares_config.h | 510 + .../src/ares/config_openbsd/ares_config.h | 510 + .../libuv/src/ares/config_sunos/ares_config.h | 510 + .../libuv/src/ares/config_win32/ares_config.h | 369 + src/rt/libuv/src/ares/get_ver.awk | 35 + src/rt/libuv/src/ares/inet_net_pton.c | 450 + src/rt/libuv/src/ares/inet_net_pton.h | 31 + src/rt/libuv/src/ares/inet_ntop.c | 232 + src/rt/libuv/src/ares/inet_ntop.h | 26 + src/rt/libuv/src/ares/nameser.h | 193 + src/rt/libuv/src/ares/setup_once.h | 488 + src/rt/libuv/src/ares/windows_port.c | 22 + src/rt/libuv/src/eio/Changes | 35 + src/rt/libuv/src/eio/LICENSE | 36 + src/rt/libuv/src/eio/Makefile.am | 15 + src/rt/libuv/{ev => src/eio}/aclocal.m4 | 0 src/rt/libuv/src/eio/autogen.sh | 5 + src/rt/libuv/src/eio/config.h.in | 86 + src/rt/libuv/src/eio/config_cygwin.h | 77 + src/rt/libuv/src/eio/config_darwin.h | 82 + src/rt/libuv/src/eio/config_freebsd.h | 78 + src/rt/libuv/src/eio/config_linux.h | 89 + src/rt/libuv/src/eio/config_sunos.h | 81 + src/rt/libuv/src/eio/configure.ac | 22 + src/rt/libuv/src/eio/demo.c | 194 + src/rt/libuv/src/eio/eio.3 | 3428 +++++++ src/rt/libuv/src/eio/eio.c | 2133 ++++ src/rt/libuv/src/eio/eio.pod | 303 + src/rt/libuv/src/eio/libeio.m4 | 156 + src/rt/libuv/src/eio/xthread.h | 161 + src/rt/libuv/{ => src}/ev/Changes | 0 src/rt/libuv/{ => src}/ev/LICENSE | 0 src/rt/libuv/{ => src}/ev/Makefile.am | 0 src/rt/libuv/{ => src}/ev/Makefile.in | 0 src/rt/libuv/{ => src}/ev/README | 0 src/rt/libuv/src/ev/aclocal.m4 | 8957 +++++++++++++++++ src/rt/libuv/{ => src}/ev/autogen.sh | 0 src/rt/libuv/{ => src}/ev/config.guess | 0 src/rt/libuv/{ => src}/ev/config.h.in | 0 src/rt/libuv/{ => src}/ev/config.sub | 0 src/rt/libuv/src/ev/config_cygwin.h | 123 + src/rt/libuv/src/ev/config_darwin.h | 122 + src/rt/libuv/src/ev/config_freebsd.h | 120 + src/rt/libuv/src/ev/config_linux.h | 130 + src/rt/libuv/src/ev/config_sunos.h | 122 + src/rt/libuv/{ => src}/ev/configure | 0 src/rt/libuv/{ => src}/ev/configure.ac | 0 src/rt/libuv/{ => src}/ev/depcomp | 0 src/rt/libuv/{ => src}/ev/ev++.h | 0 src/rt/libuv/{ => src}/ev/ev.3 | 0 src/rt/libuv/{ => src}/ev/ev.c | 0 src/rt/libuv/{ => src}/ev/ev.pod | 0 src/rt/libuv/{ => src}/ev/ev_epoll.c | 0 src/rt/libuv/{ => src}/ev/ev_kqueue.c | 0 src/rt/libuv/{ => src}/ev/ev_poll.c | 0 src/rt/libuv/{ => src}/ev/ev_port.c | 0 src/rt/libuv/{ => src}/ev/ev_select.c | 0 src/rt/libuv/{ => src}/ev/ev_vars.h | 0 src/rt/libuv/{ => src}/ev/ev_win32.c | 0 src/rt/libuv/{ => src}/ev/ev_wrap.h | 0 src/rt/libuv/{ => src}/ev/event.c | 0 src/rt/libuv/{ => src}/ev/event.h | 0 src/rt/libuv/{ => src}/ev/install-sh | 0 src/rt/libuv/{ => src}/ev/libev.m4 | 0 src/rt/libuv/{ => src}/ev/ltmain.sh | 0 src/rt/libuv/{ => src}/ev/missing | 0 src/rt/libuv/{ => src}/ev/mkinstalldirs | 0 src/rt/libuv/{ => src}/uv-common.c | 84 +- src/rt/libuv/src/uv-common.h | 51 + src/rt/libuv/src/uv-cygwin.c | 52 + src/rt/libuv/src/uv-darwin.c | 64 + src/rt/libuv/src/uv-eio.c | 113 + src/rt/libuv/src/uv-eio.h | 13 + src/rt/libuv/src/uv-freebsd.c | 49 + src/rt/libuv/src/uv-linux.c | 55 + src/rt/libuv/src/uv-sunos.c | 60 + src/rt/libuv/{ => src}/uv-unix.c | 587 +- src/rt/libuv/{ => src}/uv-win.c | 1205 ++- src/rt/libuv/test/benchmark-ares.c | 116 + src/rt/libuv/test/benchmark-getaddrinfo.c | 92 + src/rt/libuv/test/benchmark-list.h | 8 + src/rt/libuv/test/benchmark-ping-pongs.c | 12 +- src/rt/libuv/test/benchmark-pump.c | 32 +- src/rt/libuv/test/benchmark-sizes.c | 16 +- src/rt/libuv/test/dns-server.c | 325 + src/rt/libuv/test/echo-server.c | 60 +- src/rt/libuv/test/runner-unix.c | 4 +- src/rt/libuv/test/test-async.c | 14 +- src/rt/libuv/test/test-bind-error.c | 37 +- src/rt/libuv/test/test-bind6-error.c | 164 + src/rt/libuv/test/test-callback-stack.c | 28 +- src/rt/libuv/test/test-connection-fail.c | 12 +- src/rt/libuv/test/test-delayed-accept.c | 37 +- src/rt/libuv/test/test-get-currentexe.c | 10 +- src/rt/libuv/test/test-getaddrinfo.c | 110 + src/rt/libuv/test/test-gethostbyname.c | 192 + src/rt/libuv/test/test-hrtime.c | 54 + src/rt/libuv/test/test-list.h | 34 +- src/rt/libuv/test/test-loop-handles.c | 26 +- src/rt/libuv/test/test-ping-pong.c | 52 +- src/rt/libuv/test/test-shutdown-eof.c | 32 +- src/rt/libuv/test/test-tcp-writealot.c | 18 +- src/rt/libuv/test/test-timer-again.c | 16 +- src/rt/libuv/test/test-timer.c | 12 +- src/rt/rust_uv.cpp | 30 +- 195 files changed, 37891 insertions(+), 731 deletions(-) rename src/rt/libuv/{ => doc}/desired-api.md (100%) create mode 100644 src/rt/libuv/include/ares.h create mode 100644 src/rt/libuv/include/ares_version.h create mode 100644 src/rt/libuv/include/eio.h rename src/rt/libuv/{ev => include}/ev.h (99%) rename src/rt/libuv/{ => include}/ngx-queue.h (100%) rename src/rt/libuv/{ => include}/tree.h (100%) rename src/rt/libuv/{ => include}/uv-unix.h (77%) rename src/rt/libuv/{ => include}/uv-win.h (73%) rename src/rt/libuv/{ => include}/uv.h (65%) create mode 100644 src/rt/libuv/msvs/c-ares.vcxproj create mode 100644 src/rt/libuv/src/ares/AUTHORS create mode 100644 src/rt/libuv/src/ares/CHANGES create mode 100644 src/rt/libuv/src/ares/CMakeLists.txt create mode 100644 src/rt/libuv/src/ares/NEWS create mode 100644 src/rt/libuv/src/ares/README create mode 100644 src/rt/libuv/src/ares/README.cares create mode 100644 src/rt/libuv/src/ares/README.msvc create mode 100644 src/rt/libuv/src/ares/README.node create mode 100644 src/rt/libuv/src/ares/RELEASE-NOTES create mode 100644 src/rt/libuv/src/ares/TODO create mode 100644 src/rt/libuv/src/ares/ares__close_sockets.c create mode 100644 src/rt/libuv/src/ares/ares__get_hostent.c create mode 100644 src/rt/libuv/src/ares/ares__read_line.c create mode 100644 src/rt/libuv/src/ares/ares__timeval.c create mode 100644 src/rt/libuv/src/ares/ares_cancel.c create mode 100644 src/rt/libuv/src/ares/ares_data.c create mode 100644 src/rt/libuv/src/ares/ares_data.h create mode 100644 src/rt/libuv/src/ares/ares_destroy.c create mode 100644 src/rt/libuv/src/ares/ares_dns.h create mode 100644 src/rt/libuv/src/ares/ares_expand_name.c create mode 100644 src/rt/libuv/src/ares/ares_expand_string.c create mode 100644 src/rt/libuv/src/ares/ares_fds.c create mode 100644 src/rt/libuv/src/ares/ares_free_hostent.c create mode 100644 src/rt/libuv/src/ares/ares_free_string.c create mode 100644 src/rt/libuv/src/ares/ares_gethostbyaddr.c create mode 100644 src/rt/libuv/src/ares/ares_gethostbyname.c create mode 100644 src/rt/libuv/src/ares/ares_getnameinfo.c create mode 100644 src/rt/libuv/src/ares/ares_getopt.c create mode 100644 src/rt/libuv/src/ares/ares_getopt.h create mode 100644 src/rt/libuv/src/ares/ares_getsock.c create mode 100644 src/rt/libuv/src/ares/ares_init.c create mode 100644 src/rt/libuv/src/ares/ares_ipv6.h create mode 100644 src/rt/libuv/src/ares/ares_library_init.c create mode 100644 src/rt/libuv/src/ares/ares_library_init.h create mode 100644 src/rt/libuv/src/ares/ares_llist.c create mode 100644 src/rt/libuv/src/ares/ares_llist.h create mode 100644 src/rt/libuv/src/ares/ares_mkquery.c create mode 100644 src/rt/libuv/src/ares/ares_nowarn.c create mode 100644 src/rt/libuv/src/ares/ares_nowarn.h create mode 100644 src/rt/libuv/src/ares/ares_options.c create mode 100644 src/rt/libuv/src/ares/ares_parse_a_reply.c create mode 100644 src/rt/libuv/src/ares/ares_parse_aaaa_reply.c create mode 100644 src/rt/libuv/src/ares/ares_parse_mx_reply.c create mode 100644 src/rt/libuv/src/ares/ares_parse_ns_reply.c create mode 100644 src/rt/libuv/src/ares/ares_parse_ptr_reply.c create mode 100644 src/rt/libuv/src/ares/ares_parse_srv_reply.c create mode 100644 src/rt/libuv/src/ares/ares_parse_txt_reply.c create mode 100644 src/rt/libuv/src/ares/ares_private.h create mode 100644 src/rt/libuv/src/ares/ares_process.c create mode 100644 src/rt/libuv/src/ares/ares_query.c create mode 100644 src/rt/libuv/src/ares/ares_rules.h create mode 100644 src/rt/libuv/src/ares/ares_search.c create mode 100644 src/rt/libuv/src/ares/ares_send.c create mode 100644 src/rt/libuv/src/ares/ares_setup.h create mode 100644 src/rt/libuv/src/ares/ares_strcasecmp.c create mode 100644 src/rt/libuv/src/ares/ares_strcasecmp.h create mode 100644 src/rt/libuv/src/ares/ares_strdup.c create mode 100644 src/rt/libuv/src/ares/ares_strdup.h create mode 100644 src/rt/libuv/src/ares/ares_strerror.c create mode 100644 src/rt/libuv/src/ares/ares_timeout.c create mode 100644 src/rt/libuv/src/ares/ares_version.c create mode 100644 src/rt/libuv/src/ares/ares_writev.c create mode 100644 src/rt/libuv/src/ares/ares_writev.h create mode 100644 src/rt/libuv/src/ares/bitncmp.c create mode 100644 src/rt/libuv/src/ares/bitncmp.h create mode 100644 src/rt/libuv/src/ares/config_cygwin/ares_config.h create mode 100644 src/rt/libuv/src/ares/config_darwin/ares_config.h create mode 100644 src/rt/libuv/src/ares/config_freebsd/ares_config.h create mode 100644 src/rt/libuv/src/ares/config_linux/ares_config.h create mode 100644 src/rt/libuv/src/ares/config_openbsd/ares_config.h create mode 100644 src/rt/libuv/src/ares/config_sunos/ares_config.h create mode 100644 src/rt/libuv/src/ares/config_win32/ares_config.h create mode 100644 src/rt/libuv/src/ares/get_ver.awk create mode 100644 src/rt/libuv/src/ares/inet_net_pton.c create mode 100644 src/rt/libuv/src/ares/inet_net_pton.h create mode 100644 src/rt/libuv/src/ares/inet_ntop.c create mode 100644 src/rt/libuv/src/ares/inet_ntop.h create mode 100644 src/rt/libuv/src/ares/nameser.h create mode 100644 src/rt/libuv/src/ares/setup_once.h create mode 100644 src/rt/libuv/src/ares/windows_port.c create mode 100644 src/rt/libuv/src/eio/Changes create mode 100644 src/rt/libuv/src/eio/LICENSE create mode 100644 src/rt/libuv/src/eio/Makefile.am rename src/rt/libuv/{ev => src/eio}/aclocal.m4 (100%) create mode 100755 src/rt/libuv/src/eio/autogen.sh create mode 100644 src/rt/libuv/src/eio/config.h.in create mode 100644 src/rt/libuv/src/eio/config_cygwin.h create mode 100644 src/rt/libuv/src/eio/config_darwin.h create mode 100644 src/rt/libuv/src/eio/config_freebsd.h create mode 100644 src/rt/libuv/src/eio/config_linux.h create mode 100644 src/rt/libuv/src/eio/config_sunos.h create mode 100644 src/rt/libuv/src/eio/configure.ac create mode 100644 src/rt/libuv/src/eio/demo.c create mode 100644 src/rt/libuv/src/eio/eio.3 create mode 100644 src/rt/libuv/src/eio/eio.c create mode 100644 src/rt/libuv/src/eio/eio.pod create mode 100644 src/rt/libuv/src/eio/libeio.m4 create mode 100644 src/rt/libuv/src/eio/xthread.h rename src/rt/libuv/{ => src}/ev/Changes (100%) rename src/rt/libuv/{ => src}/ev/LICENSE (100%) rename src/rt/libuv/{ => src}/ev/Makefile.am (100%) rename src/rt/libuv/{ => src}/ev/Makefile.in (100%) rename src/rt/libuv/{ => src}/ev/README (100%) create mode 100644 src/rt/libuv/src/ev/aclocal.m4 rename src/rt/libuv/{ => src}/ev/autogen.sh (100%) rename src/rt/libuv/{ => src}/ev/config.guess (100%) rename src/rt/libuv/{ => src}/ev/config.h.in (100%) rename src/rt/libuv/{ => src}/ev/config.sub (100%) create mode 100644 src/rt/libuv/src/ev/config_cygwin.h create mode 100644 src/rt/libuv/src/ev/config_darwin.h create mode 100644 src/rt/libuv/src/ev/config_freebsd.h create mode 100644 src/rt/libuv/src/ev/config_linux.h create mode 100644 src/rt/libuv/src/ev/config_sunos.h rename src/rt/libuv/{ => src}/ev/configure (100%) rename src/rt/libuv/{ => src}/ev/configure.ac (100%) rename src/rt/libuv/{ => src}/ev/depcomp (100%) rename src/rt/libuv/{ => src}/ev/ev++.h (100%) rename src/rt/libuv/{ => src}/ev/ev.3 (100%) rename src/rt/libuv/{ => src}/ev/ev.c (100%) rename src/rt/libuv/{ => src}/ev/ev.pod (100%) rename src/rt/libuv/{ => src}/ev/ev_epoll.c (100%) rename src/rt/libuv/{ => src}/ev/ev_kqueue.c (100%) rename src/rt/libuv/{ => src}/ev/ev_poll.c (100%) rename src/rt/libuv/{ => src}/ev/ev_port.c (100%) rename src/rt/libuv/{ => src}/ev/ev_select.c (100%) rename src/rt/libuv/{ => src}/ev/ev_vars.h (100%) rename src/rt/libuv/{ => src}/ev/ev_win32.c (100%) rename src/rt/libuv/{ => src}/ev/ev_wrap.h (100%) rename src/rt/libuv/{ => src}/ev/event.c (100%) rename src/rt/libuv/{ => src}/ev/event.h (100%) rename src/rt/libuv/{ => src}/ev/install-sh (100%) rename src/rt/libuv/{ => src}/ev/libev.m4 (100%) rename src/rt/libuv/{ => src}/ev/ltmain.sh (100%) rename src/rt/libuv/{ => src}/ev/missing (100%) rename src/rt/libuv/{ => src}/ev/mkinstalldirs (100%) rename src/rt/libuv/{ => src}/uv-common.c (60%) create mode 100644 src/rt/libuv/src/uv-common.h create mode 100644 src/rt/libuv/src/uv-cygwin.c create mode 100644 src/rt/libuv/src/uv-darwin.c create mode 100644 src/rt/libuv/src/uv-eio.c create mode 100644 src/rt/libuv/src/uv-eio.h create mode 100644 src/rt/libuv/src/uv-freebsd.c create mode 100644 src/rt/libuv/src/uv-linux.c create mode 100644 src/rt/libuv/src/uv-sunos.c rename src/rt/libuv/{ => src}/uv-unix.c (67%) rename src/rt/libuv/{ => src}/uv-win.c (50%) create mode 100644 src/rt/libuv/test/benchmark-ares.c create mode 100644 src/rt/libuv/test/benchmark-getaddrinfo.c create mode 100644 src/rt/libuv/test/dns-server.c create mode 100644 src/rt/libuv/test/test-bind6-error.c create mode 100644 src/rt/libuv/test/test-getaddrinfo.c create mode 100644 src/rt/libuv/test/test-gethostbyname.c create mode 100644 src/rt/libuv/test/test-hrtime.c diff --git a/mk/rt.mk b/mk/rt.mk index ed3e5422923..a2f8e6c04c3 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -66,7 +66,7 @@ RUNTIME_HDR := rt/globals.h \ RUNTIME_DEF := rt/rustrt$(CFG_DEF_SUFFIX) RUNTIME_INCS := -I $(S)src/rt/isaac -I $(S)src/rt/uthash \ - -I $(S)src/rt/arch/i386 -I $(S)src/rt/libuv + -I $(S)src/rt/arch/i386 -I $(S)src/rt/libuv/include RUNTIME_OBJS := $(RUNTIME_CS:.cpp=.o) $(RUNTIME_LL:.ll=.o) $(RUNTIME_S:.s=.o) RUNTIME_LIBS := $(S)src/rt/libuv/uv.a @@ -97,7 +97,7 @@ rt/$(CFG_RUNTIME): $(RUNTIME_OBJS) $(MKFILES) $(RUNTIME_HDR) $(RUNTIME_DEF) $(RU @$(call E, link: $@) $(Q)$(call CFG_LINK_C,$@,$(CFG_GCCISH_POST_LIB_FLAGS) $(RUNTIME_LIBS) $(RUNTIME_OBJS),$(RUNTIME_DEF)) -$(S)src/rt/libuv/uv.a: rt/libuv/LIBUV_REVISION +$(S)src/rt/libuv/uv.a: $(S)src/rt/libuv/LIBUV_REVISION $(Q)$(MAKE) -C $(S)src/rt/libuv CFLAGS=\"-m32\" LDFLAGS=\"-m32\" $(Q)mkdir -p rt/libuv $(Q)cp $(S)src/rt/libuv/uv.a rt/libuv/uv.a diff --git a/src/rt/libuv/.gitignore b/src/rt/libuv/.gitignore index 333349590e6..9d142354bf3 100644 --- a/src/rt/libuv/.gitignore +++ b/src/rt/libuv/.gitignore @@ -26,3 +26,18 @@ test/run-tests.exe test/run-benchmarks.exe test/run-benchmarks.dSYM/ test/run-tests.dSYM/ + + +c-ares/.deps/ +c-ares/.libs/ +c-ares/Makefile +c-ares/acountry +c-ares/adig +c-ares/ahost +c-ares/ares_config.h +c-ares/config.log +c-ares/config.status +c-ares/libcares.pc +c-ares/libtool +c-ares/stamp-h1 +c-ares/stamp-h2 diff --git a/src/rt/libuv/AUTHORS b/src/rt/libuv/AUTHORS index 47b47d29aad..4b4cab70f13 100644 --- a/src/rt/libuv/AUTHORS +++ b/src/rt/libuv/AUTHORS @@ -3,4 +3,9 @@ Ryan Dahl Bert Belder Josh Roesslein Alan Gutierrez +Igor Zinkovsky Vanilla Hsu +Ben Noordhuis +Henry Rawas +Robert Mustacchi +Matt Stevens diff --git a/src/rt/libuv/LIBUV_REVISION b/src/rt/libuv/LIBUV_REVISION index 21c156e1dd0..f079f657765 100644 --- a/src/rt/libuv/LIBUV_REVISION +++ b/src/rt/libuv/LIBUV_REVISION @@ -1,5 +1,5 @@ This subtree is pulled from: -2b5707d834a6b85b8e589ac04cb61a6db2dab94b +ee599ec1141cc48f895de1f9d148033babdf9c2a When pulling in a new version of libuv, please update this file to ensure that everyone correctly rebuilds libuv. diff --git a/src/rt/libuv/LICENSE b/src/rt/libuv/LICENSE index 3ed5bc5ed0d..f7df47f71c9 100644 --- a/src/rt/libuv/LICENSE +++ b/src/rt/libuv/LICENSE @@ -35,3 +35,6 @@ The externally maintained libraries used by libuv are: - libev, located at ev/ is copyright Marc Alexander Lehmann, and dual-licensed under the MIT license and GPL2. + + - libeio, located at eio/ is copyright Marc Alexander Lehmann, and + dual-licensed under the MIT license and GPL2. diff --git a/src/rt/libuv/config-mingw.mk b/src/rt/libuv/config-mingw.mk index cd6e159d506..be8abca1cbe 100644 --- a/src/rt/libuv/config-mingw.mk +++ b/src/rt/libuv/config-mingw.mk @@ -20,26 +20,44 @@ # Use make -f Makefile.gcc PREFIX=i686-w64-mingw32- # for cross compilation -CC = $(PREFIX)gcc -AR = $(PREFIX)ar +CC ?= $(PREFIX)gcc +AR ?= $(PREFIX)ar E=.exe -CFLAGS=-g --std=gnu89 -Wno-variadic-macros +CFLAGS=$(CPPFLAGS) -g --std=gnu89 -D_WIN32_WINNT=0x0501 -Isrc/ares/config_win32 LINKFLAGS=-lm +CARES_OBJS += src/ares/windows_port.o + RUNNER_CFLAGS=$(CFLAGS) -D_GNU_SOURCE # Need _GNU_SOURCE for strdup? RUNNER_LINKFLAGS=$(LINKFLAGS) RUNNER_LIBS=-lws2_32 RUNNER_SRC=test/runner-win.c -uv.a: uv-win.o uv-common.o - $(AR) rcs uv.a uv-win.o uv-common.o +uv.a: src/uv-win.o src/uv-common.o src/uv-eio.o src/eio/eio.o $(CARES_OBJS) + $(AR) rcs uv.a src/uv-win.o src/uv-common.o src/uv-eio.o src/eio/eio.o $(CARES_OBJS) -uv-win.o: uv-win.c uv.h uv-win.h - $(CC) $(CFLAGS) -c uv-win.c -o uv-win.o +src/uv-win.o: src/uv-win.c include/uv.h include/uv-win.h + $(CC) $(CFLAGS) -c src/uv-win.c -o src/uv-win.o -uv-common.o: uv-common.c uv.h uv-win.h - $(CC) $(CFLAGS) -c uv-common.c -o uv-common.o +src/uv-common.o: src/uv-common.c include/uv.h include/uv-win.h + $(CC) $(CFLAGS) -c src/uv-common.c -o src/uv-common.o + +EIO_CPPFLAGS += $(CPPFLAGS) +EIO_CPPFLAGS += -DEIO_CONFIG_H=\"$(EIO_CONFIG)\" +EIO_CPPFLAGS += -DEIO_STACKSIZE=65536 +EIO_CPPFLAGS += -D_GNU_SOURCE + +src/eio/eio.o: src/eio/eio.c + $(CC) $(EIO_CPPFLAGS) $(CFLAGS) -c src/eio/eio.c -o src/eio/eio.o + +src/uv-eio.o: src/uv-eio.c + $(CC) $(CPPFLAGS) -Isrc/eio/ $(CFLAGS) -c src/uv-eio.c -o src/uv-eio.o + +clean-platform: + -rm -f src/ares/*.o + -rm -f src/eio/*.o distclean-platform: -clean-platform: + -rm -f src/ares/*.o + -rm -f src/eio/*.o diff --git a/src/rt/libuv/config-unix.mk b/src/rt/libuv/config-unix.mk index 3f9bc2f8d0e..b132cb5b5be 100644 --- a/src/rt/libuv/config-unix.mk +++ b/src/rt/libuv/config-unix.mk @@ -18,14 +18,56 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -CC = $(PREFIX)gcc -AR = $(PREFIX)ar +CC ?= $(PREFIX)gcc +AR ?= $(PREFIX)ar E= -CFLAGS=--std=gnu89 -Wno-variadic-macros -g +CSTDFLAG=--std=c89 -pedantic +CFLAGS=-g +CPPFLAGS += -Isrc/ev LINKFLAGS=-lm +CPPFLAGS += -D_LARGEFILE_SOURCE +CPPFLAGS += -D_FILE_OFFSET_BITS=64 + ifeq (SunOS,$(uname_S)) +EV_CONFIG=config_sunos.h +EIO_CONFIG=config_sunos.h +CPPFLAGS += -Isrc/ares/config_sunos LINKFLAGS+=-lsocket -lnsl +UV_OS_FILE=uv-sunos.c +endif + +ifeq (Darwin,$(uname_S)) +EV_CONFIG=config_darwin.h +EIO_CONFIG=config_darwin.h +CPPFLAGS += -Isrc/ares/config_darwin +LINKFLAGS+=-framework CoreServices +UV_OS_FILE=uv-darwin.c +endif + +ifeq (Linux,$(uname_S)) +EV_CONFIG=config_linux.h +EIO_CONFIG=config_linux.h +CSTDFLAG += -D_XOPEN_SOURCE=600 +CPPFLAGS += -Isrc/ares/config_linux +LINKFLAGS+=-lrt +UV_OS_FILE=uv-linux.c +endif + +ifeq (FreeBSD,$(uname_S)) +EV_CONFIG=config_freebsd.h +EIO_CONFIG=config_freebsd.h +CPPFLAGS += -Isrc/ares/config_freebsd +LINKFLAGS+= +UV_OS_FILE=uv-freebsd.c +endif + +ifneq (,$(findstring CYGWIN,$(uname_S))) +EV_CONFIG=config_cygwin.h +EIO_CONFIG=config_cygwin.h +CPPFLAGS += -Isrc/ares/config_cygwin +LINKFLAGS+= +UV_OS_FILE=uv-cygwin.c endif # Need _GNU_SOURCE for strdup? @@ -35,23 +77,43 @@ RUNNER_LINKFLAGS=$(LINKFLAGS) -pthread RUNNER_LIBS= RUNNER_SRC=test/runner-unix.c -uv.a: uv-unix.o uv-common.o ev/ev.o - $(AR) rcs uv.a uv-unix.o uv-common.o ev/ev.o +uv.a: src/uv-unix.o src/uv-common.o src/uv-platform.o src/ev/ev.o src/uv-eio.o src/eio/eio.o $(CARES_OBJS) + $(AR) rcs uv.a src/uv-unix.o src/uv-platform.o src/uv-common.o src/uv-eio.o src/ev/ev.o \ + src/eio/eio.o $(CARES_OBJS) -uv-unix.o: uv-unix.c uv.h uv-unix.h - $(CC) $(CFLAGS) -c uv-unix.c -o uv-unix.o +src/uv-platform.o: src/$(UV_OS_FILE) include/uv.h include/uv-unix.h + $(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c src/$(UV_OS_FILE) -o src/uv-platform.o -uv-common.o: uv-common.c uv.h uv-unix.h - $(CC) $(CFLAGS) -c uv-common.c -o uv-common.o +src/uv-unix.o: src/uv-unix.c include/uv.h include/uv-unix.h + $(CC) $(CSTDFLAG) $(CPPFLAGS) -Ieio $(CFLAGS) -c src/uv-unix.c -o src/uv-unix.o -ev/ev.o: ev/config.h ev/ev.c - $(MAKE) -C ev +src/uv-common.o: src/uv-common.c include/uv.h include/uv-unix.h + $(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c src/uv-common.c -o src/uv-common.o + +src/ev/ev.o: src/ev/ev.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c src/ev/ev.c -o src/ev/ev.o -DEV_CONFIG_H=\"$(EV_CONFIG)\" + + +EIO_CPPFLAGS += $(CPPFLAGS) +EIO_CPPFLAGS += -DEIO_CONFIG_H=\"$(EIO_CONFIG)\" +EIO_CPPFLAGS += -DEIO_STACKSIZE=65536 +EIO_CPPFLAGS += -D_GNU_SOURCE + +src/eio/eio.o: src/eio/eio.c + $(CC) $(EIO_CPPFLAGS) $(CFLAGS) -c src/eio/eio.c -o src/eio/eio.o + +src/uv-eio.o: src/uv-eio.c + $(CC) $(CPPFLAGS) -Isrc/eio/ $(CSTDFLAG) $(CFLAGS) -c src/uv-eio.c -o src/uv-eio.o -ev/config.h: - cd ev && ./configure clean-platform: - $(MAKE) -C ev clean + -rm -f src/ares/*.o + -rm -f src/ev/*.o + -rm -f src/eio/*.o + -rm -rf test/run-tests.dSYM run-benchmarks.dSYM distclean-platform: - $(MAKE) -C ev distclean + -rm -f src/ares/*.o + -rm -f src/ev/*.o + -rm -f src/eio/*.o + -rm -rf test/run-tests.dSYM run-benchmarks.dSYM diff --git a/src/rt/libuv/desired-api.md b/src/rt/libuv/doc/desired-api.md similarity index 100% rename from src/rt/libuv/desired-api.md rename to src/rt/libuv/doc/desired-api.md diff --git a/src/rt/libuv/include/ares.h b/src/rt/libuv/include/ares.h new file mode 100644 index 00000000000..905a29eea6f --- /dev/null +++ b/src/rt/libuv/include/ares.h @@ -0,0 +1,582 @@ + +/* Copyright 1998, 2009 by the Massachusetts Institute of Technology. + * Copyright (C) 2007-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#ifndef ARES__H +#define ARES__H + +#include "ares_version.h" /* c-ares version defines */ + +/* + * Define WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__)) && \ + !defined(WIN32) && !defined(__SYMBIAN32__) +# define WIN32 +#endif + +/*************************** libuv patch ***************/ + +/* + * We want to avoid autoconf altogether since there are a finite number of + * operating systems and simply build c-ares. Therefore we do not want the + * configurations provided by ares_build.h since we are always statically + * linking c-ares into libuv. Having a system dependent ares_build.h forces + * all users of ares.h to include the correct ares_build.h. We do not care + * about the linking checks provided by ares_rules.h. This would complicate + * the libuv build process. + */ + + +#if defined(WIN32) +/* Configure process defines this to 1 when it finds out that system */ +/* header file ws2tcpip.h must be included by the external interface. */ +/* #undef CARES_PULL_WS2TCPIP_H */ +# include +# include +# include + +#else /* Not Windows */ + +# include +# include +# include +#endif + +#if 0 +/* The size of `long', as computed by sizeof. */ +#define CARES_SIZEOF_LONG 4 +#endif + +/* Integral data type used for ares_socklen_t. */ +#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t + +#if 0 +/* The size of `ares_socklen_t', as computed by sizeof. */ +#define CARES_SIZEOF_ARES_SOCKLEN_T 4 +#endif + +/* Data type definition of ares_socklen_t. */ +typedef int ares_socklen_t; + +#if 0 /* libuv disabled */ +#include "ares_rules.h" /* c-ares rules enforcement */ +#endif + +/*********************** end libuv patch ***************/ + +#include + +/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish + libc5-based Linux systems. Only include it on system that are known to + require it! */ +#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ + defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) +#include +#endif +#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) +#include +#endif + +#if defined(WATT32) +# include +# include +# include +#elif defined(WIN32) +# include +# include +# include +#else +# include +# include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** c-ares external API function linkage decorations. +*/ + +#if !defined(CARES_STATICLIB) && \ + (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)) + /* __declspec function decoration for Win32 and Symbian DLL's */ +# if defined(CARES_BUILDING_LIBRARY) +# define CARES_EXTERN __declspec(dllexport) +# else +# define CARES_EXTERN __declspec(dllimport) +# endif +#else + /* visibility function decoration for other cases */ +# if !defined(CARES_SYMBOL_HIDING) || \ + defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__) +# define CARES_EXTERN +# else +# define CARES_EXTERN CARES_SYMBOL_SCOPE_EXTERN +# endif +#endif + + +#define ARES_SUCCESS 0 + +/* Server error codes (ARES_ENODATA indicates no relevant answer) */ +#define ARES_ENODATA 1 +#define ARES_EFORMERR 2 +#define ARES_ESERVFAIL 3 +#define ARES_ENOTFOUND 4 +#define ARES_ENOTIMP 5 +#define ARES_EREFUSED 6 + +/* Locally generated error codes */ +#define ARES_EBADQUERY 7 +#define ARES_EBADNAME 8 +#define ARES_EBADFAMILY 9 +#define ARES_EBADRESP 10 +#define ARES_ECONNREFUSED 11 +#define ARES_ETIMEOUT 12 +#define ARES_EOF 13 +#define ARES_EFILE 14 +#define ARES_ENOMEM 15 +#define ARES_EDESTRUCTION 16 +#define ARES_EBADSTR 17 + +/* ares_getnameinfo error codes */ +#define ARES_EBADFLAGS 18 + +/* ares_getaddrinfo error codes */ +#define ARES_ENONAME 19 +#define ARES_EBADHINTS 20 + +/* Uninitialized library error code */ +#define ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */ + +/* ares_library_init error codes */ +#define ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */ +#define ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */ + +/* More error codes */ +#define ARES_ECANCELLED 24 /* introduced in 1.7.0 */ + +/* Flag values */ +#define ARES_FLAG_USEVC (1 << 0) +#define ARES_FLAG_PRIMARY (1 << 1) +#define ARES_FLAG_IGNTC (1 << 2) +#define ARES_FLAG_NORECURSE (1 << 3) +#define ARES_FLAG_STAYOPEN (1 << 4) +#define ARES_FLAG_NOSEARCH (1 << 5) +#define ARES_FLAG_NOALIASES (1 << 6) +#define ARES_FLAG_NOCHECKRESP (1 << 7) + +/* Option mask values */ +#define ARES_OPT_FLAGS (1 << 0) +#define ARES_OPT_TIMEOUT (1 << 1) +#define ARES_OPT_TRIES (1 << 2) +#define ARES_OPT_NDOTS (1 << 3) +#define ARES_OPT_UDP_PORT (1 << 4) +#define ARES_OPT_TCP_PORT (1 << 5) +#define ARES_OPT_SERVERS (1 << 6) +#define ARES_OPT_DOMAINS (1 << 7) +#define ARES_OPT_LOOKUPS (1 << 8) +#define ARES_OPT_SOCK_STATE_CB (1 << 9) +#define ARES_OPT_SORTLIST (1 << 10) +#define ARES_OPT_SOCK_SNDBUF (1 << 11) +#define ARES_OPT_SOCK_RCVBUF (1 << 12) +#define ARES_OPT_TIMEOUTMS (1 << 13) +#define ARES_OPT_ROTATE (1 << 14) + +/* Nameinfo flag values */ +#define ARES_NI_NOFQDN (1 << 0) +#define ARES_NI_NUMERICHOST (1 << 1) +#define ARES_NI_NAMEREQD (1 << 2) +#define ARES_NI_NUMERICSERV (1 << 3) +#define ARES_NI_DGRAM (1 << 4) +#define ARES_NI_TCP 0 +#define ARES_NI_UDP ARES_NI_DGRAM +#define ARES_NI_SCTP (1 << 5) +#define ARES_NI_DCCP (1 << 6) +#define ARES_NI_NUMERICSCOPE (1 << 7) +#define ARES_NI_LOOKUPHOST (1 << 8) +#define ARES_NI_LOOKUPSERVICE (1 << 9) +/* Reserved for future use */ +#define ARES_NI_IDN (1 << 10) +#define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11) +#define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12) + +/* Addrinfo flag values */ +#define ARES_AI_CANONNAME (1 << 0) +#define ARES_AI_NUMERICHOST (1 << 1) +#define ARES_AI_PASSIVE (1 << 2) +#define ARES_AI_NUMERICSERV (1 << 3) +#define ARES_AI_V4MAPPED (1 << 4) +#define ARES_AI_ALL (1 << 5) +#define ARES_AI_ADDRCONFIG (1 << 6) +/* Reserved for future use */ +#define ARES_AI_IDN (1 << 10) +#define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11) +#define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12) +#define ARES_AI_CANONIDN (1 << 13) + +#define ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \ + ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \ + ARES_AI_ADDRCONFIG) +#define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this + many sockets */ +#define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num))) +#define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \ + ARES_GETSOCK_MAXNUM))) + +/* c-ares library initialization flag values */ +#define ARES_LIB_INIT_NONE (0) +#define ARES_LIB_INIT_WIN32 (1 << 0) +#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32) + + +/* + * Typedef our socket type + */ + +#ifndef ares_socket_typedef +#ifdef WIN32 +typedef SOCKET ares_socket_t; +#define ARES_SOCKET_BAD INVALID_SOCKET +#else +typedef int ares_socket_t; +#define ARES_SOCKET_BAD -1 +#endif +#define ares_socket_typedef +#endif /* ares_socket_typedef */ + +typedef void (*ares_sock_state_cb)(void *data, + ares_socket_t socket_fd, + int readable, + int writable); + +struct apattern; + +/* NOTE about the ares_options struct to users and developers. + + This struct will remain looking like this. It will not be extended nor + shrunk in future releases, but all new options will be set by ares_set_*() + options instead of with the ares_init_options() function. + + Eventually (in a galaxy far far away), all options will be settable by + ares_set_*() options and the ares_init_options() function will become + deprecated. + + When new options are added to c-ares, they are not added to this + struct. And they are not "saved" with the ares_save_options() function but + instead we encourage the use of the ares_dup() function. Needless to say, + if you add config options to c-ares you need to make sure ares_dup() + duplicates this new option. + + */ +struct ares_options { + int flags; + int timeout; /* in seconds or milliseconds, depending on options */ + int tries; + int ndots; + unsigned short udp_port; + unsigned short tcp_port; + int socket_send_buffer_size; + int socket_receive_buffer_size; + struct in_addr *servers; + int nservers; + char **domains; + int ndomains; + char *lookups; + ares_sock_state_cb sock_state_cb; + void *sock_state_cb_data; + struct apattern *sortlist; + int nsort; +}; + +struct hostent; +struct timeval; +struct sockaddr; +struct ares_channeldata; + +typedef struct ares_channeldata *ares_channel; + +typedef void (*ares_callback)(void *arg, + int status, + int timeouts, + unsigned char *abuf, + int alen); + +typedef void (*ares_host_callback)(void *arg, + int status, + int timeouts, + struct hostent *hostent); + +typedef void (*ares_nameinfo_callback)(void *arg, + int status, + int timeouts, + char *node, + char *service); + +typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd, + int type, + void *data); + +CARES_EXTERN int ares_library_init(int flags); + +CARES_EXTERN void ares_library_cleanup(void); + +CARES_EXTERN const char *ares_version(int *version); + +CARES_EXTERN int ares_init(ares_channel *channelptr); + +CARES_EXTERN int ares_init_options(ares_channel *channelptr, + struct ares_options *options, + int optmask); + +CARES_EXTERN int ares_save_options(ares_channel channel, + struct ares_options *options, + int *optmask); + +CARES_EXTERN void ares_destroy_options(struct ares_options *options); + +CARES_EXTERN int ares_dup(ares_channel *dest, + ares_channel src); + +CARES_EXTERN void ares_destroy(ares_channel channel); + +CARES_EXTERN void ares_cancel(ares_channel channel); + +/* These next 3 configure local binding for the out-going socket + * connection. Use these to specify source IP and/or network device + * on multi-homed systems. + */ +CARES_EXTERN void ares_set_local_ip4(ares_channel channel, unsigned int local_ip); + +/* local_ip6 should be 16 bytes in length */ +CARES_EXTERN void ares_set_local_ip6(ares_channel channel, + const unsigned char* local_ip6); + +/* local_dev_name should be null terminated. */ +CARES_EXTERN void ares_set_local_dev(ares_channel channel, + const char* local_dev_name); + +CARES_EXTERN void ares_set_socket_callback(ares_channel channel, + ares_sock_create_callback callback, + void *user_data); + +CARES_EXTERN void ares_send(ares_channel channel, + const unsigned char *qbuf, + int qlen, + ares_callback callback, + void *arg); + +CARES_EXTERN void ares_query(ares_channel channel, + const char *name, + int dnsclass, + int type, + ares_callback callback, + void *arg); + +CARES_EXTERN void ares_search(ares_channel channel, + const char *name, + int dnsclass, + int type, + ares_callback callback, + void *arg); + +CARES_EXTERN void ares_gethostbyname(ares_channel channel, + const char *name, + int family, + ares_host_callback callback, + void *arg); + +CARES_EXTERN int ares_gethostbyname_file(ares_channel channel, + const char *name, + int family, + struct hostent **host); + +CARES_EXTERN void ares_gethostbyaddr(ares_channel channel, + const void *addr, + int addrlen, + int family, + ares_host_callback callback, + void *arg); + +CARES_EXTERN void ares_getnameinfo(ares_channel channel, + const struct sockaddr *sa, + ares_socklen_t salen, + int flags, + ares_nameinfo_callback callback, + void *arg); + +CARES_EXTERN int ares_fds(ares_channel channel, + fd_set *read_fds, + fd_set *write_fds); + +CARES_EXTERN int ares_getsock(ares_channel channel, + ares_socket_t *socks, + int numsocks); + +CARES_EXTERN struct timeval *ares_timeout(ares_channel channel, + struct timeval *maxtv, + struct timeval *tv); + +CARES_EXTERN void ares_process(ares_channel channel, + fd_set *read_fds, + fd_set *write_fds); + +CARES_EXTERN void ares_process_fd(ares_channel channel, + ares_socket_t read_fd, + ares_socket_t write_fd); + +CARES_EXTERN int ares_mkquery(const char *name, + int dnsclass, + int type, + unsigned short id, + int rd, + unsigned char **buf, + int *buflen); + +CARES_EXTERN int ares_expand_name(const unsigned char *encoded, + const unsigned char *abuf, + int alen, + char **s, + long *enclen); + +CARES_EXTERN int ares_expand_string(const unsigned char *encoded, + const unsigned char *abuf, + int alen, + unsigned char **s, + long *enclen); + +/* + * NOTE: before c-ares 1.7.0 we would most often use the system in6_addr + * struct below when ares itself was built, but many apps would use this + * private version since the header checked a HAVE_* define for it. Starting + * with 1.7.0 we always declare and use our own to stop relying on the + * system's one. + */ +struct ares_in6_addr { + union { + unsigned char _S6_u8[16]; + } _S6_un; +}; + +struct ares_addrttl { + struct in_addr ipaddr; + int ttl; +}; + +struct ares_addr6ttl { + struct ares_in6_addr ip6addr; + int ttl; +}; + +struct ares_srv_reply { + struct ares_srv_reply *next; + char *host; + unsigned short priority; + unsigned short weight; + unsigned short port; +}; + +struct ares_mx_reply { + struct ares_mx_reply *next; + char *host; + unsigned short priority; +}; + +struct ares_txt_reply { + struct ares_txt_reply *next; + unsigned char *txt; + size_t length; /* length excludes null termination */ +}; + +/* +** Parse the buffer, starting at *abuf and of length alen bytes, previously +** obtained from an ares_search call. Put the results in *host, if nonnull. +** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with +** their TTLs in that array, and set *naddrttls to the number of addresses +** so written. +*/ + +CARES_EXTERN int ares_parse_a_reply(const unsigned char *abuf, + int alen, + struct hostent **host, + struct ares_addrttl *addrttls, + int *naddrttls); + +CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf, + int alen, + struct hostent **host, + struct ares_addr6ttl *addrttls, + int *naddrttls); + +CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf, + int alen, + const void *addr, + int addrlen, + int family, + struct hostent **host); + +CARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf, + int alen, + struct hostent **host); + +CARES_EXTERN int ares_parse_srv_reply(const unsigned char* abuf, + int alen, + struct ares_srv_reply** srv_out); + +CARES_EXTERN int ares_parse_mx_reply(const unsigned char* abuf, + int alen, + struct ares_mx_reply** mx_out); + +CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf, + int alen, + struct ares_txt_reply** txt_out); + +CARES_EXTERN void ares_free_string(void *str); + +CARES_EXTERN void ares_free_hostent(struct hostent *host); + +CARES_EXTERN void ares_free_data(void *dataptr); + +CARES_EXTERN const char *ares_strerror(int code); + +/* TODO: Hold port here as well. */ +struct ares_addr_node { + struct ares_addr_node *next; + int family; + union { + struct in_addr addr4; + struct ares_in6_addr addr6; + } addr; +}; + +CARES_EXTERN int ares_set_servers(ares_channel channel, + struct ares_addr_node *servers); + +/* Incomming string format: host[:port][,host[:port]]... */ +CARES_EXTERN int ares_set_servers_csv(ares_channel channel, + const char* servers); + +CARES_EXTERN int ares_get_servers(ares_channel channel, + struct ares_addr_node **servers); + +#ifdef __cplusplus +} +#endif + +#endif /* ARES__H */ diff --git a/src/rt/libuv/include/ares_version.h b/src/rt/libuv/include/ares_version.h new file mode 100644 index 00000000000..8baa897cda2 --- /dev/null +++ b/src/rt/libuv/include/ares_version.h @@ -0,0 +1,24 @@ + +#ifndef ARES__VERSION_H +#define ARES__VERSION_H + +/* This is the global package copyright */ +#define ARES_COPYRIGHT "2004 - 2010 Daniel Stenberg, ." + +#define ARES_VERSION_MAJOR 1 +#define ARES_VERSION_MINOR 7 +#define ARES_VERSION_PATCH 4 +#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\ + (ARES_VERSION_MINOR<<8)|\ + (ARES_VERSION_PATCH)) +#define ARES_VERSION_STR "1.7.4" + +#if (ARES_VERSION >= 0x010700) +# define CARES_HAVE_ARES_LIBRARY_INIT 1 +# define CARES_HAVE_ARES_LIBRARY_CLEANUP 1 +#else +# undef CARES_HAVE_ARES_LIBRARY_INIT +# undef CARES_HAVE_ARES_LIBRARY_CLEANUP +#endif + +#endif diff --git a/src/rt/libuv/include/eio.h b/src/rt/libuv/include/eio.h new file mode 100644 index 00000000000..3dd3267678a --- /dev/null +++ b/src/rt/libuv/include/eio.h @@ -0,0 +1,356 @@ +/* + * libeio API header + * + * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License ("GPL") version 2 or any later version, + * in which case the provisions of the GPL are applicable instead of + * the above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the BSD license, indicate your decision + * by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file under + * either the BSD or the GPL. + */ + +#ifndef EIO_H_ +#define EIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __OpenBSD__ +# include +#endif + +#ifdef _WIN32 +# define uid_t int +# define gid_t int +#endif + +typedef struct eio_req eio_req; +typedef struct eio_dirent eio_dirent; + +typedef int (*eio_cb)(eio_req *req); + +#ifndef EIO_REQ_MEMBERS +# define EIO_REQ_MEMBERS +#endif + +#ifndef EIO_STRUCT_STAT +# ifdef _WIN32 +# define EIO_STRUCT_STAT struct _stati64 +# else +# define EIO_STRUCT_STAT struct stat +# endif +#endif + +#ifndef EIO_STRUCT_STATVFS +# define EIO_STRUCT_STATVFS struct statvfs +#endif + +/* for readdir */ + +/* eio_readdir flags */ +enum +{ + EIO_READDIR_DENTS = 0x01, /* ptr2 contains eio_dirents, not just the (unsorted) names */ + EIO_READDIR_DIRS_FIRST = 0x02, /* dirents gets sorted into a good stat() ing order to find directories first */ + EIO_READDIR_STAT_ORDER = 0x04, /* dirents gets sorted into a good stat() ing order to quickly stat all files */ + EIO_READDIR_FOUND_UNKNOWN = 0x80, /* set by eio_readdir when *_ARRAY was set and any TYPE=UNKNOWN's were found */ + + EIO_READDIR_CUSTOM1 = 0x100, /* for use by apps */ + EIO_READDIR_CUSTOM2 = 0x200 /* for use by apps */ +}; + +/* using "typical" values in the hope that the compiler will do something sensible */ +enum eio_dtype +{ + EIO_DT_UNKNOWN = 0, + EIO_DT_FIFO = 1, + EIO_DT_CHR = 2, + EIO_DT_MPC = 3, /* multiplexed char device (v7+coherent) */ + EIO_DT_DIR = 4, + EIO_DT_NAM = 5, /* xenix special named file */ + EIO_DT_BLK = 6, + EIO_DT_MPB = 7, /* multiplexed block device (v7+coherent) */ + EIO_DT_REG = 8, + EIO_DT_NWK = 9, /* HP-UX network special */ + EIO_DT_CMP = 9, /* VxFS compressed */ + EIO_DT_LNK = 10, + /* DT_SHAD = 11,*/ + EIO_DT_SOCK = 12, + EIO_DT_DOOR = 13, /* solaris door */ + EIO_DT_WHT = 14, + EIO_DT_MAX = 15 /* highest DT_VALUE ever, hopefully */ +}; + +struct eio_dirent +{ + int nameofs; /* offset of null-terminated name string in (char *)req->ptr2 */ + unsigned short namelen; /* size of filename without trailing 0 */ + unsigned char type; /* one of EIO_DT_* */ + signed char score; /* internal use */ + ino_t inode; /* the inode number, if available, otherwise unspecified */ +}; + +/* eio_msync flags */ +enum +{ + EIO_MS_ASYNC = 1, + EIO_MS_INVALIDATE = 2, + EIO_MS_SYNC = 4 +}; + +/* eio_mtouch flags */ + +enum +{ + EIO_MT_MODIFY = 1 +}; + +/* eio_sync_file_range flags */ + +enum +{ + EIO_SYNC_FILE_RANGE_WAIT_BEFORE = 1, + EIO_SYNC_FILE_RANGE_WRITE = 2, + EIO_SYNC_FILE_RANGE_WAIT_AFTER = 4 +}; + +typedef double eio_tstamp; /* feel free to use double in your code directly */ + +/* the eio request structure */ + +enum +{ + EIO_CUSTOM, + EIO_OPEN, EIO_CLOSE, EIO_DUP2, + EIO_READ, EIO_WRITE, + EIO_READAHEAD, EIO_SENDFILE, + EIO_STAT, EIO_LSTAT, EIO_FSTAT, + EIO_STATVFS, EIO_FSTATVFS, + EIO_TRUNCATE, EIO_FTRUNCATE, + EIO_UTIME, EIO_FUTIME, + EIO_CHMOD, EIO_FCHMOD, + EIO_CHOWN, EIO_FCHOWN, + EIO_SYNC, EIO_FSYNC, EIO_FDATASYNC, + EIO_MSYNC, EIO_MTOUCH, EIO_SYNC_FILE_RANGE, + EIO_MLOCK, EIO_MLOCKALL, + EIO_UNLINK, EIO_RMDIR, EIO_MKDIR, EIO_RENAME, + EIO_MKNOD, EIO_READDIR, + EIO_LINK, EIO_SYMLINK, EIO_READLINK, + EIO_GROUP, EIO_NOP, + EIO_BUSY +}; + +/* mlockall constants */ +enum +{ + EIO_MCL_CURRENT = 1, + EIO_MCL_FUTURE = 2 +}; + +/* request priorities */ + +enum { + EIO_PRI_MIN = -4, + EIO_PRI_MAX = 4, + EIO_PRI_DEFAULT = 0 +}; + +/* eio request structure */ +/* this structure is mostly read-only */ +/* when initialising it, all members must be zero-initialised */ +struct eio_req +{ + eio_req volatile *next; /* private ETP */ + + ssize_t result; /* result of syscall, e.g. result = read (... */ + off_t offs; /* read, write, truncate, readahead, sync_file_range: file offset */ + size_t size; /* read, write, readahead, sendfile, msync, mlock, sync_file_range: length */ + void *ptr1; /* all applicable requests: pathname, old name; readdir: optional eio_dirents */ + void *ptr2; /* all applicable requests: new name or memory buffer; readdir: name strings */ + eio_tstamp nv1; /* utime, futime: atime; busy: sleep time */ + eio_tstamp nv2; /* utime, futime: mtime */ + + int type; /* EIO_xxx constant ETP */ + int int1; /* all applicable requests: file descriptor; sendfile: output fd; open, msync, mlockall, readdir: flags */ + long int2; /* chown, fchown: uid; sendfile: input fd; open, chmod, mkdir, mknod: file mode, sync_file_range: flags */ + long int3; /* chown, fchown: gid; mknod: dev_t */ + int errorno; /* errno value on syscall return */ + + unsigned char flags; /* private */ + signed char pri; /* the priority */ + + void *data; + eio_cb finish; + void (*destroy)(eio_req *req); /* called when requets no longer needed */ + void (*feed)(eio_req *req); /* only used for group requests */ + + EIO_REQ_MEMBERS + + eio_req *grp, *grp_prev, *grp_next, *grp_first; /* private */ +}; + +/* _private_ request flags */ +enum { + EIO_FLAG_CANCELLED = 0x01, /* request was cancelled */ + EIO_FLAG_PTR1_FREE = 0x02, /* need to free(ptr1) */ + EIO_FLAG_PTR2_FREE = 0x04, /* need to free(ptr2) */ + EIO_FLAG_GROUPADD = 0x08 /* some request was added to the group */ +}; + +/* undocumented/unsupported/private helper */ +/*void eio_page_align (void **addr, size_t *length);*/ + +/* returns < 0 on error, errno set + * need_poll, if non-zero, will be called when results are available + * and eio_poll_cb needs to be invoked (it MUST NOT call eio_poll_cb itself). + * done_poll is called when the need to poll is gone. + */ +int eio_init (void (*want_poll)(void), void (*done_poll)(void)); + +/* must be called regularly to handle pending requests */ +/* returns 0 if all requests were handled, -1 if not, or the value of EIO_FINISH if != 0 */ +int eio_poll (void); + +/* stop polling if poll took longer than duration seconds */ +void eio_set_max_poll_time (eio_tstamp nseconds); +/* do not handle more then count requests in one call to eio_poll_cb */ +void eio_set_max_poll_reqs (unsigned int nreqs); + +/* set minimum required number + * maximum wanted number + * or maximum idle number of threads */ +void eio_set_min_parallel (unsigned int nthreads); +void eio_set_max_parallel (unsigned int nthreads); +void eio_set_max_idle (unsigned int nthreads); + +unsigned int eio_nreqs (void); /* number of requests in-flight */ +unsigned int eio_nready (void); /* number of not-yet handled requests */ +unsigned int eio_npending (void); /* numbe rof finished but unhandled requests */ +unsigned int eio_nthreads (void); /* number of worker threads in use currently */ + +/*****************************************************************************/ +/* convinience wrappers */ + +#ifndef EIO_NO_WRAPPERS +eio_req *eio_nop (int pri, eio_cb cb, void *data); /* does nothing except go through the whole process */ +eio_req *eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data); /* ties a thread for this long, simulating busyness */ +eio_req *eio_sync (int pri, eio_cb cb, void *data); +eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data); +eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data); +eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data); +eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data); +eio_req *eio_mlock (void *addr, size_t length, int pri, eio_cb cb, void *data); +eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data); +eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data); +eio_req *eio_close (int fd, int pri, eio_cb cb, void *data); +eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data); +eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); +eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); +eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_fstatvfs (int fd, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_futime (int fd, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data); +eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data); +eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data); +eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data); +eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, int pri, eio_cb cb, void *data); +eio_req *eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_utime (const char *path, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data); +eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data); +eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data); +eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ +eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data); +eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data); +eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ +eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data); +eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data); +eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data); +eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data); +eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data); +#endif + +/*****************************************************************************/ +/* groups */ + +eio_req *eio_grp (eio_cb cb, void *data); +void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit); +void eio_grp_limit (eio_req *grp, int limit); +void eio_grp_add (eio_req *grp, eio_req *req); +void eio_grp_cancel (eio_req *grp); /* cancels all sub requests but not the group */ + +/*****************************************************************************/ +/* request api */ + +/* true if the request was cancelled, useful in the invoke callback */ +#define EIO_CANCELLED(req) ((req)->flags & EIO_FLAG_CANCELLED) + +#define EIO_RESULT(req) ((req)->result) +/* returns a pointer to the result buffer allocated by eio */ +#define EIO_BUF(req) ((req)->ptr2) +#define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) +#define EIO_STATVFS_BUF(req) ((EIO_STRUCT_STATVFS *)EIO_BUF(req)) +#define EIO_PATH(req) ((char *)(req)->ptr1) + +/* submit a request for execution */ +void eio_submit (eio_req *req); +/* cancel a request as soon fast as possible, if possible */ +void eio_cancel (eio_req *req); +/* destroy a request that has never been submitted */ +void eio_destroy (eio_req *req); + +/*****************************************************************************/ +/* convinience functions */ + +ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count); + +/*****************************************************************************/ +/* export these so node_file can use these function instead of pread/write */ + +#if !HAVE_PREADWRITE +ssize_t eio__pread (int fd, void *buf, size_t count, off_t offset); +ssize_t eio__pwrite (int fd, void *buf, size_t count, off_t offset); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/rt/libuv/ev/ev.h b/src/rt/libuv/include/ev.h similarity index 99% rename from src/rt/libuv/ev/ev.h rename to src/rt/libuv/include/ev.h index 6fb8083413a..526b9f1bcb9 100644 --- a/src/rt/libuv/ev/ev.h +++ b/src/rt/libuv/include/ev.h @@ -197,7 +197,7 @@ struct ev_loop; /* eventmask, revents, events... */ enum { - EV_UNDEF = 0xFFFFFFFF, /* guaranteed to be invalid */ + EV_UNDEF = -1, /* guaranteed to be invalid */ EV_NONE = 0x00, /* no events */ EV_READ = 0x01, /* ev_io detected read will not block */ EV_WRITE = 0x02, /* ev_io detected write will not block */ @@ -219,7 +219,7 @@ enum { EV_CLEANUP = 0x00040000, /* event loop resumed in child */ EV_ASYNC = 0x00080000, /* async intra-loop signal */ EV_CUSTOM = 0x01000000, /* for use by user code */ - EV_ERROR = 0x80000000 /* sent when an error occurs */ + EV_ERROR = (-2147483647 - 1) /* sent when an error occurs */ }; /* can be used to add custom fields to all watchers, while losing binary compatibility */ diff --git a/src/rt/libuv/ngx-queue.h b/src/rt/libuv/include/ngx-queue.h similarity index 100% rename from src/rt/libuv/ngx-queue.h rename to src/rt/libuv/include/ngx-queue.h diff --git a/src/rt/libuv/tree.h b/src/rt/libuv/include/tree.h similarity index 100% rename from src/rt/libuv/tree.h rename to src/rt/libuv/include/tree.h diff --git a/src/rt/libuv/uv-unix.h b/src/rt/libuv/include/uv-unix.h similarity index 77% rename from src/rt/libuv/uv-unix.h rename to src/rt/libuv/include/uv-unix.h index 9d689013341..f68a7fd6fd9 100644 --- a/src/rt/libuv/uv-unix.h +++ b/src/rt/libuv/include/uv-unix.h @@ -24,9 +24,11 @@ #include "ngx-queue.h" -#include "ev/ev.h" +#include "ev.h" +#include #include +#include #include #include @@ -37,13 +39,15 @@ typedef struct { size_t len; } uv_buf_t; +#define UV_REQ_BUFSML_SIZE (4) #define UV_REQ_PRIVATE_FIELDS \ int write_index; \ ev_timer timer; \ ngx_queue_t queue; \ uv_buf_t* bufs; \ - int bufcnt; + int bufcnt; \ + uv_buf_t bufsml[UV_REQ_BUFSML_SIZE]; /* TODO: union or classes please! */ @@ -53,48 +57,64 @@ typedef struct { ev_idle next_watcher; +#define UV_STREAM_PRIVATE_FIELDS \ + uv_read_cb read_cb; \ + uv_alloc_cb alloc_cb; + + /* UV_TCP */ #define UV_TCP_PRIVATE_FIELDS \ int delayed_error; \ - uv_read_cb read_cb; \ - uv_alloc_cb alloc_cb; \ uv_connection_cb connection_cb; \ int accepted_fd; \ uv_req_t *connect_req; \ uv_req_t *shutdown_req; \ ev_io read_watcher; \ ev_io write_watcher; \ - ngx_queue_t write_queue; + ngx_queue_t write_queue; \ + ngx_queue_t write_completed_queue; /* UV_PREPARE */ \ #define UV_PREPARE_PRIVATE_FIELDS \ ev_prepare prepare_watcher; \ - uv_loop_cb prepare_cb; + uv_prepare_cb prepare_cb; /* UV_CHECK */ #define UV_CHECK_PRIVATE_FIELDS \ ev_check check_watcher; \ - uv_loop_cb check_cb; + uv_check_cb check_cb; /* UV_IDLE */ #define UV_IDLE_PRIVATE_FIELDS \ ev_idle idle_watcher; \ - uv_loop_cb idle_cb; + uv_idle_cb idle_cb; /* UV_ASYNC */ #define UV_ASYNC_PRIVATE_FIELDS \ ev_async async_watcher; \ - uv_loop_cb async_cb; + uv_async_cb async_cb; /* UV_TIMER */ #define UV_TIMER_PRIVATE_FIELDS \ ev_timer timer_watcher; \ - uv_loop_cb timer_cb; + uv_timer_cb timer_cb; +#define UV_ARES_TASK_PRIVATE_FIELDS \ + int sock; \ + ev_io read_watcher; \ + ev_io write_watcher; + +#define UV_GETADDRINFO_PRIVATE_FIELDS \ + uv_getaddrinfo_cb cb; \ + struct addrinfo* hints; \ + char* hostname; \ + char* service; \ + struct addrinfo* res; \ + int retcode; #endif /* UV_UNIX_H */ diff --git a/src/rt/libuv/uv-win.h b/src/rt/libuv/include/uv-win.h similarity index 73% rename from src/rt/libuv/uv-win.h rename to src/rt/libuv/include/uv-win.h index 837da7d1013..e6254fee09a 100644 --- a/src/rt/libuv/uv-win.h +++ b/src/rt/libuv/include/uv-win.h @@ -31,7 +31,6 @@ #include "tree.h" - /** * It should be possible to cast uv_buf_t[] to WSABUF[] * see http://msdn.microsoft.com/en-us/library/ms741542(v=vs.85).aspx @@ -53,10 +52,12 @@ typedef struct uv_buf_t { uv_err_t error; \ struct uv_req_s* next_req; -#define uv_tcp_connection_fields \ +#define UV_STREAM_PRIVATE_FIELDS \ uv_alloc_cb alloc_cb; \ uv_read_cb read_cb; \ struct uv_req_s read_req; \ + +#define uv_tcp_connection_fields \ unsigned int write_reqs_pending; \ uv_req_t* shutdown_req; @@ -81,32 +82,49 @@ typedef struct uv_buf_t { RB_ENTRY(uv_timer_s) tree_entry; \ int64_t due; \ int64_t repeat; \ - uv_loop_cb timer_cb; - -#define UV_LOOP_PRIVATE_FIELDS \ - uv_handle_t* loop_prev; \ - uv_handle_t* loop_next; \ - uv_loop_cb loop_cb; + uv_timer_cb timer_cb; #define UV_ASYNC_PRIVATE_FIELDS \ struct uv_req_s async_req; \ /* char to avoid alignment issues */ \ char volatile async_sent; -#define UV_PREPARE_PRIVATE_FIELDS /* empty */ -#define UV_CHECK_PRIVATE_FIELDS /* empty */ -#define UV_IDLE_PRIVATE_FIELDS /* empty */ +#define UV_PREPARE_PRIVATE_FIELDS \ + uv_prepare_t* prepare_prev; \ + uv_prepare_t* prepare_next; \ + uv_prepare_cb prepare_cb; -/* - * TODO: remove UV_LOOP_PRIVATE_FIELDS from UV_HANDLE_PRIVATE_FIELDS and - * use it in UV_(PREPARE|CHECK|IDLE)_PRIVATE_FIELDS instead. - */ +#define UV_CHECK_PRIVATE_FIELDS \ + uv_check_t* check_prev; \ + uv_check_t* check_next; \ + uv_check_cb check_cb; + +#define UV_IDLE_PRIVATE_FIELDS \ + uv_idle_t* idle_prev; \ + uv_idle_t* idle_next; \ + uv_idle_cb idle_cb; #define UV_HANDLE_PRIVATE_FIELDS \ uv_handle_t* endgame_next; \ unsigned int flags; \ - uv_err_t error; \ - UV_LOOP_PRIVATE_FIELDS + uv_err_t error; +#define UV_ARES_TASK_PRIVATE_FIELDS \ + struct uv_req_s ares_req; \ + SOCKET sock; \ + HANDLE h_wait; \ + WSAEVENT h_event; \ + HANDLE h_close_event; + +#define UV_GETADDRINFO_PRIVATE_FIELDS \ + struct uv_req_s getadddrinfo_req; \ + uv_getaddrinfo_cb getaddrinfo_cb; \ + void* alloc; \ + wchar_t* node; \ + wchar_t* service; \ + struct addrinfoW* hints; \ + struct addrinfoW* res; \ + int retcode; int uv_utf16_to_utf8(wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, size_t utf8Size); +int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size); diff --git a/src/rt/libuv/uv.h b/src/rt/libuv/include/uv.h similarity index 65% rename from src/rt/libuv/uv.h rename to src/rt/libuv/include/uv.h index cd48fde6fe0..6aecb282008 100644 --- a/src/rt/libuv/uv.h +++ b/src/rt/libuv/include/uv.h @@ -28,21 +28,28 @@ extern "C" { #define UV_VERSION_MAJOR 0 #define UV_VERSION_MINOR 1 +#define CARES_STATICLIB 1 + #include /* int64_t */ #include /* size_t */ -#ifndef ssize_t +#include "ares.h" + +#ifndef _SSIZE_T_ typedef intptr_t ssize_t; #endif typedef struct uv_err_s uv_err_t; typedef struct uv_handle_s uv_handle_t; +typedef struct uv_stream_s uv_stream_t; typedef struct uv_tcp_s uv_tcp_t; typedef struct uv_timer_s uv_timer_t; typedef struct uv_prepare_s uv_prepare_t; typedef struct uv_check_s uv_check_t; typedef struct uv_idle_s uv_idle_t; typedef struct uv_req_s uv_req_t; +typedef struct uv_async_s uv_async_t; +typedef struct uv_getaddrinfo_s uv_getaddrinfo_t; #if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__) @@ -60,16 +67,20 @@ typedef struct uv_req_s uv_req_t; * In the case of uv_read_cb the uv_buf_t returned should be freed by the * user. */ -typedef uv_buf_t (*uv_alloc_cb)(uv_tcp_t* tcp, size_t suggested_size); -typedef void (*uv_read_cb)(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf); +typedef uv_buf_t (*uv_alloc_cb)(uv_stream_t* tcp, size_t suggested_size); +typedef void (*uv_read_cb)(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf); typedef void (*uv_write_cb)(uv_req_t* req, int status); typedef void (*uv_connect_cb)(uv_req_t* req, int status); typedef void (*uv_shutdown_cb)(uv_req_t* req, int status); -typedef void (*uv_connection_cb)(uv_tcp_t* server, int status); +typedef void (*uv_connection_cb)(uv_handle_t* server, int status); typedef void (*uv_close_cb)(uv_handle_t* handle); -/* TODO: do loop_cb and async_cb really need a status argument? */ -typedef void (*uv_loop_cb)(uv_handle_t* handle, int status); -typedef void (*uv_async_cb)(uv_handle_t* handle, int status); +typedef void (*uv_timer_cb)(uv_timer_t* handle, int status); +/* TODO: do these really need a status argument? */ +typedef void (*uv_async_cb)(uv_async_t* handle, int status); +typedef void (*uv_prepare_cb)(uv_prepare_t* handle, int status); +typedef void (*uv_check_cb)(uv_check_t* handle, int status); +typedef void (*uv_idle_cb)(uv_idle_t* handle, int status); +typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* handle, int status, struct addrinfo* res); /* Expand this list if necessary. */ @@ -108,7 +119,12 @@ typedef enum { UV_EPROTO, UV_EPROTONOSUPPORT, UV_EPROTOTYPE, - UV_ETIMEDOUT + UV_ETIMEDOUT, + UV_ECHARSET, + UV_EAIFAMNOSUPPORT, + UV_EAINONAME, + UV_EAISERVICE, + UV_EAISOCKTYPE } uv_err_code; typedef enum { @@ -121,7 +137,10 @@ typedef enum { UV_PREPARE, UV_CHECK, UV_IDLE, - UV_ASYNC + UV_ASYNC, + UV_ARES, + UV_ARES_TASK, + UV_GETADDRINFO } uv_handle_type; typedef enum { @@ -148,7 +167,7 @@ struct uv_req_s { uv_req_type type; /* public */ uv_handle_t* handle; - void* cb; + void *(*cb)(void *); void* data; /* private */ UV_REQ_PRIVATE_FIELDS @@ -157,7 +176,9 @@ struct uv_req_s { /* * Initialize a request for use with uv_write, uv_shutdown, or uv_connect. */ -void uv_req_init(uv_req_t* req, uv_handle_t* handle, void* cb); +void uv_req_init(uv_req_t* req, uv_handle_t* handle, void *(*cb)(void *)); + +int uv_shutdown(uv_req_t* req); #define UV_HANDLE_FIELDS \ @@ -167,7 +188,7 @@ void uv_req_init(uv_req_t* req, uv_handle_t* handle, void* cb); uv_close_cb close_cb; \ void* data; \ /* private */ \ - UV_HANDLE_PRIVATE_FIELDS \ + UV_HANDLE_PRIVATE_FIELDS /* The abstract base class of all handles. */ struct uv_handle_s { @@ -187,33 +208,29 @@ int uv_is_active(uv_handle_t* handle); int uv_close(uv_handle_t* handle, uv_close_cb close_cb); -/* - * A subclass of uv_handle_t representing a TCP stream or TCP server. In the - * future this will probably be split into two classes - one a stream and - * the other a server. - */ -struct uv_tcp_s { +#define UV_STREAM_FIELDS \ + /* number of bytes queued for writing */ \ + size_t write_queue_size; \ + /* private */ \ + UV_STREAM_PRIVATE_FIELDS + +/* The abstract base class for all streams. */ +struct uv_stream_s { UV_HANDLE_FIELDS - size_t write_queue_size; /* number of bytes queued for writing */ - UV_TCP_PRIVATE_FIELDS + UV_STREAM_FIELDS }; -int uv_tcp_init(uv_tcp_t* handle); - -int uv_bind(uv_tcp_t* handle, struct sockaddr_in); - -int uv_connect(uv_req_t* req, struct sockaddr_in); - -int uv_shutdown(uv_req_t* req); - -int uv_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb); - -/* This call is used in conjunction with uv_listen() to accept incoming TCP +/* This call is used in conjunction with uv_listen() to accept incoming * connections. Call uv_accept after receiving a uv_connection_cb to accept - * the connection. Before calling uv_accept use uv_tcp_init() must be + * the connection. Before calling uv_accept use uv_*_init() must be * called on the client. Non-zero return value indicates an error. + * + * When the uv_connection_cb is called it is guaranteed that uv_accept will + * complete successfully the first time. If you attempt to use it more than + * once, it may fail. It is suggested to only call uv_accept once per + * uv_connection_cb call. */ -int uv_accept(uv_tcp_t* server, uv_tcp_t* client); +int uv_accept(uv_handle_t* server, uv_stream_t* client); /* Read data from an incoming stream. The callback will be made several * several times until there is no more data to read or uv_read_stop is @@ -224,13 +241,52 @@ int uv_accept(uv_tcp_t* server, uv_tcp_t* client); * eof; it happens when libuv requested a buffer through the alloc callback * but then decided that it didn't need that buffer. */ -int uv_read_start(uv_tcp_t*, uv_alloc_cb alloc_cb, uv_read_cb read_cb); +int uv_read_start(uv_stream_t*, uv_alloc_cb alloc_cb, uv_read_cb read_cb); -int uv_read_stop(uv_tcp_t*); +int uv_read_stop(uv_stream_t*); +/* Write data to stream. Buffers are written in order. Example: + * + * uv_buf_t a[] = { + * { .base = "1", .len = 1 }, + * { .base = "2", .len = 1 } + * }; + * + * uv_buf_t b[] = { + * { .base = "3", .len = 1 }, + * { .base = "4", .len = 1 } + * }; + * + * // writes "1234" + * uv_write(req, a, 2); + * uv_write(req, b, 2); + * + */ int uv_write(uv_req_t* req, uv_buf_t bufs[], int bufcnt); +/* + * A subclass of uv_stream_t representing a TCP stream or TCP server. In the + * future this will probably be split into two classes - one a stream and + * the other a server. + */ +struct uv_tcp_s { + UV_HANDLE_FIELDS + UV_STREAM_FIELDS + UV_TCP_PRIVATE_FIELDS +}; + +int uv_tcp_init(uv_tcp_t* handle); + +int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in); +int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6); + +int uv_tcp_connect(uv_req_t* req, struct sockaddr_in); +int uv_tcp_connect6(uv_req_t* req, struct sockaddr_in6); + +int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb); + + /* * Subclass of uv_handle_t. libev wrapper. Every active prepare handle gets * its callback called exactly once per loop iteration, just before the @@ -243,7 +299,7 @@ struct uv_prepare_s { int uv_prepare_init(uv_prepare_t* prepare); -int uv_prepare_start(uv_prepare_t* prepare, uv_loop_cb cb); +int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb); int uv_prepare_stop(uv_prepare_t* prepare); @@ -260,7 +316,7 @@ struct uv_check_s { int uv_check_init(uv_check_t* check); -int uv_check_start(uv_check_t* check, uv_loop_cb cb); +int uv_check_start(uv_check_t* check, uv_check_cb cb); int uv_check_stop(uv_check_t* check); @@ -278,7 +334,7 @@ struct uv_idle_s { int uv_idle_init(uv_idle_t* idle); -int uv_idle_start(uv_idle_t* idle, uv_loop_cb cb); +int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb); int uv_idle_stop(uv_idle_t* idle); @@ -291,10 +347,10 @@ int uv_idle_stop(uv_idle_t* idle); * after the call to async_send. Unlike all other libuv functions, * uv_async_send can be called from another thread. */ -typedef struct { +struct uv_async_s { UV_HANDLE_FIELDS UV_ASYNC_PRIVATE_FIELDS -} uv_async_t; +}; int uv_async_init(uv_async_t* async, uv_async_cb async_cb); @@ -312,7 +368,7 @@ struct uv_timer_s { int uv_timer_init(uv_timer_t* timer); -int uv_timer_start(uv_timer_t* timer, uv_loop_cb cb, int64_t timeout, int64_t repeat); +int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat); int uv_timer_stop(uv_timer_t* timer); @@ -334,6 +390,37 @@ void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat); int64_t uv_timer_get_repeat(uv_timer_t* timer); +/* c-ares integration initialize and terminate */ +int uv_ares_init_options(ares_channel *channelptr, + struct ares_options *options, + int optmask); + +void uv_ares_destroy(ares_channel channel); + + +/* + * Subclass of uv_handle_t. Used for integration of getaddrinfo. + */ +struct uv_getaddrinfo_s { + UV_HANDLE_FIELDS + UV_GETADDRINFO_PRIVATE_FIELDS +}; + + +/* uv_getaddrinfo + * return code of UV_OK means that request is accepted, + * and callback will be called with result. + * Other return codes mean that there will not be a callback. + * Input arguments may be released after return from this call. + * Callback must not call freeaddrinfo + */ + int uv_getaddrinfo(uv_getaddrinfo_t* handle, + uv_getaddrinfo_cb getaddrinfo_cb, + const char* node, + const char* service, + const struct addrinfo* hints); + + /* * Most functions return boolean: 0 for success and -1 for failure. * On error the user should then call uv_last_error() to determine @@ -358,10 +445,22 @@ int64_t uv_now(); /* Utility */ -struct sockaddr_in uv_ip4_addr(char* ip, int port); +struct sockaddr_in uv_ip4_addr(const char* ip, int port); +struct sockaddr_in6 uv_ip6_addr(const char* ip, int port); /* Gets the executable path */ -int uv_get_exepath(char* buffer, size_t* size); +int uv_exepath(char* buffer, size_t* size); + +/* + * Returns the current high-resolution real time. This is expressed in + * nanoseconds. It is relative to an arbitrary time in the past. It is not + * related to the time of day and therefore not subject to clock drift. The + * primary use is for measuring performance between intervals. + * + * Note not every platform can support nanosecond resolution; however, this + * value will always be in nanoseconds. + */ +extern uint64_t uv_hrtime(void); /* the presence of this union forces similar struct layout */ @@ -372,6 +471,7 @@ union uv_any_handle { uv_idle_t idle; uv_async_t async; uv_timer_t timer; + uv_getaddrinfo_t getaddrinfo; }; /* Diagnostic counters */ @@ -386,7 +486,19 @@ typedef struct { uint64_t timer_init; } uv_counters_t; -uv_counters_t* const uv_counters(); +uv_counters_t* uv_counters(); + + +/* Don't export the private CPP symbols. */ +#undef UV_REQ_PRIVATE_FIELDS +#undef UV_STREAM_PRIVATE_FIELDS +#undef UV_TCP_PRIVATE_FIELDS +#undef UV_PREPARE_PRIVATE_FIELDS +#undef UV_CHECK_PRIVATE_FIELDS +#undef UV_IDLE_PRIVATE_FIELDS +#undef UV_ASYNC_PRIVATE_FIELDS +#undef UV_TIMER_PRIVATE_FIELDS +#undef UV_GETADDRINFO_PRIVATE_FIELDS #ifdef __cplusplus } diff --git a/src/rt/libuv/msvs/c-ares.vcxproj b/src/rt/libuv/msvs/c-ares.vcxproj new file mode 100644 index 00000000000..4ada6ccb3df --- /dev/null +++ b/src/rt/libuv/msvs/c-ares.vcxproj @@ -0,0 +1,179 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + Win32Proj + + + + StaticLibrary + true + + + StaticLibrary + true + + + StaticLibrary + false + + + StaticLibrary + false + + + + + + + + + + + + + + + + + + + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + + + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + + + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + + + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + $(SolutionDir)..\build\$(Platform)\$(Configuration)\ + + + + WIN32;HAVE_CONFIG_H;_DEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreadedDebug + Level3 + ProgramDatabase + Disabled + ..\include;..\src\ares\config_win32 + + + + + WIN32;HAVE_CONFIG_H;_DEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreadedDebug + Level3 + ProgramDatabase + Disabled + ..\include;..\src\ares\config_win32 + + + + + MultiThreaded + ..\include;..\src\ares\config_win32 + WIN32;HAVE_CONFIG_H;_LIB;%(PreprocessorDefinitions) + + + + + MultiThreaded + ..\include;..\src\ares\config_win32 + WIN32;HAVE_CONFIG_H;_LIB;%(PreprocessorDefinitions) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/rt/libuv/msvs/libuv-benchmark.vcxproj b/src/rt/libuv/msvs/libuv-benchmark.vcxproj index 4a24462b2f6..5727a1aa3c8 100644 --- a/src/rt/libuv/msvs/libuv-benchmark.vcxproj +++ b/src/rt/libuv/msvs/libuv-benchmark.vcxproj @@ -81,6 +81,7 @@ Level3 ProgramDatabase Disabled + ..\include;..\src\ares\config_win32 MachineX86 @@ -96,6 +97,7 @@ Level3 ProgramDatabase Disabled + ..\include;..\src\ares\config_win32 true @@ -109,6 +111,7 @@ MultiThreaded Level3 ProgramDatabase + ..\include;..\src\ares\config_win32 MachineX86 @@ -125,6 +128,7 @@ MultiThreaded Level3 ProgramDatabase + ..\include;..\src\ares\config_win32 true @@ -135,28 +139,19 @@ + + + - - true - true - true - true - - - true - true - true - true - diff --git a/src/rt/libuv/msvs/libuv-test.vcxproj b/src/rt/libuv/msvs/libuv-test.vcxproj index 0c360b90546..5b47daeb201 100644 --- a/src/rt/libuv/msvs/libuv-test.vcxproj +++ b/src/rt/libuv/msvs/libuv-test.vcxproj @@ -82,6 +82,7 @@ Level3 ProgramDatabase Disabled + ..\include;..\src\ares\config_win32 MachineX86 @@ -97,6 +98,7 @@ Level3 ProgramDatabase Disabled + ..\include;..\src\ares\config_win32 true @@ -110,6 +112,7 @@ MultiThreaded Level3 ProgramDatabase + ..\include;..\src\ares\config_win32 MachineX86 @@ -126,6 +129,7 @@ MultiThreaded Level3 ProgramDatabase + ..\include;..\src\ares\config_win32 true @@ -137,18 +141,16 @@ - - true - true - true - true - + + + + @@ -162,12 +164,6 @@ - - true - true - true - true - diff --git a/src/rt/libuv/msvs/libuv.sln b/src/rt/libuv/msvs/libuv.sln index e68d41d38c8..a4eca0a6d4b 100644 --- a/src/rt/libuv/msvs/libuv.sln +++ b/src/rt/libuv/msvs/libuv.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libuv-test", "libuv-test.vc EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libuv-benchmark", "libuv-benchmark.vcxproj", "{6CCBDAFD-7A11-133D-357B-E2D2F4C621E4}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c-ares", "c-ares.vcxproj", "{2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -39,6 +41,14 @@ Global {6CCBDAFD-7A11-133D-357B-E2D2F4C621E4}.Release|Win32.Build.0 = Release|Win32 {6CCBDAFD-7A11-133D-357B-E2D2F4C621E4}.Release|x64.ActiveCfg = Release|x64 {6CCBDAFD-7A11-133D-357B-E2D2F4C621E4}.Release|x64.Build.0 = Release|x64 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Debug|Win32.ActiveCfg = Debug|Win32 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Debug|Win32.Build.0 = Debug|Win32 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Debug|x64.ActiveCfg = Debug|x64 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Debug|x64.Build.0 = Debug|x64 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Release|Win32.ActiveCfg = Release|Win32 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Release|Win32.Build.0 = Release|Win32 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Release|x64.ActiveCfg = Release|x64 + {2B6A4644-EBA9-DFB5-AF35-6C56EDF05C7F}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/rt/libuv/msvs/libuv.vcxproj b/src/rt/libuv/msvs/libuv.vcxproj index 7b11f49e370..c896c6970f0 100644 --- a/src/rt/libuv/msvs/libuv.vcxproj +++ b/src/rt/libuv/msvs/libuv.vcxproj @@ -78,6 +78,7 @@ Level3 ProgramDatabase Disabled + ..\include;..\src\ares\config_win32 @@ -87,48 +88,42 @@ Level3 ProgramDatabase Disabled + ..\include;..\src\ares\config_win32 MultiThreaded + ..\include;..\src\ares\config_win32 MultiThreaded + ..\include;..\src\ares\config_win32 - - - true - true - true - true - - - - + + {2b6a4644-eba9-dfb5-af35-6c56edf05c7f} + true + true + false + true + false + - - true - true - true - true - - - + + - - - - - - - + + + + + + diff --git a/src/rt/libuv/src/ares/AUTHORS b/src/rt/libuv/src/ares/AUTHORS new file mode 100644 index 00000000000..e197a7419d0 --- /dev/null +++ b/src/rt/libuv/src/ares/AUTHORS @@ -0,0 +1,37 @@ +c-ares is based on ares, and these are the people that have worked on it since +the fork was made: + +Alexander Lazic +Alexey Simak +Andreas Rieke +Ashish Sharma +Brad House +Brad Spencer +Bram Matthys +Dan Fandrich +Daniel Stenberg +Dirk Manske +Dominick Meglio +Doug Goldstein +Duncan Wilcox +Eino Tuominen +Erik Kline +George Neill +Gisle Vanem +Guilherme Balena Versiani +Gunter Knauf +Henrik Stoerner +James Bursa +Michael Wallner +Nick Mathewson +Phil Blundell +Ravi Pratap +Robin Cornelius +Sebastian at basti79.de +Shmulik Regev +Steinar H. Gunderson +Tofu Linden +Vlad Dinulescu +William Ahern +Yang Tse +liren at vivisimo.com diff --git a/src/rt/libuv/src/ares/CHANGES b/src/rt/libuv/src/ares/CHANGES new file mode 100644 index 00000000000..f739b468790 --- /dev/null +++ b/src/rt/libuv/src/ares/CHANGES @@ -0,0 +1,1198 @@ + Changelog for the c-ares project + +Version 1.7.4 (December 9, 2010) + +Changed: + + o local-bind: Support binding to local interface/IPs, see + ares_set_local_ip4, ares_set_local_ip6, ares_set_local_dev + +Fixed: + + o memory leak in ares_getnameinfo + o add missing break that caused get_ares_servers to fail + o ares_parse_a_reply: fix CNAME response parsing + o init_by_options: don't copy an empty sortlist + o Replaced uint32_t with unsigned int to fix broken builds + on a couple of platforms + o Fix lookup with HOSTALIASES set + o adig: fix NAPTR parsing + o compiler warning cleanups + +Version 1.7.3 (June 11, 2010) + +Fixed: + + o builds on Android + o now includes all files necessary to build it (1.7.2 lacked a file) + +Version 1.7.2 (June 10, 2010) + +Changed: + + o Added ares_parse_mx_reply() + +Fixed: + + o ares_init: Last, not first instance of domain or search should win + o improve alternative definition of bool + o fix VS2010 compiler warnings + + +Version 1.7.1 (Mar 23, 2010) + +* May 31, 2010 (Jakub Hrozek) +- Use the last instance of domain/search, not the first one + +* March 23, 2010 (Daniel Stenberg) +- We switched from CVS to git. See http://github.com/bagder/c-ares + +* March 5, 2010 (Daniel Stenberg) +- Daniel Johnson provided fixes for building with the clang compiler. + +* March 5, 2010 (Yang Tse) +- Added IPv6 name servers support. Implementation has been based on code, + comments and feedback provided November and December of 2008 by Daniel + Stenberg, Gregor Jasny, Phil Blundell and myself, December 2009 by Cedric + Bail, and February 2010 by Jakub Hrozek on the c-ares mailing list. On + March I reviewed all that, selected the best of each, and adjusted or + extended parts of it to make the best fit. + + The external and visible result of all this is that two new functions are + added to the external API, ares_get_servers() and ares_set_servers(), which + becomes now the preferred way of getting and setting name servers for any + ares channel as these support both IPv4 and IPv6 name servers. + + In order to not break ABI compatibility, ares_init_options() with option + mask ARES_OPT_SERVERS and ares_save_options() may still be used in code + which is intended to run on IPv4-only stacks. But remember that these + functions do not support IPv6 name servers. This implies that if the user + is capable of defining or providing an IPv6 name server, and the app is + using ares_init_options() or ares_save_options() at some point to handle + the name servers, the app will likely lose IPv6 name servers. + +* January 28, 2010 (Daniel Stenberg) +- Tommie Gannert pointed out a silly bug in ares_process_fd() since it didn't + check for broken connections like ares_process() did. Based on that, I + merged the two functions into a single generic one with two front-ends. + +* December 29, 2009 (Yang Tse) +- Laszlo Tamas Szabo adjusted Makefile.msvc compiler options so that where + run-time error checks enabling compiler option /GZ was used it is replaced + with equivalent /RTCsu for Visual Studio 2003 and newer versions. Option + /GX is replaced with equivalent /EHsc for all versions. Also fixed socket + data type for internal configure_socket function. + +* December 21, 2009 (Yang Tse) +- Ingmar Runge noticed that Windows config-win32.h configuration file + did not include a definition for HAVE_CLOSESOCKET which resulted in + function close() being inappropriately used to close sockets. + +Version 1.7.0 (Nov 30, 2009) + +* November 26, 2009 (Yang Tse) +- Larry Lansing fixed ares_parse_srv_reply to properly parse replies + which might contain non-SRV answers, skipping over potential non-SRV + ones such as CNAMEs. + +* November 23, 2009 (Yang Tse) +- Changed naming convention for c-ares libraries built with MSVC, details + and build instructions provided in README.msvc file. + +* November 22, 2009 (Yang Tse) +- Jakub Hrozek fixed more function prototypes in man pages to sync them + with the ones declared in ares.h + +- Jakub Hrozek renamed addrttl and addr6ttl structs to ares_addrttl and + ares_addr6ttl in order to prevent name space pollution, along with + necessary changes to code base and man pages.This change does not break + ABI, there is no need to recompile existing applications. But existing + applications using these structs with the old name will need source code + adjustments when recompiled using c-ares 1.7.0. + +* November 21, 2009 (Yang Tse) +- Added manifest stuff to Makefile.msvc. + +* November 20, 2009 (Yang Tse) +- Fixed several function prototypes in man pages that were out of sync + with the ones declared in ares.h. Added ares_free_data() along with + man page. Updated ares_parse_srv_reply() and ares_parse_txt_reply() + with changes from Jakub Hrozek making these now return linked lists + instead of arrays, and merging the ares_free_data() adjustments. + +* November 10, 2009 (Yang Tse) +- Updated MSVC 6.0 project files to match settings from Makefile.msvc. + +* November 9, 2009 (Yang Tse) +- Makefile.msvc is now the reference method to build c-ares and sample + programs with any MSVC compiler or MS Visual Studio version. If no + option or target are specified it builds dynamic and static c-ares + libraries in debug and release flavours and also builds all sample + programs using each of the different c-ares libraries. + +* November 2, 2009 (Yang Tse) +- Renamed c-ares setup.h to ares_setup.h + +* October 31, 2009 (Yang Tse) +- Symbol hiding configure options are named now --enable-symbol-hiding + and --disable-symbol-hiding in an attempt to make them less ambiguous. + +* October 30, 2009 (Yang Tse) +- Many fixes for ares_parse_txt_reply() + +* October 29, 2009 (Daniel Stenberg) +- Jakub Hrozek added ares_parse_txt_reply() for TXT parsing + +* October 29, 2009 (Yang Tse) +- Updated MSVC 6.0 workspace and project files that allows building + dynamic and static c-ares libraries in debug and release flavours. + Additionally each of the three sample programs is built against + each of the four possible c-ares libraries, generating all this + a total number of 12 executables and 4 libraries. + +* October 28, 2009 (Yang Tse) +- Initial step towards the ability to reduce c-ares exported symbols + when built as a shared library based on the 'visibility' attribute + for GNUC and Intel compilers and based on __global for Sun compilers, + taking also in account __declspec function decoration for Win32 and + Symbian DLL's. + +* October 27, 2009 (Yang Tse) +- Fixed Pelles C Win32 target compilation issues. + +* October 23, 2009 (Yang Tse) +- John Engelhart noticed an unreleased problem relative to a duplicate + ARES_ECANCELLED error code value and missing error code description. + +* October 7, 2009 (Yang Tse) +- Overhauled ares__get_hostent() Fixing out of bounds memory overwrite + triggered with malformed /etc/hosts file. Improving parsing of /etc/hosts + file. Validating requested address family. Ensuring that failures always + return a NULL pointer. Adjusting header inclusions. + +* October 6, 2009 (Yang Tse) +- Fix ssize_t redefinition errors on WIN64 reported by Alexey Simak. + +* September 29, 2009 (Yang Tse) +- Make configure script also check if _REENTRANT definition is required to + make errno available as a preprocessor macro. + +* September 7, 2009 (Yang Tse) +- Add T_SRV portability check to ares_parse_srv_reply.c + +* 4 Sep 2009 (Daniel Stenberg) +- Jakub Hrozek added ares_parse_srv_reply() for SRV parsing + +* 3 Aug 2009 (Daniel Stenberg) +- Joshua Kwan fixed the init routine to fill in the defaults for stuff that + fails to get inited by other means. This fixes a case of when the c-ares + init fails when internet access is fone. + +- Timo Teras changed the reason code used in the resolve callback done when + ares_cancel() is used, to be ARES_ECANCELLED instead of ARES_ETIMEOUT to + better allow the callback to know what's happening. + +* 14 Jul 2009 (Guenter Knauf) +- renamed generated config.h to ares_config.h to avoid any future clashes + with config.h from other projects. + +* June 20 2009 (Yang Tse) +- Refactor how libraries are checked for connect() function in configure + script and check for connect() as it is done for other functions. + +* June 19 2009 (Yang Tse) +- Make sclose() function-like macro definition used to close a socket, + now solely based on HAVE_CLOSESOCKET and HAVE_CLOSESOCKET_CAMEL + config file preprocessor definitions + +* June 18 2009 (Yang Tse) +- Add CloseSocket camel case function check for configure script. + +* June 17 2009 (Yang Tse) +- Check for socket() and closesocket() as it is done for other functions + in configure script. + +* June 11 2009 (Yang Tse) +- Modified buildconf so that when automake runs it copies missing files + instead of symlinking them. + +* June 8 2009 (Yang Tse) +- Removed buildconf.bat from release and daily snapshot archives. This + file is only for CVS tree checkout builds. + +* May 26 2009 (Yang Tse) +- Added --enable-curldebug configure option to enable and disable building + with the low-level curl debug memory tracking 'feature' to allow decoupled + setting from --enable-debug, allowing again to build c-ares independently + out of the CVS tree. + + For the c-ares library option --enable-debug enables debug build features + which are _not_ related with memory tracking. For the c-ares library when + --enable-debug is given it does not enable the memory tracking feature. If + you wish to enable the curl debug memory tracking you must use configure + option --enable-curldebug explicitily to do so. + + Internally, definition of preprocessor symbol DEBUGBUILD restricts code + which is only compiled for debug enabled builds. And symbol CURLDEBUG is + used to differentiate code which is _only_ used for memory tracking. + + Make ares_init(), ares_dup() and ares_init_options() fail returning + ARES_ENOTINITIALIZED if library initialization has not been performed + calling ares_library_init(). + +* May 20 2009 (Yang Tse) +- Added ares_library_init() and ares_library_cleanup() man pages. + +* May 19 2009 (Yang Tse) +- Introduced ares_library_init() and ares_library_cleanup() functions. + + This is an API and ABI break for Win32/64 systems. Non-Win32/64 build targets + using c-ares 1.7.0 can still survive without calling these functions. Read all + the details on ares_library_init(3) and ares_library_cleanup(3) man pages that + are included. + + curl/libcurl 7.19.5 is fully compatible with c-ares 1.7.0 on all systems. + + In order to use c-ares 1.7.0 with curl/libcurl on Win32/64 systems it is + required that curl/libcurl is 7.19.5 or newer. In other words, it is not + possible on Win32/64 to use c-ares 1.7.0 with a curl/libcurl version less + than 7.19.5 + +* May 11 2009 (Daniel Stenberg) +- Gregor Jasny made c-ares link with libtool 's -export-symbols-regex option to + only expose functions starting with ares_. + +* May 7 2009 (Yang Tse) +- Fix an m4 overquoting triggering a spurious 'AS_TR_CPP' symbol definition + attempt in generated config.h + +* May 2 2009 (Yang Tse) +- Use a build-time configured ares_socklen_t data type instead of socklen_t. + +* April 21 2009 (Yang Tse) +- Moved potential inclusion of system's malloc.h and memory.h header files to + setup_once.h. Inclusion of each header file is based on the definition of + NEED_MALLOC_H and NEED_MEMORY_H respectively. + +* March 11 2009 (Yang Tse) +- Japheth Cleaver fixed acountry.c replacing u_long with unsigned long. + +* February 20 2009 (Yang Tse) +- Do not halt compilation when using VS2008 to build a Windows 2000 target. + +* February 3 2009 (Phil Blundell) +- If the server returns garbage or nothing at all in response to an AAAA query, + go on and ask for A records anyway. + +* January 31 2009 (Daniel Stenberg) +- ares_gethostbyname() now accepts 'AF_UNSPEC' as a family for resolving + either AF_INET6 or AF_INET. It works by accepting any of the looksups in the + hosts file, and it resolves the AAAA field with a fallback to A. + +* January 14 2009 (Daniel Stenberg) +- ares.h no longer uses the HAVE_STRUCT_IN6_ADDR define check, but instead it + now declares the private struct ares_in6_addr for all systems instead of + relying on one possibly not present in the system. + +* January 13 2009 (Phil Blundell) +- ares__send_query() now varies the retry timeout pseudo-randomly to avoid + packet storms when several queries were started at the same time. + +* January 11 2009 (Daniel Stenberg) +- Phil Blundell added the internal function ares__expand_name_for_response() + that is now used by the ares_parse_*_reply() functions instead of the + ares_expand_name() simply to easier return ARES_EBADRESP for the cases where + the name expansion fails as in responses that really isn't expected. + +Version 1.6.0 (Dec 9, 2008) + +* December 9 2008 (Gisle Vanem) + + Fixes for Win32 targets using the Watt-32 tcp/ip stack. + +* Dec 4 2008 (Daniel Stenberg) + + Gregor Jasny provided the patch that introduces ares_set_socket_callback(), + and I edited it to also get duped by ares_dup(). + +* Dec 3 2008 (Daniel Stenberg) + + API changes: + + I made sure the public ares_config struct looks like before and yet it + supports the ROTATE option thanks to c-ares now storing the "optmask" + internally. Thus we should be ABI compatible with the past release(s) + now. My efforts mentioned below should not break backwards ABI compliance. + + Here's how I suggest we proceed with the API: + + ares_init() will be primary "channel creator" function. + + ares_init_options() will continue to work exactly like now and before. For + starters, it will be the (only) way to set the existing options. + + ares_save_options() will continue to work like today, but will ONLY save + options that you can set today (including ARES_OPT_ROTATE actually) but new + options that we add may not be saved with this. + + Instead we introduce: + + ares_dup() that instead can make a new channel and clone the config used + from an existing channel. It will then clone all config options, including + future new things we add. + + ares_set_*() style functions that set (new) config options. As a start we + simply add these for new functionality, but over time we can also introduce + them for existing "struct ares_options" so that we can eventually deprecate + the two ares_*_options() functions. + + ares_get_*() style functions for extracting info from a channel handle that + should be used instead of ares_save_options(). + +* Nov 26 2008 (Yang Tse) +- Brad Spencer provided changes to allow buildconf to work on OS X. + +- Gerald Combs fixed a bug in ares_parse_ptr_reply() which would cause a + buffer to shrink instead of expand if a reply contained 8 or more records. + +* Nov 25 2008 (Yang Tse) +- In preparation for the upcomming IPv6 nameservers patch, the internal + ares_addr union is now changed into an internal struct which also holds + the address family. + +* Nov 19 2008 (Daniel Stenberg) +- Brad Spencer brought the new function ares_gethostbyname_file() which simply + resolves a host name from the given file, using the regular hosts syntax. + +* Nov 1 2008 (Daniel Stenberg) +- Carlo Contavalli added support for the glibc "rotate" option, as documented + in man resolv.conf: + + causes round robin selection of nameservers from among those listed. This + has the effect of spreading the query load among all listed servers, rather + than having all clients try the first listed server first every time. + + You can enable it with ARES_OPT_ROTATE + +* Oct 21 2008 (Yang Tse) + Charles Hardin added handling of EINPROGRESS for UDP connects. + +* Oct 18 2008 (Daniel Stenberg) + Charles Hardin made adig support a regular numerical dotted IP address for the + -s option as well. + +* Oct 7 2008 (Yang Tse) +- Added --enable-optimize configure option to enable and disable compiler + optimizations to allow decoupled setting from --enable-debug. + +* Oct 2 2008 (Yang Tse) +- Added --enable-warnings configure option to enable and disable strict + compiler warnings to allow decoupled setting from --enable-debug. + +* Sep 17 2008 (Yang Tse) +- Code reorganization to allow internal/private use of "nameser.h" to any + system that lacks arpa/nameser.h or arpa/nameser_compat.h header files. + +* Sep 16 2008 (Yang Tse) +- Code reorganization to allow internal/private use of ares_writev to any + system that lacks the writev function. + +* Sep 15 2008 (Yang Tse) +- Code reorganization to allow internal/private use of ares_strcasecmp to any + system that lacks the strcasecmp function. + +- Improve configure detection of some string functions. + +* Sep 11 2008 (Yang Tse) +- Code reorganization to allow internal/private use of ares_strdup to any + system that lacks the strdup function. + +Version 1.5.3 (Aug 29, 2008) + +* Aug 25 2008 (Yang Tse) +- Improvement by Brad House: + + This patch addresses an issue in which a response could be sent back to the + source port of a client from a different address than the request was made to. + This is one form of a DNS cache poisoning attack. + + The patch simply uses recvfrom() rather than recv() and validates that the + address returned from recvfrom() matches the address of the server we have + connected to. Only necessary on UDP sockets as they are connection-less, TCP + is unaffected. + +- Fix by George Neill: + Fixed compilation of acountry sample application failure on some systems. + +* Aug 4 2008 (Daniel Stenberg) +- Fix by Tofu Linden: + + The symptom: + * Users (usually, but not always) on 2-Wire routers and the Comcast service + and a wired connection to their router would find that the second and + subsequent DNS lookups from fresh processes using c-ares to resolve the same + address would cause the process to never see a reply (it keeps polling for + around 1m15s before giving up). + + The repro: + * On such a machine (and yeah, it took us a lot of QA to find the systems + that reproduce such a specific problem!), do 'ahost www.secondlife.com', + then do it again. The first process's lookup will work, subsequent lookups + will time-out and fail. + + The cause: + * init_id_key() was calling randomize_key() *before* it initialized + key->state, meaning that the randomness generated by randomize_key() is + immediately overwritten with deterministic values. (/dev/urandom was also + being read incorrectly in the c-ares version we were using, but this was + fixed in a later version.) + * This makes the stream of generated query-IDs from any new c-ares process + be an identical and predictable sequence of IDs. + * This makes the 2-Wire's default built-in DNS server detect these queries + as probable-duplicates and (erroneously) not respond at all. + + +* Aug 4 2008 (Yang Tse) +- Autoconf 2.62 has changed the behaviour of the AC_AIX macro which we use. + Prior versions of autoconf defined _ALL_SOURCE if _AIX was defined. 2.62 + version of AC_AIX defines _ALL_SOURCE and other four preprocessor symbols + no matter if the system is AIX or not. To keep the traditional behaviour, + and an uniform one across autoconf versions AC_AIX is replaced with our + own internal macro CARES_CHECK_AIX_ALL_SOURCE. + +* Aug 1 2008 (Yang Tse) +- Configure process now checks if the preprocessor _REENTRANT symbol is already + defined. If it isn't currently defined a set of checks are performed to test + if its definition is required to make visible to the compiler a set of *_r + functions. Finally, if _REENTRANT is already defined or needed it takes care + of making adjustments necessary to ensure that it is defined equally for the + configure process tests and generated config file. + +* Jul 20 2008 (Yang Tse) +- When recvfrom prototype uses a void pointer for arguments 2, 5 or 6 this will + now cause the definition, as appropriate, of RECVFROM_TYPE_ARG2_IS_VOID, + RECVFROM_TYPE_ARG5_IS_VOID or RECVFROM_TYPE_ARG6_IS_VOID. + +* Jul 17 2008 (Yang Tse) +- RECVFROM_TYPE_ARG2, RECVFROM_TYPE_ARG5 and RECVFROM_TYPE_ARG6 are now defined + to the data type pointed by its respective argument and not the pointer type. + +* Jul 16 2008 (Yang Tse) +- Improved configure detection of number of arguments for getservbyport_r. + Detection is now based on compilation checks instead of linker ones. + +- Configure process now checks availability of recvfrom() socket function and + finds out its return type and the types of its arguments. Added definitions + for non-configure systems config files, and introduced macro sreadfrom which + will be used on udp sockets as a recvfrom() wrapper in the future. + +* Jul 15 2008 (Yang Tse) +- Introduce definition of _REENTRANT symbol in setup.h to improve library + usability. Previously the configure process only used the AC_SYS_LARGEFILE + macro for debug builds, now it is also used for non-debug ones enabling the + use of configure options --enable-largefile and --disable-largefile which + might be needed for library compatibility. Remove checking the size of + curl_off_t, it is no longer needed. + +* Jul 3 2008 (Daniel Stenberg) +- Phil Blundell: If you ask ares_gethostbyname() to do an AF_INET6 lookup and + the target host has only A records, it automatically falls back to an + AF_INET lookup and gives you the A results. However, if the target host has + a CNAME record, this behaviour is defeated since the original query does + return some data even though ares_parse_aaa_reply() doesn't consider it + relevant. Here's a small patch to make it behave the same with and without + the CNAME. + +* Jul 2 2008 (Yang Tse) +- Fallback to gettimeofday when monotonic clock is unavailable at run-time. + +* Jun 30 2008 (Daniel Stenberg) + +- As was pointed out to me by Andreas Schuldei, the MAXHOSTNAMELEN define is + not posix or anything and thus c-ares failed to build on hurd (and possibly + elsewhere). The define was also somewhat artificially used in the windows + port. Now, I instead rewrote the use of gethostbyname to enlarge the host + name buffer in case of need and totally avoid the use of the MAXHOSTNAMELEN + define. I thus also removed the defien from the namser.h file where it was + once added for the windows build. + + I also fixed init_by_defaults() function to not leak memory in case if + error. + +* Jun 9 2008 (Yang Tse) + +- Make libcares.pc generated file for pkg-config include information relative + to the libraries needed for the static linking of c-ares. + +* May 30 2008 (Yang Tse) + +- Brad House fixed a missing header file inclusion in adig sample program. + +Version 1.5.2 (May 29, 2008) + +* May 13 2008 (Daniel Stenberg) + +- Introducing millisecond resolution support for the timeout option. See + ares_init_options()'s ARES_OPT_TIMEOUTMS. + +* May 9 2008 (Yang Tse) + +- Use monotonic time source if available, for private function ares__tvnow() + +* May 7 2008 (Daniel Stenberg) + +- Sebastian made c-ares able to return all PTR-records when doing reverse + lookups. It is not common practice to have multiple PTR-Records for a single + IP, but its perfectly legal and some sites have those. + +- Doug Goldstein provided a configure patch: updates autoconf 2.13 usage to + autoconf 2.57 usage (which is the version you have specified as the minimum + version). It's a minor change but it does clean up some warnings with newer + autoconf (specifically 2.62). + +* May 5 2008 (Yang Tse) + +- Improved parsing of resolver configuration files. + +* April 4 2008 (Daniel Stenberg) + +- Eino Tuominen improved the code when a file is used to seed the randomizer. + +- Alexey Simak made adig support NAPTR records + +- Alexey Simak fixed the VC dsp file by adding the missing source file + ares_expand_string.c + +* December 11 2007 (Gisle Vanem) + +- Added another sample application; acountry.c which converts an + IPv4-address(es) and/or host-name(s) to country-name and country-code. + This uses the service of the DNSBL at countries.nerd.dk. + +* December 3 2007 (Daniel Stenberg) + +- Brad Spencer fixed the configure script to assume that there's no + /dev/urandom when built cross-compiled as then the script cannot check for + it. + +- Erik Kline cleaned up ares_gethostbyaddr.c:next_lookup() somewhat + +Version 1.5.1 (Nov 21, 2007) + +* November 21 2007 (Daniel Stenberg) + +- Robin Cornelius pointed out that ares_llist.h was missing in the release + archive for 1.5.0 + +Version 1.5.0 (Nov 21, 2007) + +* October 2 2007 (Daniel Stenberg) + +- ares_strerror() segfaulted if the input error number was out of the currently + supported range. + +- Yang Tse: Avoid a segfault when generating a DNS "Transaction ID" in + internal function init_id_key() under low memory conditions. + +* September 28 2007 (Daniel Stenberg) + +- Bumped version to 1.5.0 for next release and soname bumped to 2 due to ABI + and API changes in the progress callback (and possibly more coming up from + Steinar) + +* September 28 2007 (Steinar H. Gunderson) + +- Don't skip a server if it's the only one. (Bugfix from the Google tree.) + +- Made the query callbacks receive the number of timeouts that happened during + the execution of a query, and updated documentation accordingly. (Patch from + the Google tree.) + +- Support a few more socket options: ARES_OPT_SOCK_SNDBUF and + ARES_OPT_SOCK_RCVBUF + +- Always register for TCP events even if there are no outstanding queries, as + the other side could always close the connection, which is a valid event + which should be responded to. + +* September 22 2007 (Daniel Stenberg) + +- Steinar H. Gunderson fixed: Correctly clear sockets from the fd_set on in + several functions (write_tcp_data, read_tcp_data, read_udp_packets) so that + if it fails and the socket is closed the following code doesn't try to use + the file descriptor. + +- Steinar H. Gunderson modified c-ares to now also do to DNS retries even when + TCP is used since there are several edge cases where it still makes sense. + +- Brad House provided a fix for ares_save_options(): + + Apparently I overlooked something with the ares_save_options() where it + would try to do a malloc(0) when no options of that type needed to be saved. + On most platforms, this was fine because malloc(0) doesn't actually return + NULL, but on AIX it does, so ares_save_options would return ARES_ENOMEM. + +* July 14 2007 (Daniel Stenberg) + +- Vlad Dinulescu fixed two outstanding valgrind reports: + + 1. In ares_query.c , in find_query_by_id we compare q->qid (which is a short + int variable) with qid, which is declared as an int variable. Moreover, + DNS_HEADER_SET_QID is used to set the value of qid, but DNS_HEADER_SET_QID + sets only the first two bytes of qid. I think that qid should be declared as + "unsigned short" in this function. + + 2. The same problem occurs in ares_process.c, process_answer() . query->qid + (an unsigned short integer variable) is compared with id, which is an + integer variable. Moreover, id is initialized from DNS_HEADER_QID which sets + only the first two bytes of id. I think that the id variable should be + declared as "unsigned short" in this function. + + Even after declaring these variables as "unsigned short", the valgrind + errors are still there. Which brings us to the third problem. + + 3. The third problem is that Valgrind assumes that query->qid is not + initialised correctly. And it does that because query->qid is set from + DNS_HEADER_QID(qbuf); Valgrind says that qbuf has unitialised bytes. And + qbuf has uninitialised bytes because of channel->next_id . And next_id is + set by ares_init.c:ares__generate_new_id() . I found that putting short r=0 + in this function (instead of short r) makes all Valgrind warnings go away. + I have studied ares__rc4() too, and this is the offending line: + + buffer_ptr[counter] ^= state[xorIndex]; (ares_query.c:62) + + This is what triggers Valgrind.. buffer_ptr is unitialised in this function, + and by applying ^= on it, it remains unitialised. + +Version 1.4.0 (June 8, 2007) + +* June 4 2007 (Daniel Stenberg) + +- James Bursa reported a major memory problem when resolving multi-IP names + and I found and fixed the problem. It was added by Ashish Sharma's patch + two days ago. + + When I then tried to verify multiple entries in /etc/hosts after my fix, I + got another segfault and decided this code was not ripe for inclusion and I + reverted the patch. + +* June 2 2007 + +- Brad Spencer found and fixed three flaws in the code, found with the new + gcc 4.2.0 warning: -Waddress + +- Brad House fixed VS2005 compiler warnings due to time_t being 64bit. + He also made recent Microsoft compilers use _strdup() instead of strdup(). + +- Brad House's man pages for ares_save_options() and ares_destroy_options() + were added. + +- Ashish Sharma provided a patch for supporting multiple entries in the + /etc/hosts file. Patch edited for coding style and functionality by me + (Daniel). + +* May 30 2007 + +- Shmulik Regev brought cryptographically secure transaction IDs: + + The c-ares library implementation uses a DNS "Transaction ID" field that is + seeded with a pseudo random number (based on gettimeofday) which is + incremented (++) between consecutive calls and is therefore rather + predictable. In general, predictability of DNS Transaction ID is a well + known security problem (e.g. + http://bak.spc.org/dms/archive/dns_id_attack.txt) and makes a c-ares based + implementation vulnerable to DNS poisoning. Credit goes to Amit Klein + (Trusteer) for identifying this problem. + + The patch I wrote changes the implementation to use a more secure way of + generating unique IDs. It starts by obtaining a key with reasonable entropy + which is used with an RC4 stream to generate the cryptographically secure + transaction IDs. + + Note that the key generation code (in ares_init:randomize_key) has two + versions, the Windows specific one uses a cryptographically safe function + provided (but undocumented :) by the operating system (described at + http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx). The + default implementation is a bit naive and uses the standard 'rand' + function. Surely a better way to generate random keys exists for other + platforms. + + The patch can be tested by using the adig utility and using the '-s' option. + +- Brad House added ares_save_options() and ares_destroy_options() that can be + used to keep options for later re-usal when ares_init_options() is used. + + Problem: Calling ares_init() for each lookup can be unnecessarily resource + intensive. On windows, it must LoadLibrary() or search the registry + on each call to ares_init(). On unix, it must read and parse + multiple files to obtain the necessary configuration information. In + a single-threaded environment, it would make sense to only + ares_init() once, but in a heavily multi-threaded environment, it is + undesirable to ares_init() and ares_destroy() for each thread created + and track that. + + Solution: Create ares_save_options() and ares_destroy_options() functions to + retrieve and free options obtained from an initialized channel. The + options populated can be used to pass back into ares_init_options(), + it should populate all needed fields and not retrieve any information + from the system. Probably wise to destroy the cache every minute or + so to prevent the data from becoming stale. + +- Daniel S added ares_process_fd() to allow applications to ask for processing + on specific sockets and thus avoiding select() and associated + functions/macros. This function will be used by upcoming libcurl releases + for this very reason. It also made me export the ares_socket_t type in the + public ares.h header file, since ares_process_fd() uses that type for two of + the arguments. + +* May 25 2007 + +- Ravi Pratap fixed a flaw in the init_by_resolv_conf() function for windows + that could cause it to return a bad return code. + +* April 16 2007 + +- Yang Tse: Provide ares_getopt() command-line parser function as a source + code helper function, not belonging to the actual c-ares library. + +* February 19 2007 + +- Vlad Dinulescu added ares_parse_ns_reply(). + +* February 13 2007 + +- Yang Tse: Fix failure to get the search sequence of /etc/hosts and + DNS from /etc/nsswitch.conf, /etc/host.conf or /etc/svc.conf when + /etc/resolv.conf did not exist or was unable to read it. + +* November 22 2006 + +- Install ares_dns.h too + +- Michael Wallner fixed this problem: When I set domains in the options + struct, and there are domain/search entries in /etc/resolv.conf, the domains + of the options struct will be overridden. + +* November 6 2006 + +- Yang Tse removed a couple of potential zero size memory allocations. + +- Andreas Rieke fixed the line endings in the areslib.dsp file that I (Daniel) + broke in the 1.3.2 release. We should switch to a system where that file is + auto-generated. We could rip some code for that from curl... + +Version 1.3.2 (November 3, 2006) + +* October 12 2006 + +- Prevent ares_getsock() to overflow if more than 16 sockets are used. + +* September 11 2006 + +- Guilherme Balena Versiani: I noted a strange BUG in Win32 port + (ares_init.c/get_iphlpapi_dns_info() function): when I disable the network + by hand or disconnect the network cable in Windows 2000 or Windows XP, my + application gets 127.0.0.1 as the only name server. The problem comes from + 'GetNetworkParams' function, that returns the empty string "" as the only + name server in that case. Moreover, the Windows implementation of + inet_addr() returns INADDR_LOOPBACK instead of INADDR_NONE. + +* August 29 2006 + +- Brad Spencer did + + o made ares_version.h use extern "C" for c++ compilers + o fixed compiler warnings in ares_getnameinfo.c + o fixed a buffer position init for TCP reads + +* August 3 2006 + +- Ravi Pratap fixed ares_getsock() to actually return the proper bitmap and + not always zero! + +Version 1.3.1 (June 24, 2006) + +* July 23, 2006 + +- Gisle Vanem added getopt() to the ahost program. Currently accepts + only [-t {a|aaaa}] to specify address family in ares_gethostbyname(). + +* June 19, 2006 + +- (wahern) Removed "big endian" DNS section and RR data integer parser + macros from ares_dns.h, which break c-ares on my Sparc64. Bit-wise + operations in C operate on logical values. And in any event the octets are + already in big-endian (aka network) byte order so they're being reversed + (thus the source of the breakage). + +* June 18, 2006 + +- William Ahern handles EAGAIN/EWOULDBLOCK errors in most of the I/O calls + from area_process.c. + + TODO: Handle one last EAGAIN for a UDP socket send(2) in + ares__send_query(). + +* May 10, 2006 + +- Bram Matthys brought my attention to a libtool peculiarity where detecting + things such as C++ compiler actually is a bad thing and since we don't need + that detection I added a work-around, much inspired by a previous patch by + Paolo Bonzini. This also shortens the configure script quite a lot. + +* May 3, 2006 + +- Nick Mathewson added the ARES_OPT_SOCK_STATE_CB option that when set makes + c-ares call a callback on socket state changes. A better way than the + ares_getsock() to get full control over the socket state. + +* January 9, 2006 + +- Alexander Lazic improved the getservbyport_r() configure check. + +* January 6, 2006 + +- Alexander Lazic pointed out that the buildconf should use the ACLOCAL_FLAGS + variable for easier controlling what it does and how it runs. + +* January 5, 2006 + +- James Bursa fixed c-ares to find the hosts file on RISC OS, and made it + build with newer gcc versions that no longer defines "riscos". + +* December 22 + +- Daniel Stenberg added ares_getsock() that extracts the set of sockets to + wait for action on. Similar to ares_fds() but not restricted to using + select() for the waiting. + +* November 25 + +- Yang Tse fixed some send() / recv() compiler warnings + +* September 18 + +- Added constants that will be used by ares_getaddrinfo + +- Made ares_getnameinfo use the reentrant getservbyport (getservbyport_r) if it + is available to ensure it works properly in a threaded environment. + +* September 10 + +- configure fix for detecting a member in the sockaddr_in6 struct which failed + on ipv6-enabled HP-UX 11.00 + +Version 1.3.0 (August 29, 2005) + +* August 21 + +- Alfredo Tupone provided a fix for the Windows code in get_iphlpapi_dns_info() + when getting the DNS server etc. + +* June 19 + +- Added some checks for the addrinfo structure. + +* June 2 + +- William Ahern: + + Make UDP sockets non-blocking. I've confirmed that at least on Linux 2.4 a + read event can come back from poll() on a valid SOCK_DGRAM socket but + recv(2) will still block. This patch doesn't ignore EAGAIN in + read_udp_packets(), though maybe it should. (This patch was edited by Daniel + Stenberg and a new configure test was added (imported from curl's configure) + to properly detect what non-blocking socket approach to use.) + + I'm not quite sure how this was happening, but I've been seeing PTR queries + which seem to return empty responses. At least, they were empty when calling + ares_expand_name() on the record. Here's a patch which guarantees to + NUL-terminate the expanded name. The old behavior failed to NUL-terminate if + len was 0, and this was causing strlen() to run past the end of the buffer + after calling ares_expand_name() and getting ARES_SUCCESS as the return + value. If q is not greater than *s then it's equal and *s is always + allocated with at least one byte. + +* May 16 + +- Added ares_getnameinfo which mimics the getnameinfo API (another feature + that could use testing). + +* May 14 + +- Added an inet_ntop function from BIND for systems that do not have it. + +* April 9 + +- Made sortlist support IPv6 (this can probably use some testing). + +- Made sortlist support CIDR matching for IPv4. + +* April 8 + +- Added preliminary IPv6 support to ares_gethostbyname. Currently, sortlist + does not work with IPv6. Also provided an implementation of bitncmp from + BIND for systems that do not supply this function. This will be used to add + IPv6 support to sortlist. + +- Made ares_gethostbyaddr support IPv6 by specifying AF_INET6 as the family. + The function can lookup IPv6 addresses both from files (/etc/hosts) and + DNS lookups. + +* April 7 + +- Tupone Alfredo fixed includes of arpa/nameser_compat.h to build fine on Mac + OS X. + +* April 5 + +- Dominick Meglio: Provided implementations of inet_net_pton and inet_pton + from BIND for systems that do not include these functions. + +* March 11, 2005 + +- Dominick Meglio added ares_parse_aaaa_reply.c and did various + adjustments. The first little steps towards IPv6 support! + +* November 7 + +- Fixed the VC project and makefile to use ares_cancel and ares_version + +* October 24 + +- The released ares_version.h from 1.2.1 says 1.2.0 due to a maketgz flaw. + This is now fixed. + +Version 1.2.1 (October 20, 2004) + +* September 29 + +- Henrik Stoerner fix: got a report that Tru64 Unix (the unix from Digital + when they made Alpha's) uses /etc/svc.conf for the purpose fixed below for + other OSes. He made c-ares check for and understand it if present. + +- Now c-ares will use local host name lookup _before_ DNS resolving by default + if nothing else is told. + +* September 26 + +- Henrik Stoerner: found out that c-ares does not look at the /etc/host.conf + file to determine the sequence in which to search /etc/hosts and DNS. So on + systems where this order is defined by /etc/host.conf instead of a "lookup" + entry in /etc/resolv.conf, c-ares will always default to looking in DNS + first, and /etc/hosts second. + + c-ares now looks at + + 1) resolv.conf (for the "lookup" line); + 2) nsswitch.fon (for the "hosts:" line); + 3) host.conf (for the "order" line). + + First match wins. + +- Dominick Meglio patched: C-ares on Windows assumed that the HOSTS file is + located in a static location. It assumed + C:\Windows\System32\Drivers\Etc. This is a poor assumption to make. In fact, + the location of the HOSTS file can be changed via a registry setting. + + There is a key called DatabasePath which specifies the path to the HOSTS + file: + http://www.microsoft.com/technet/itsolutions/network/deploy/depovg/tcpip2k.mspx + + The patch will make c-ares correctly consult the registry for the location + of this file. + +* August 29 + +- Gisle Vanem fixed the MSVC build files. + +* August 20 + +- Gisle Vanem made c-ares build and work with his Watt-32 TCP/IP stack. + +* August 13 + +- Harshal Pradhan made a minor syntax change in ares_init.c to make it build + fine with MSVC 7.1 + +* July 24 + +- Made the lib get built static only if --enable-debug is used. + +- Gisle Vanem fixed: + + Basically in loops like handle_errors(), 'query->next' was assigned a local + variable and then query was referenced after the memory was freed by + next_server(). I've changed that so next_server() and end_query() returns + the next query. So callers should use this ret-value. + + The next problem was that 'server->tcp_buffer_pos' had a random value at + entry to 1st recv() (luckily causing Winsock to return ENOBUFS). + + I've also added a ares_writev() for Windows to streamline the code a bit + more. + +* July 20 +- Fixed a few variable return types for some system calls. Made configure + check for ssize_t to make it possible to use that when receiving the send() + error code. This is necessary to prevent compiler warnings on some systems. + +- Made configure create config.h, and all source files now include setup.h that + might include the proper config.h (or a handicrafted alternative). + +- Switched to 'ares_socket_t' type for sockets in ares, since Windows don't + use 'int' for that. + +- automake-ified and libool-ified c-ares. Now it builds libcares as a shared + lib on most platforms if wanted. (This bloated the size of the release + archive with another 200K!) + +- Makefile.am now uses Makefile.inc for the c sources, h headers and man + pages, to make it easier for other makefiles to use the exact same set of + files. + +- Adjusted 'maketgz' to use the new automake magic when building distribution + archives. + +- Anyone desires HTML and/or PDF versions of the man pages in the release + archives? + +* July 3 +- Günter Knauf made c-ares build and run on Novell Netware. + +* July 1 +- Gisle Vanem provided Makefile.dj to build with djgpp, added a few more djgpp + fixes and made ares not use 'errno' to provide further info on Windows. + +* June 30 +- Gisle Vanem made it build with djgpp and run fine with the Watt-32 stack. + +* June 10 +- Gisle Vanem's init patch for Windows: + + The init_by_resolv_conf() function fetches the DNS-server(s) + from a series of registry branches. + + This can be wrong in the case where DHCP has assigned nameservers, but the + user has overridden these servers with other prefered settings. Then it's + wrong to use the DHCPNAMESERVER setting in registry. + + In the case of no global DHCP-assigned or fixed servers, but DNS server(s) + per adapter, one has to query the adapter branches. But how can c-ares know + which adapter is valid for use? AFAICS it can't. There could be one adapter + that is down (e.g. a VPN adapter). + + So it's better to leave this to the IP Helper API (iphlapi) available in + Win-98/2000 and later. My patch falls-back to the old way if not available. + +* June 8 +- James Bursa fixed an init issue for RISC OS. + +* May 11 +- Nico Stappenbelt reported that when processing domain and search lines in + the resolv.conf file, the first entry encountered is processed and used as + the search list. According to the manual pages for both Linux, Solaris and + Tru64, the last entry of either a domain or a search field is used. + + This is now adjusted in the code + +Version 1.2.0 (April 13, 2004) + +* April 2, 2004 +- Updated various man pages to look nicer when converted to HTML on the web + site. + +* April 1, 2004 +- Dirk Manske provided a new function that is now named ares_cancel(). It is + used to cancel/cleanup a resolve/request made using ares functions on the + given ares channel. It does not destroy/kill the ares channel itself. + +- Dominick Meglio cleaned up the formatting in several man pages. + +* March 30, 2004 +- Dominick Meglio's new ares_expand_string. A helper function when decoding + incoming DNS packages. + +- Daniel Stenberg modified the Makefile.in to use a for loop for the man page + installation to improve overview and make it easier to add man pages. + +Version 1.1.0 (March 11, 2004) + +* March 9, 2004 +- Gisle Vanem improved build on Windows. + +* February 25, 2004 +- Dan Fandrich found a flaw in the Feb 22 fix. + +- Added better configure --enable-debug logic (taken from the curl configure + script). Added acinclude.m4 to the tarball. + +* February 23, 2004 +- Removed ares_free_errmem(), the function, the file and the man page. It was + not used and it did nothing. + +- Fixed a lot of code that wasn't "64bit clean" and thus caused a lot of + compiler warnings on picky compilers. + +* February 22, 2004 +- Dominick Meglio made ares init support multiple name servers in the + NameServer key on Windows. + +* February 16, 2004 +- Modified ares_private.h to include libcurl's memory debug header if + CURLDEBUG is set. This makes all the ares-functions supervised properly by + the curl test suite. This also forced me to add inclusion of the + ares_private.h header in a few more files that are using some kind of + memory-related resources. + +- Made the makefile only build ahost and adig if 'make demos' is used. + +* February 10, 2004 +- Dirk Manske made ares_version.h installed with 'make install' + +* February 4, 2004 +- ares_free_errmem() is subject for removal, it is simply present for future + purposes, and since we removed the extra parameter in strerror() it won't + be used by c-ares! +- configure --enable-debug now enables picky compiler options if gcc is used +- fixed several compiler warnings --enable-debug showed and Joerg Mueller-Tolk + reported + +Version 1.0.0 (February 3, 2004) + +* February 3, 2004 +- now we produce the libcares.a library instead of the previous libares.a + since we are no longer compatible + +* February 2, 2004 + +- ares_strerror() has one argument less. This is the first official + modification of the existing provided ares API. + +* January 29, 2004 + +- Dirk Manske fixed how the socket is set non-blocking. + +* January 4, 2004 + +- Dominick Meglio made the private gettimeofday() become ares_gettimeofday() + instead in order to not pollute the name space and risk colliding with + other libraries' versions of this function. + +* October 24, 2003. Daniel Stenberg + + Added ares_version(). + +Version 1.0-pre1 (8 October 2003) + +- James Bursa made it run on RISC OS + +- Dominick Meglio made it run fine on NT4 + +- Duncan Wilcox made it work fine on Mac OS X + +- Daniel Stenberg adjusted the windows port + +- liren at vivisimo.com made the initial windows port + +* Imported the sources from ares 1.1.1 diff --git a/src/rt/libuv/src/ares/CMakeLists.txt b/src/rt/libuv/src/ares/CMakeLists.txt new file mode 100644 index 00000000000..7bbb95b879c --- /dev/null +++ b/src/rt/libuv/src/ares/CMakeLists.txt @@ -0,0 +1,22 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${node_platform}-${cares_arch}) +add_definitions(-DHAVE_CONFIG_H=1) + +include(CheckLibraryExists) +check_library_exists(socket socket "" HAVE_SOCKET_LIB) +check_library_exists(nsl gethostbyname "" HAVE_NSL_LIB) + +file(GLOB lib_sources *.c) +add_library(cares ${lib_sources}) + +if(${HAVE_SOCKET_LIB}) + set(cares_libs ${cares_libs} socket) +endif() + +if(${HAVE_NSL_LIB}) + set(cares_libs ${cares_libs} nsl) +endif() + +if(cares_libs) + target_link_libraries(cares ${cares_libs}) +endif() diff --git a/src/rt/libuv/src/ares/NEWS b/src/rt/libuv/src/ares/NEWS new file mode 100644 index 00000000000..95a2eeea274 --- /dev/null +++ b/src/rt/libuv/src/ares/NEWS @@ -0,0 +1,21 @@ +Major changes since: +* see the CHANGES file + +Major changes in release 1.1.1: +* ares should now compile as C++ code (no longer uses reserved word + "class"). +* Added SRV support to adig test program. +* Fixed a few error handling bugs in query processing. + +Major changes in release 1.1.0: +* Added ares_free_string() function so that memory can be freed in the + same layer as it is allocated, a desirable feature in some + environments. +* A few of the ares_dns.h macros are fixed to use the proper bitwise + operator. +* Fixed a couple of fenceposts fixed in ares_expand_name()'s + bounds-checking. +* In process_timeouts(), extract query->next before calling + next_server() and possibly freeing the query structure. +* Casted arguments to ctype macros casted to unsigned char, since not + all char values are valid inputs to those macros according to ANSI. diff --git a/src/rt/libuv/src/ares/README b/src/rt/libuv/src/ares/README new file mode 100644 index 00000000000..56a43c53a74 --- /dev/null +++ b/src/rt/libuv/src/ares/README @@ -0,0 +1,60 @@ +c-ares +====== + +This is c-ares, an asynchronous resolver library. It is intended for +applications which need to perform DNS queries without blocking, or need to +perform multiple DNS queries in parallel. The primary examples of such +applications are servers which communicate with multiple clients and programs +with graphical user interfaces. + +The full source code is available in the 'c-ares' release archives, and in a +git repository: http://github.com/bagder/c-ares + +If you find bugs, correct flaws, have questions or have comments in general in +regard to c-ares (or by all means the original ares too), get in touch with us +on the c-ares mailing list: http://cool.haxx.se/mailman/listinfo/c-ares + +c-ares is of course distributed under the same MIT-style license as the +original ares. + +You'll find all c-ares details and news here: + + http://c-ares.haxx.se/ + + +NOTES FOR C-ARES HACKERS + +The following notes apply to c-ares version 1.7.0 and later. + +* The distributed ares_build.h file is only intended to be used on systems + which can not run the also distributed configure script. + +* The distributed ares_build.h file is generated as a copy of ares_build.h.dist + when the c-ares source code distribution archive file is originally created. + +* If you check out from git on a non-configure platform, you must run the + appropriate buildconf* script to set up ares_build.h and other local files + before being able of compiling the library. + +* On systems capable of running the configure script, the configure process + will overwrite the distributed ares_build.h file with one that is suitable + and specific to the library being configured and built, this new file is + generated from the ares_build.h.in template file. + +* If you intend to distribute an already compiled c-ares library you _MUST_ + also distribute along with it the generated ares_build.h which has been + used to compile it. Otherwise the library will be of no use for the users of + the library that you have built. It is _your_ responsibility to provide this + file. No one at the c-ares project can know how you have built the library. + +* File ares_build.h includes platform and configuration dependent info, + and must not be modified by anyone. Configure script generates it for you. + +* We cannot assume anything else but very basic compiler features being + present. While c-ares requires an ANSI C compiler to build, some of the + earlier ANSI compilers clearly can't deal with some preprocessor operators. + +* Newlines must remain unix-style for older compilers' sake. + +* Comments must be written in the old-style /* unnested C-fashion */ + diff --git a/src/rt/libuv/src/ares/README.cares b/src/rt/libuv/src/ares/README.cares new file mode 100644 index 00000000000..aca54c8cd1f --- /dev/null +++ b/src/rt/libuv/src/ares/README.cares @@ -0,0 +1,13 @@ +c-ares +====== + +This package is based on ares 1.1.1 (written by Greg Hudson). I decided to +fork and release a separate project since the ares author didn't want the +improvements that were vital for our use of it. + +This package is dubbed 'c-ares' since I (Daniel Stenberg) wanted this for use +within the curl project (hence the letter C) and it makes a nice pun. Also, +c-ares is not API compatible with ares: a new name makes that more obvious to +the public. + +The original libares was distributed at athena-dist.mit.edu:pub/ATHENA/ares. diff --git a/src/rt/libuv/src/ares/README.msvc b/src/rt/libuv/src/ares/README.msvc new file mode 100644 index 00000000000..9c1163ac5f1 --- /dev/null +++ b/src/rt/libuv/src/ares/README.msvc @@ -0,0 +1,118 @@ + + + ___ __ _ _ __ ___ ___ + / __| ___ / _` | '__/ _ \/ __| + | (_ |___| (_| | | | __/\__ \ + \___| \__,_|_| \___||___/ + + + How to build c-ares using MSVC or Visual Studio + ================================================= + + + + How to build using MSVC from the command line + --------------------------------------------- + + Open a command prompt window and ensure that the environment is properly + set up in order to use MSVC or Visual Studio compiler tools. + + Change to c-ares source folder where Makefile.msvc file is located and run: + + > nmake -f Makefile.msvc + + This will build all c-ares libraries as well as three sample programs. + + Once the above command has finished a new folder named MSVCXX will exist + below the folder where makefile.msvc is found. The name of the folder + depends on the MSVC compiler version being used to build c-ares. + + Below the MSVCXX folder there will exist four folders named 'cares', + 'ahost', 'acountry', and 'adig'. The 'cares' folder is the one that + holds the c-ares libraries you have just generated, the other three + hold sample programs that use the libraries. + + The above command builds four versions of the c-ares library, dynamic + and static versions and each one in release and debug flavours. Each + of these is found in folders named dll-release, dll-debug, lib-release, + and lib-debug, which hang from the 'cares' folder mentioned above. Each + sample program also has folders with the same names to reflect which + library version it is using. + + + How to build using Visual Studio 6 IDE + -------------------------------------- + + A VC++ 6.0 reference workspace (vc6aws.dsw) is available within the 'vc' + folder to allow proper building of the library and sample programs. + + 1) Open the vc6aws.dsw workspace with MSVC6's IDE. + 2) Select 'Build' from top menu. + 3) Select 'Batch Build' from dropdown menu. + 4) Make sure that the sixteen project configurations are 'checked'. + 5) Click on the 'Build' button. + 6) Once the sixteen project configurations are built you are done. + + Dynamic and static c-ares libraries are built in debug and release flavours, + and can be located each one in its own subdirectory, dll-debug, dll-release, + lib-debug and lib-release, all of them below the 'vc\cares' subdirectory. + + In the same way four executable versions of each sample program are built, + each using its respective library. The resulting sample executables are + located in its own subdirectory, dll-debug, dll-release, lib-debug and + lib-release, below the 'vc\acountry', 'vc\adig' and 'vc\ahost'folders. + + These reference VC++ 6.0 configurations are generated using the dynamic CRT. + + + How to build using Visual Studio 2003 or newer IDE + -------------------------------------------------- + + First you have to convert the VC++ 6.0 reference workspace and project files + to the Visual Studio IDE version you are using, following next steps: + + 1) Open vc\vc6aws.dsw with VS20XX. + 2) Allow VS20XX to update all projects and workspaces. + 3) Save ALL and close VS20XX. + 4) Open vc\vc6aws.sln with VS20XX. + 5) Select batch build, check 'all' projects and click 'build' button. + + Same comments relative to generated files and folders as done above for + Visual Studio 6 IDE apply here. + + + Relationship between c-ares library file names and versions + ----------------------------------------------------------- + + c-ares static release library version files: + + libcares.lib -> static release library + + c-ares static debug library version files: + + libcaresd.lib -> static debug library + + c-ares dynamic release library version files: + + cares.dll -> dynamic release library + cares.lib -> import library for the dynamic release library + cares.exp -> export file for the dynamic release library + + c-ares dynamic debug library version files: + + caresd.dll -> dynamic debug library + caresd.lib -> import library for the dynamic debug library + caresd.exp -> export file for the dynamic debug library + caresd.pdb -> debug symbol file for the dynamic debug library + + + How to use c-ares static libraries + ---------------------------------- + + When using the c-ares static library in your program, you will have to + define preprocessor symbol CARES_STATICLIB while building your program, + otherwise you will get errors at linkage stage. + + +Have Fun! + diff --git a/src/rt/libuv/src/ares/README.node b/src/rt/libuv/src/ares/README.node new file mode 100644 index 00000000000..17503096fdd --- /dev/null +++ b/src/rt/libuv/src/ares/README.node @@ -0,0 +1,21 @@ +Library: c-ares, DNS resolver + +Version: 1.7.3 (11 June, 2010) + +Authors: Greg Hudson, Daniel Stenberg + +License: MIT + +Notes: + +Just use waf instead of the autoconf based configure script. Delete most of +the documentation and other files distributed with it. To upgrade, run +./configure on linux, macintosh, solaris (and other supported platforms) and +copy +- ares_config.h +- ares_setup.h +- ares_build.h +into the appropriate directory. + + + diff --git a/src/rt/libuv/src/ares/RELEASE-NOTES b/src/rt/libuv/src/ares/RELEASE-NOTES new file mode 100644 index 00000000000..639a314e196 --- /dev/null +++ b/src/rt/libuv/src/ares/RELEASE-NOTES @@ -0,0 +1,25 @@ +c-ares version 1.7.4 + +Changed: + + o local-bind: Support binding to local interface/IPs, see + ares_set_local_ip4, ares_set_local_ip6, ares_set_local_dev + +Fixed: + + o memory leak in ares_getnameinfo + o add missing break that caused get_ares_servers to fail + o ares_parse_a_reply: fix CNAME response parsing + o init_by_options: don't copy an empty sortlist + o Replaced uint32_t with unsigned int to fix broken builds + on a couple of platforms + o Fix lookup with HOSTALIASES set + o adig: fix NAPTR parsing + o compiler warning cleanups + +Thanks go to these friendly people for their efforts and contributions: + + Andrew C. Morrow, Ben Greear, Ben Noordhuis, Daniel Stenberg, + Guenter Knauf, Mike Crowe, Patrik Thunstrom, Yang Tse + +Have fun! diff --git a/src/rt/libuv/src/ares/TODO b/src/rt/libuv/src/ares/TODO new file mode 100644 index 00000000000..fa31cea6fb7 --- /dev/null +++ b/src/rt/libuv/src/ares/TODO @@ -0,0 +1,23 @@ +TODO +==== + +ares_reinit() + +- To allow an app to force a re-read of /etc/resolv.conf etc, pretty much + like the res_init() resolver function offers + +ares_gethostbyname + +- When built to support IPv6, it needs to also support PF_UNSPEC or similar, + so that an application can ask for any protocol and then c-ares would return + all known resolves and not just explicitly IPv4 _or_ IPv6 resolves. + +ares_process + +- Upon next ABI breakage ares_process() should be changed to return 'int' + and return ARES_ENOTINITIALIZED if ares_library_init() has not been called. + +ares_process_fd + +- Upon next ABI breakage ares_process_fd() should be changed to return + 'int' and return ARES_ENOTINITIALIZED if library has not been initialized. diff --git a/src/rt/libuv/src/ares/ares__close_sockets.c b/src/rt/libuv/src/ares/ares__close_sockets.c new file mode 100644 index 00000000000..5d391a9ef2e --- /dev/null +++ b/src/rt/libuv/src/ares/ares__close_sockets.c @@ -0,0 +1,66 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#include +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "ares.h" +#include "ares_private.h" + +void ares__close_sockets(ares_channel channel, struct server_state *server) +{ + struct send_request *sendreq; + + /* Free all pending output buffers. */ + while (server->qhead) + { + /* Advance server->qhead; pull out query as we go. */ + sendreq = server->qhead; + server->qhead = sendreq->next; + if (sendreq->data_storage != NULL) + free(sendreq->data_storage); + free(sendreq); + } + server->qtail = NULL; + + /* Reset any existing input buffer. */ + if (server->tcp_buffer) + free(server->tcp_buffer); + server->tcp_buffer = NULL; + server->tcp_lenbuf_pos = 0; + + /* Reset brokenness */ + server->is_broken = 0; + + /* Close the TCP and UDP sockets. */ + if (server->tcp_socket != ARES_SOCKET_BAD) + { + SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0); + sclose(server->tcp_socket); + server->tcp_socket = ARES_SOCKET_BAD; + server->tcp_connection_generation = ++channel->tcp_connection_generation; + } + if (server->udp_socket != ARES_SOCKET_BAD) + { + SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0); + sclose(server->udp_socket); + server->udp_socket = ARES_SOCKET_BAD; + } +} diff --git a/src/rt/libuv/src/ares/ares__get_hostent.c b/src/rt/libuv/src/ares/ares__get_hostent.c new file mode 100644 index 00000000000..298df09182a --- /dev/null +++ b/src/rt/libuv/src/ares/ares__get_hostent.c @@ -0,0 +1,263 @@ + +/* Copyright 1998, 2010 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif + +#include "ares.h" +#include "inet_net_pton.h" +#include "ares_private.h" + +int ares__get_hostent(FILE *fp, int family, struct hostent **host) +{ + char *line = NULL, *p, *q, **alias; + char *txtaddr, *txthost, *txtalias; + int status; + size_t addrlen, linesize, naliases; + struct ares_addr addr; + struct hostent *hostent = NULL; + + *host = NULL; /* Assume failure */ + + /* Validate family */ + switch (family) { + case AF_INET: + case AF_INET6: + case AF_UNSPEC: + break; + default: + return ARES_EBADFAMILY; + } + + while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) + { + + /* Trim line comment. */ + p = line; + while (*p && (*p != '#')) + p++; + *p = '\0'; + + /* Trim trailing whitespace. */ + q = p - 1; + while ((q >= line) && ISSPACE(*q)) + q--; + *++q = '\0'; + + /* Skip leading whitespace. */ + p = line; + while (*p && ISSPACE(*p)) + p++; + if (!*p) + /* Ignore line if empty. */ + continue; + + /* Pointer to start of IPv4 or IPv6 address part. */ + txtaddr = p; + + /* Advance past address part. */ + while (*p && !ISSPACE(*p)) + p++; + if (!*p) + /* Ignore line if reached end of line. */ + continue; + + /* Null terminate address part. */ + *p = '\0'; + + /* Advance to host name */ + p++; + while (*p && ISSPACE(*p)) + p++; + if (!*p) + /* Ignore line if reached end of line. */ + continue; + + /* Pointer to start of host name. */ + txthost = p; + + /* Advance past host name. */ + while (*p && !ISSPACE(*p)) + p++; + + /* Pointer to start of first alias. */ + txtalias = NULL; + if (*p) + { + q = p + 1; + while (*q && ISSPACE(*q)) + q++; + if (*q) + txtalias = q; + } + + /* Null terminate host name. */ + *p = '\0'; + + /* find out number of aliases. */ + naliases = 0; + if (txtalias) + { + p = txtalias; + while (*p) + { + while (*p && !ISSPACE(*p)) + p++; + while (*p && ISSPACE(*p)) + p++; + naliases++; + } + } + + /* Convert address string to network address for the requested family. */ + addrlen = 0; + addr.family = AF_UNSPEC; + addr.addrV4.s_addr = INADDR_NONE; + if ((family == AF_INET) || (family == AF_UNSPEC)) + { + addr.addrV4.s_addr = inet_addr(txtaddr); + if (addr.addrV4.s_addr != INADDR_NONE) + { + /* Actual network address family and length. */ + addr.family = AF_INET; + addrlen = sizeof(addr.addrV4); + } + } + if ((family == AF_INET6) || ((family == AF_UNSPEC) && (!addrlen))) + { + if (ares_inet_pton(AF_INET6, txtaddr, &addr.addrV6) > 0) + { + /* Actual network address family and length. */ + addr.family = AF_INET6; + addrlen = sizeof(addr.addrV6); + } + } + if (!addrlen) + /* Ignore line if invalid address string for the requested family. */ + continue; + + /* + ** Actual address family possible values are AF_INET and AF_INET6 only. + */ + + /* Allocate memory for the hostent structure. */ + hostent = malloc(sizeof(struct hostent)); + if (!hostent) + break; + + /* Initialize fields for out of memory condition. */ + hostent->h_aliases = NULL; + hostent->h_addr_list = NULL; + + /* Copy official host name. */ + hostent->h_name = strdup(txthost); + if (!hostent->h_name) + break; + + /* Copy network address. */ + hostent->h_addr_list = malloc(2 * sizeof(char *)); + if (!hostent->h_addr_list) + break; + hostent->h_addr_list[1] = NULL; + hostent->h_addr_list[0] = malloc(addrlen); + if (!hostent->h_addr_list[0]) + break; + if (addr.family == AF_INET) + memcpy(hostent->h_addr_list[0], &addr.addrV4, sizeof(addr.addrV4)); + else + memcpy(hostent->h_addr_list[0], &addr.addrV6, sizeof(addr.addrV6)); + + /* Copy aliases. */ + hostent->h_aliases = malloc((naliases + 1) * sizeof(char *)); + if (!hostent->h_aliases) + break; + alias = hostent->h_aliases; + while (naliases) + *(alias + naliases--) = NULL; + *alias = NULL; + while (txtalias) + { + p = txtalias; + while (*p && !ISSPACE(*p)) + p++; + q = p; + while (*q && ISSPACE(*q)) + q++; + *p = '\0'; + if ((*alias = strdup(txtalias)) == NULL) + break; + alias++; + txtalias = *q ? q : NULL; + } + if (txtalias) + /* Alias memory allocation failure. */ + break; + + /* Copy actual network address family and length. */ + hostent->h_addrtype = addr.family; + hostent->h_length = (int)addrlen; + + /* Free line buffer. */ + free(line); + + /* Return hostent successfully */ + *host = hostent; + return ARES_SUCCESS; + + } + + /* If allocated, free line buffer. */ + if (line) + free(line); + + if (status == ARES_SUCCESS) + { + /* Memory allocation failure; clean up. */ + if (hostent) + { + if (hostent->h_name) + free((char *) hostent->h_name); + if (hostent->h_aliases) + { + for (alias = hostent->h_aliases; *alias; alias++) + free(*alias); + free(hostent->h_aliases); + } + if (hostent->h_addr_list) + { + if (hostent->h_addr_list[0]) + free(hostent->h_addr_list[0]); + free(hostent->h_addr_list); + } + free(hostent); + } + return ARES_ENOMEM; + } + + return status; +} diff --git a/src/rt/libuv/src/ares/ares__read_line.c b/src/rt/libuv/src/ares/ares__read_line.c new file mode 100644 index 00000000000..ca018035ec3 --- /dev/null +++ b/src/rt/libuv/src/ares/ares__read_line.c @@ -0,0 +1,71 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include +#include +#include +#include "ares.h" +#include "ares_nowarn.h" +#include "ares_private.h" + +/* This is an internal function. Its contract is to read a line from + * a file into a dynamically allocated buffer, zeroing the trailing + * newline if there is one. The calling routine may call + * ares__read_line multiple times with the same buf and bufsize + * pointers; *buf will be reallocated and *bufsize adjusted as + * appropriate. The initial value of *buf should be NULL. After the + * calling routine is done reading lines, it should free *buf. + */ +int ares__read_line(FILE *fp, char **buf, size_t *bufsize) +{ + char *newbuf; + size_t offset = 0; + size_t len; + + if (*buf == NULL) + { + *buf = malloc(128); + if (!*buf) + return ARES_ENOMEM; + *bufsize = 128; + } + + for (;;) + { + int bytestoread = aresx_uztosi(*bufsize - offset); + + if (!fgets(*buf + offset, bytestoread, fp)) + return (offset != 0) ? 0 : (ferror(fp)) ? ARES_EFILE : ARES_EOF; + len = offset + strlen(*buf + offset); + if ((*buf)[len - 1] == '\n') + { + (*buf)[len - 1] = 0; + break; + } + offset = len; + if(len < *bufsize - 1) + continue; + + /* Allocate more space. */ + newbuf = realloc(*buf, *bufsize * 2); + if (!newbuf) + return ARES_ENOMEM; + *buf = newbuf; + *bufsize *= 2; + } + return ARES_SUCCESS; +} diff --git a/src/rt/libuv/src/ares/ares__timeval.c b/src/rt/libuv/src/ares/ares__timeval.c new file mode 100644 index 00000000000..f7aa7883f93 --- /dev/null +++ b/src/rt/libuv/src/ares/ares__timeval.c @@ -0,0 +1,111 @@ + +/* Copyright (C) 2008 by Daniel Stenberg et al + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include "ares.h" +#include "ares_private.h" + +#if defined(WIN32) && !defined(MSDOS) + +struct timeval ares__tvnow(void) +{ + /* + ** GetTickCount() is available on _all_ Windows versions from W95 up + ** to nowadays. Returns milliseconds elapsed since last system boot, + ** increases monotonically and wraps once 49.7 days have elapsed. + */ + struct timeval now; + DWORD milliseconds = GetTickCount(); + now.tv_sec = milliseconds / 1000; + now.tv_usec = (milliseconds % 1000) * 1000; + return now; +} + +#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) + +struct timeval ares__tvnow(void) +{ + /* + ** clock_gettime() is granted to be increased monotonically when the + ** monotonic clock is queried. Time starting point is unspecified, it + ** could be the system start-up time, the Epoch, or something else, + ** in any case the time starting point does not change once that the + ** system has started up. + */ + struct timeval now; + struct timespec tsnow; + if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) { + now.tv_sec = tsnow.tv_sec; + now.tv_usec = tsnow.tv_nsec / 1000; + } + /* + ** Even when the configure process has truly detected monotonic clock + ** availability, it might happen that it is not actually available at + ** run-time. When this occurs simply fallback to other time source. + */ +#ifdef HAVE_GETTIMEOFDAY + else + (void)gettimeofday(&now, NULL); +#else + else { + now.tv_sec = (long)time(NULL); + now.tv_usec = 0; + } +#endif + return now; +} + +#elif defined(HAVE_GETTIMEOFDAY) + +struct timeval ares__tvnow(void) +{ + /* + ** gettimeofday() is not granted to be increased monotonically, due to + ** clock drifting and external source time synchronization it can jump + ** forward or backward in time. + */ + struct timeval now; + (void)gettimeofday(&now, NULL); + return now; +} + +#else + +struct timeval ares__tvnow(void) +{ + /* + ** time() returns the value of time in seconds since the Epoch. + */ + struct timeval now; + now.tv_sec = (long)time(NULL); + now.tv_usec = 0; + return now; +} + +#endif + +#if 0 /* Not used */ +/* + * Make sure that the first argument is the more recent time, as otherwise + * we'll get a weird negative time-diff back... + * + * Returns: the time difference in number of milliseconds. + */ +long ares__tvdiff(struct timeval newer, struct timeval older) +{ + return (newer.tv_sec-older.tv_sec)*1000+ + (newer.tv_usec-older.tv_usec)/1000; +} +#endif + diff --git a/src/rt/libuv/src/ares/ares_cancel.c b/src/rt/libuv/src/ares/ares_cancel.c new file mode 100644 index 00000000000..eb790ae00d0 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_cancel.c @@ -0,0 +1,63 @@ + +/* Copyright (C) 2004 by Daniel Stenberg et al + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include +#include +#include "ares.h" +#include "ares_private.h" + +/* + * ares_cancel() cancels all ongoing requests/resolves that might be going on + * on the given channel. It does NOT kill the channel, use ares_destroy() for + * that. + */ +void ares_cancel(ares_channel channel) +{ + struct query *query; + struct list_node* list_head; + struct list_node* list_node; + int i; + + list_head = &(channel->all_queries); + for (list_node = list_head->next; list_node != list_head; ) + { + query = list_node->data; + list_node = list_node->next; /* since we're deleting the query */ + query->callback(query->arg, ARES_ECANCELLED, 0, NULL, 0); + ares__free_query(query); + } +#ifndef NDEBUG + /* Freeing the query should remove it from all the lists in which it sits, + * so all query lists should be empty now. + */ + assert(ares__is_list_empty(&(channel->all_queries))); + for (i = 0; i < ARES_QID_TABLE_SIZE; i++) + { + assert(ares__is_list_empty(&(channel->queries_by_qid[i]))); + } + for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++) + { + assert(ares__is_list_empty(&(channel->queries_by_timeout[i]))); + } +#endif + if (!(channel->flags & ARES_FLAG_STAYOPEN)) + { + if (channel->servers) + { + for (i = 0; i < channel->nservers; i++) + ares__close_sockets(channel, &channel->servers[i]); + } + } +} diff --git a/src/rt/libuv/src/ares/ares_data.c b/src/rt/libuv/src/ares/ares_data.c new file mode 100644 index 00000000000..a2477be192c --- /dev/null +++ b/src/rt/libuv/src/ares/ares_data.c @@ -0,0 +1,190 @@ + +/* Copyright (C) 2009-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + + +#include "ares_setup.h" + +#include + +#include "ares.h" +#include "ares_data.h" +#include "ares_private.h" + + +/* +** ares_free_data() - c-ares external API function. +** +** This function must be used by the application to free data memory that +** has been internally allocated by some c-ares function and for which a +** pointer has already been returned to the calling application. The list +** of c-ares functions returning pointers that must be free'ed using this +** function is: +** +** ares_get_servers() +** ares_parse_srv_reply() +** ares_parse_txt_reply() +*/ + +void ares_free_data(void *dataptr) +{ + struct ares_data *ptr; + + if (!dataptr) + return; + +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:1684) + /* 1684: conversion from pointer to same-sized integral type */ +#endif + + ptr = (void *)((char *)dataptr - offsetof(struct ares_data, data)); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif + + if (ptr->mark != ARES_DATATYPE_MARK) + return; + + switch (ptr->type) + { + case ARES_DATATYPE_MX_REPLY: + + if (ptr->data.mx_reply.next) + ares_free_data(ptr->data.mx_reply.next); + if (ptr->data.mx_reply.host) + free(ptr->data.mx_reply.host); + break; + + case ARES_DATATYPE_SRV_REPLY: + + if (ptr->data.srv_reply.next) + ares_free_data(ptr->data.srv_reply.next); + if (ptr->data.srv_reply.host) + free(ptr->data.srv_reply.host); + break; + + case ARES_DATATYPE_TXT_REPLY: + + if (ptr->data.txt_reply.next) + ares_free_data(ptr->data.txt_reply.next); + if (ptr->data.txt_reply.txt) + free(ptr->data.txt_reply.txt); + break; + + case ARES_DATATYPE_ADDR_NODE: + + if (ptr->data.addr_node.next) + ares_free_data(ptr->data.addr_node.next); + break; + + default: + return; + } + + free(ptr); +} + + +/* +** ares_malloc_data() - c-ares internal helper function. +** +** This function allocates memory for a c-ares private ares_data struct +** for the specified ares_datatype, initializes c-ares private fields +** and zero initializes those which later might be used from the public +** API. It returns an interior pointer which can be passed by c-ares +** functions to the calling application, and that must be free'ed using +** c-ares external API function ares_free_data(). +*/ + +void *ares_malloc_data(ares_datatype type) +{ + struct ares_data *ptr; + + ptr = malloc(sizeof(struct ares_data)); + if (!ptr) + return NULL; + + switch (type) + { + case ARES_DATATYPE_MX_REPLY: + ptr->data.mx_reply.next = NULL; + ptr->data.mx_reply.host = NULL; + ptr->data.mx_reply.priority = 0; + break; + + case ARES_DATATYPE_SRV_REPLY: + ptr->data.srv_reply.next = NULL; + ptr->data.srv_reply.host = NULL; + ptr->data.srv_reply.priority = 0; + ptr->data.srv_reply.weight = 0; + ptr->data.srv_reply.port = 0; + break; + + case ARES_DATATYPE_TXT_REPLY: + ptr->data.txt_reply.next = NULL; + ptr->data.txt_reply.txt = NULL; + ptr->data.txt_reply.length = 0; + break; + + case ARES_DATATYPE_ADDR_NODE: + ptr->data.addr_node.next = NULL; + ptr->data.addr_node.family = 0; + memset(&ptr->data.addr_node.addrV6, 0, + sizeof(ptr->data.addr_node.addrV6)); + break; + + default: + free(ptr); + return NULL; + } + + ptr->mark = ARES_DATATYPE_MARK; + ptr->type = type; + + return &ptr->data; +} + + +/* +** ares_get_datatype() - c-ares internal helper function. +** +** This function returns the ares_datatype of the data stored in a +** private ares_data struct when given the public API pointer. +*/ + +ares_datatype ares_get_datatype(void * dataptr) +{ + struct ares_data *ptr; + +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:1684) + /* 1684: conversion from pointer to same-sized integral type */ +#endif + + ptr = (void *)((char *)dataptr - offsetof(struct ares_data, data)); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif + + if (ptr->mark == ARES_DATATYPE_MARK) + return ptr->type; + + return ARES_DATATYPE_UNKNOWN; +} diff --git a/src/rt/libuv/src/ares/ares_data.h b/src/rt/libuv/src/ares/ares_data.h new file mode 100644 index 00000000000..de1608be5b8 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_data.h @@ -0,0 +1,65 @@ + +/* Copyright (C) 2009-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +typedef enum { + ARES_DATATYPE_UNKNOWN = 1, /* unknown data type - introduced in 1.7.0 */ + ARES_DATATYPE_SRV_REPLY, /* struct ares_srv_reply - introduced in 1.7.0 */ + ARES_DATATYPE_TXT_REPLY, /* struct ares_txt_reply - introduced in 1.7.0 */ + ARES_DATATYPE_ADDR_NODE, /* struct ares_addr_node - introduced in 1.7.1 */ + ARES_DATATYPE_MX_REPLY, /* struct ares_mx_reply - introduced in 1.7.2 */ +#if 0 + ARES_DATATYPE_ADDR6TTL, /* struct ares_addrttl */ + ARES_DATATYPE_ADDRTTL, /* struct ares_addr6ttl */ + ARES_DATATYPE_HOSTENT, /* struct hostent */ + ARES_DATATYPE_OPTIONS, /* struct ares_options */ +#endif + ARES_DATATYPE_LAST /* not used - introduced in 1.7.0 */ +} ares_datatype; + +#define ARES_DATATYPE_MARK 0xbead + +/* + * ares_data struct definition is internal to c-ares and shall not + * be exposed by the public API in order to allow future changes + * and extensions to it without breaking ABI. This will be used + * internally by c-ares as the container of multiple types of data + * dynamically allocated for which a reference will be returned + * to the calling application. + * + * c-ares API functions returning a pointer to c-ares internally + * allocated data will actually be returning an interior pointer + * into this ares_data struct. + * + * All this is 'invisible' to the calling application, the only + * requirement is that this kind of data must be free'ed by the + * calling application using ares_free_data() with the pointer + * it has received from a previous c-ares function call. + */ + +struct ares_data { + ares_datatype type; /* Actual data type identifier. */ + unsigned int mark; /* Private ares_data signature. */ + union { + struct ares_txt_reply txt_reply; + struct ares_srv_reply srv_reply; + struct ares_addr_node addr_node; + struct ares_mx_reply mx_reply; + } data; +}; + +void *ares_malloc_data(ares_datatype type); + +ares_datatype ares_get_datatype(void * dataptr); diff --git a/src/rt/libuv/src/ares/ares_destroy.c b/src/rt/libuv/src/ares/ares_destroy.c new file mode 100644 index 00000000000..5e274daeef5 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_destroy.c @@ -0,0 +1,105 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2004-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include +#include +#include "ares.h" +#include "ares_private.h" + +void ares_destroy_options(struct ares_options *options) +{ + int i; + + if(options->servers) + free(options->servers); + for (i = 0; i < options->ndomains; i++) + free(options->domains[i]); + free(options->domains); + if(options->sortlist) + free(options->sortlist); + free(options->lookups); +} + +void ares_destroy(ares_channel channel) +{ + int i; + struct query *query; + struct list_node* list_head; + struct list_node* list_node; + + if (!channel) + return; + + list_head = &(channel->all_queries); + for (list_node = list_head->next; list_node != list_head; ) + { + query = list_node->data; + list_node = list_node->next; /* since we're deleting the query */ + query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0); + ares__free_query(query); + } +#ifndef NDEBUG + /* Freeing the query should remove it from all the lists in which it sits, + * so all query lists should be empty now. + */ + assert(ares__is_list_empty(&(channel->all_queries))); + for (i = 0; i < ARES_QID_TABLE_SIZE; i++) + { + assert(ares__is_list_empty(&(channel->queries_by_qid[i]))); + } + for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++) + { + assert(ares__is_list_empty(&(channel->queries_by_timeout[i]))); + } +#endif + + ares__destroy_servers_state(channel); + + if (channel->domains) { + for (i = 0; i < channel->ndomains; i++) + free(channel->domains[i]); + free(channel->domains); + } + + if(channel->sortlist) + free(channel->sortlist); + + if (channel->lookups) + free(channel->lookups); + + free(channel); +} + +void ares__destroy_servers_state(ares_channel channel) +{ + struct server_state *server; + int i; + + if (channel->servers) + { + for (i = 0; i < channel->nservers; i++) + { + server = &channel->servers[i]; + ares__close_sockets(channel, server); + assert(ares__is_list_empty(&server->queries_to_server)); + } + free(channel->servers); + channel->servers = NULL; + } + channel->nservers = -1; +} diff --git a/src/rt/libuv/src/ares/ares_dns.h b/src/rt/libuv/src/ares/ares_dns.h new file mode 100644 index 00000000000..6893c024c89 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_dns.h @@ -0,0 +1,90 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#ifndef ARES__DNS_H +#define ARES__DNS_H + +#define DNS__16BIT(p) (((p)[0] << 8) | (p)[1]) +#define DNS__32BIT(p) (((p)[0] << 24) | ((p)[1] << 16) | \ + ((p)[2] << 8) | (p)[3]) + +#define DNS__SET16BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 8) & 0xff)), \ + ((p)[1] = (unsigned char)((v) & 0xff))) +#define DNS__SET32BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 24) & 0xff)), \ + ((p)[1] = (unsigned char)(((v) >> 16) & 0xff)), \ + ((p)[2] = (unsigned char)(((v) >> 8) & 0xff)), \ + ((p)[3] = (unsigned char)((v) & 0xff))) + +#if 0 +/* we cannot use this approach on systems where we can't access 16/32 bit + data on un-aligned addresses */ +#define DNS__16BIT(p) ntohs(*(unsigned short*)(p)) +#define DNS__32BIT(p) ntohl(*(unsigned long*)(p)) +#define DNS__SET16BIT(p, v) *(unsigned short*)(p) = htons(v) +#define DNS__SET32BIT(p, v) *(unsigned long*)(p) = htonl(v) +#endif + +/* Macros for parsing a DNS header */ +#define DNS_HEADER_QID(h) DNS__16BIT(h) +#define DNS_HEADER_QR(h) (((h)[2] >> 7) & 0x1) +#define DNS_HEADER_OPCODE(h) (((h)[2] >> 3) & 0xf) +#define DNS_HEADER_AA(h) (((h)[2] >> 2) & 0x1) +#define DNS_HEADER_TC(h) (((h)[2] >> 1) & 0x1) +#define DNS_HEADER_RD(h) ((h)[2] & 0x1) +#define DNS_HEADER_RA(h) (((h)[3] >> 7) & 0x1) +#define DNS_HEADER_Z(h) (((h)[3] >> 4) & 0x7) +#define DNS_HEADER_RCODE(h) ((h)[3] & 0xf) +#define DNS_HEADER_QDCOUNT(h) DNS__16BIT((h) + 4) +#define DNS_HEADER_ANCOUNT(h) DNS__16BIT((h) + 6) +#define DNS_HEADER_NSCOUNT(h) DNS__16BIT((h) + 8) +#define DNS_HEADER_ARCOUNT(h) DNS__16BIT((h) + 10) + +/* Macros for constructing a DNS header */ +#define DNS_HEADER_SET_QID(h, v) DNS__SET16BIT(h, v) +#define DNS_HEADER_SET_QR(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 7)) +#define DNS_HEADER_SET_OPCODE(h, v) ((h)[2] |= (unsigned char)(((v) & 0xf) << 3)) +#define DNS_HEADER_SET_AA(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 2)) +#define DNS_HEADER_SET_TC(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 1)) +#define DNS_HEADER_SET_RD(h, v) ((h)[2] |= (unsigned char)((v) & 0x1)) +#define DNS_HEADER_SET_RA(h, v) ((h)[3] |= (unsigned char)(((v) & 0x1) << 7)) +#define DNS_HEADER_SET_Z(h, v) ((h)[3] |= (unsigned char)(((v) & 0x7) << 4)) +#define DNS_HEADER_SET_RCODE(h, v) ((h)[3] |= (unsigned char)((v) & 0xf)) +#define DNS_HEADER_SET_QDCOUNT(h, v) DNS__SET16BIT((h) + 4, v) +#define DNS_HEADER_SET_ANCOUNT(h, v) DNS__SET16BIT((h) + 6, v) +#define DNS_HEADER_SET_NSCOUNT(h, v) DNS__SET16BIT((h) + 8, v) +#define DNS_HEADER_SET_ARCOUNT(h, v) DNS__SET16BIT((h) + 10, v) + +/* Macros for parsing the fixed part of a DNS question */ +#define DNS_QUESTION_TYPE(q) DNS__16BIT(q) +#define DNS_QUESTION_CLASS(q) DNS__16BIT((q) + 2) + +/* Macros for constructing the fixed part of a DNS question */ +#define DNS_QUESTION_SET_TYPE(q, v) DNS__SET16BIT(q, v) +#define DNS_QUESTION_SET_CLASS(q, v) DNS__SET16BIT((q) + 2, v) + +/* Macros for parsing the fixed part of a DNS resource record */ +#define DNS_RR_TYPE(r) DNS__16BIT(r) +#define DNS_RR_CLASS(r) DNS__16BIT((r) + 2) +#define DNS_RR_TTL(r) DNS__32BIT((r) + 4) +#define DNS_RR_LEN(r) DNS__16BIT((r) + 8) + +/* Macros for constructing the fixed part of a DNS resource record */ +#define DNS_RR_SET_TYPE(r) DNS__SET16BIT(r, v) +#define DNS_RR_SET_CLASS(r) DNS__SET16BIT((r) + 2, v) +#define DNS_RR_SET_TTL(r) DNS__SET32BIT((r) + 4, v) +#define DNS_RR_SET_LEN(r) DNS__SET16BIT((r) + 8, v) + +#endif /* ARES__DNS_H */ diff --git a/src/rt/libuv/src/ares/ares_expand_name.c b/src/rt/libuv/src/ares/ares_expand_name.c new file mode 100644 index 00000000000..2af6b2ac40b --- /dev/null +++ b/src/rt/libuv/src/ares/ares_expand_name.c @@ -0,0 +1,193 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include "ares.h" +#include "ares_private.h" /* for the memdebug */ + +static int name_length(const unsigned char *encoded, const unsigned char *abuf, + int alen); + +/* Expand an RFC1035-encoded domain name given by encoded. The + * containing message is given by abuf and alen. The result given by + * *s, which is set to a NUL-terminated allocated buffer. *enclen is + * set to the length of the encoded name (not the length of the + * expanded name; the goal is to tell the caller how many bytes to + * move forward to get past the encoded name). + * + * In the simple case, an encoded name is a series of labels, each + * composed of a one-byte length (limited to values between 0 and 63 + * inclusive) followed by the label contents. The name is terminated + * by a zero-length label. + * + * In the more complicated case, a label may be terminated by an + * indirection pointer, specified by two bytes with the high bits of + * the first byte (corresponding to INDIR_MASK) set to 11. With the + * two high bits of the first byte stripped off, the indirection + * pointer gives an offset from the beginning of the containing + * message with more labels to decode. Indirection can happen an + * arbitrary number of times, so we have to detect loops. + * + * Since the expanded name uses '.' as a label separator, we use + * backslashes to escape periods or backslashes in the expanded name. + */ + +int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf, + int alen, char **s, long *enclen) +{ + int len, indir = 0; + char *q; + const unsigned char *p; + union { + ssize_t sig; + size_t uns; + } nlen; + + nlen.sig = name_length(encoded, abuf, alen); + if (nlen.sig < 0) + return ARES_EBADNAME; + + *s = malloc(nlen.uns + 1); + if (!*s) + return ARES_ENOMEM; + q = *s; + + if (nlen.uns == 0) { + /* RFC2181 says this should be ".": the root of the DNS tree. + * Since this function strips trailing dots though, it becomes "" + */ + q[0] = '\0'; + *enclen = 1; /* the caller should move one byte to get past this */ + return ARES_SUCCESS; + } + + /* No error-checking necessary; it was all done by name_length(). */ + p = encoded; + while (*p) + { + if ((*p & INDIR_MASK) == INDIR_MASK) + { + if (!indir) + { + *enclen = p + 2 - encoded; + indir = 1; + } + p = abuf + ((*p & ~INDIR_MASK) << 8 | *(p + 1)); + } + else + { + len = *p; + p++; + while (len--) + { + if (*p == '.' || *p == '\\') + *q++ = '\\'; + *q++ = *p; + p++; + } + *q++ = '.'; + } + } + if (!indir) + *enclen = p + 1 - encoded; + + /* Nuke the trailing period if we wrote one. */ + if (q > *s) + *(q - 1) = 0; + else + *q = 0; /* zero terminate */ + + return ARES_SUCCESS; +} + +/* Return the length of the expansion of an encoded domain name, or + * -1 if the encoding is invalid. + */ +static int name_length(const unsigned char *encoded, const unsigned char *abuf, + int alen) +{ + int n = 0, offset, indir = 0; + + /* Allow the caller to pass us abuf + alen and have us check for it. */ + if (encoded == abuf + alen) + return -1; + + while (*encoded) + { + if ((*encoded & INDIR_MASK) == INDIR_MASK) + { + /* Check the offset and go there. */ + if (encoded + 1 >= abuf + alen) + return -1; + offset = (*encoded & ~INDIR_MASK) << 8 | *(encoded + 1); + if (offset >= alen) + return -1; + encoded = abuf + offset; + + /* If we've seen more indirects than the message length, + * then there's a loop. + */ + if (++indir > alen) + return -1; + } + else + { + offset = *encoded; + if (encoded + offset + 1 >= abuf + alen) + return -1; + encoded++; + while (offset--) + { + n += (*encoded == '.' || *encoded == '\\') ? 2 : 1; + encoded++; + } + n++; + } + } + + /* If there were any labels at all, then the number of dots is one + * less than the number of labels, so subtract one. + */ + return (n) ? n - 1 : n; +} + +/* Like ares_expand_name but returns EBADRESP in case of invalid input. */ +int ares__expand_name_for_response(const unsigned char *encoded, + const unsigned char *abuf, int alen, + char **s, long *enclen) +{ + int status = ares_expand_name(encoded, abuf, alen, s, enclen); + if (status == ARES_EBADNAME) + status = ARES_EBADRESP; + return status; +} diff --git a/src/rt/libuv/src/ares/ares_expand_string.c b/src/rt/libuv/src/ares/ares_expand_string.c new file mode 100644 index 00000000000..f24cccf6470 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_expand_string.c @@ -0,0 +1,75 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif + +#include +#include +#include "ares.h" +#include "ares_private.h" /* for the memdebug */ + +/* Simply decodes a length-encoded character string. The first byte of the + * input is the length of the string to be returned and the bytes thereafter + * are the characters of the string. The returned result will be NULL + * terminated. + */ +int ares_expand_string(const unsigned char *encoded, + const unsigned char *abuf, + int alen, + unsigned char **s, + long *enclen) +{ + unsigned char *q; + union { + ssize_t sig; + size_t uns; + } elen; + + if (encoded == abuf+alen) + return ARES_EBADSTR; + + elen.uns = *encoded; + if (encoded+elen.sig+1 > abuf+alen) + return ARES_EBADSTR; + + encoded++; + + *s = malloc(elen.uns+1); + if (*s == NULL) + return ARES_ENOMEM; + q = *s; + strncpy((char *)q, (char *)encoded, elen.uns); + q[elen.uns] = '\0'; + + *s = q; + + *enclen = (long)(elen.sig+1); + + return ARES_SUCCESS; +} + diff --git a/src/rt/libuv/src/ares/ares_fds.c b/src/rt/libuv/src/ares/ares_fds.c new file mode 100644 index 00000000000..b57be9287bb --- /dev/null +++ b/src/rt/libuv/src/ares/ares_fds.c @@ -0,0 +1,62 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#include "ares.h" +#include "ares_private.h" + +int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds) +{ + struct server_state *server; + ares_socket_t nfds; + int i; + + /* Are there any active queries? */ + int active_queries = !ares__is_list_empty(&(channel->all_queries)); + + nfds = 0; + for (i = 0; i < channel->nservers; i++) + { + server = &channel->servers[i]; + /* We only need to register interest in UDP sockets if we have + * outstanding queries. + */ + if (active_queries && server->udp_socket != ARES_SOCKET_BAD) + { + FD_SET(server->udp_socket, read_fds); + if (server->udp_socket >= nfds) + nfds = server->udp_socket + 1; + } + /* We always register for TCP events, because we want to know + * when the other side closes the connection, so we don't waste + * time trying to use a broken connection. + */ + if (server->tcp_socket != ARES_SOCKET_BAD) + { + FD_SET(server->tcp_socket, read_fds); + if (server->qhead) + FD_SET(server->tcp_socket, write_fds); + if (server->tcp_socket >= nfds) + nfds = server->tcp_socket + 1; + } + } + return (int)nfds; +} diff --git a/src/rt/libuv/src/ares/ares_free_hostent.c b/src/rt/libuv/src/ares/ares_free_hostent.c new file mode 100644 index 00000000000..b124560d86a --- /dev/null +++ b/src/rt/libuv/src/ares/ares_free_hostent.c @@ -0,0 +1,39 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include + +#ifdef HAVE_NETDB_H +#include +#endif + +#include "ares.h" +#include "ares_private.h" /* for memdebug */ + +void ares_free_hostent(struct hostent *host) +{ + char **p; + + free((char *)(host->h_name)); + for (p = host->h_aliases; *p; p++) + free(*p); + free(host->h_aliases); + free(host->h_addr_list[0]); /* no matter if there is one or many entries, + there is only one malloc for all of them */ + free(host->h_addr_list); + free(host); +} diff --git a/src/rt/libuv/src/ares/ares_free_string.c b/src/rt/libuv/src/ares/ares_free_string.c new file mode 100644 index 00000000000..e0545c1d1af --- /dev/null +++ b/src/rt/libuv/src/ares/ares_free_string.c @@ -0,0 +1,25 @@ + +/* Copyright 2000 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include +#include "ares.h" +#include "ares_private.h" + +void ares_free_string(void *str) +{ + free(str); +} diff --git a/src/rt/libuv/src/ares/ares_gethostbyaddr.c b/src/rt/libuv/src/ares/ares_gethostbyaddr.c new file mode 100644 index 00000000000..0de2cf249f0 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_gethostbyaddr.c @@ -0,0 +1,292 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include + +#include "ares.h" +#include "inet_net_pton.h" +#include "ares_private.h" + +#ifdef WATT32 +#undef WIN32 +#endif + +struct addr_query { + /* Arguments passed to ares_gethostbyaddr() */ + ares_channel channel; + struct ares_addr addr; + ares_host_callback callback; + void *arg; + + const char *remaining_lookups; + int timeouts; +}; + +static void next_lookup(struct addr_query *aquery); +static void addr_callback(void *arg, int status, int timeouts, + unsigned char *abuf, int alen); +static void end_aquery(struct addr_query *aquery, int status, + struct hostent *host); +static int file_lookup(struct ares_addr *addr, struct hostent **host); +static void ptr_rr_name(char *name, const struct ares_addr *addr); + +void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen, + int family, ares_host_callback callback, void *arg) +{ + struct addr_query *aquery; + + if (family != AF_INET && family != AF_INET6) + { + callback(arg, ARES_ENOTIMP, 0, NULL); + return; + } + + if ((family == AF_INET && addrlen != sizeof(aquery->addr.addrV4)) || + (family == AF_INET6 && addrlen != sizeof(aquery->addr.addrV6))) + { + callback(arg, ARES_ENOTIMP, 0, NULL); + return; + } + + aquery = malloc(sizeof(struct addr_query)); + if (!aquery) + { + callback(arg, ARES_ENOMEM, 0, NULL); + return; + } + aquery->channel = channel; + if (family == AF_INET) + memcpy(&aquery->addr.addrV4, addr, sizeof(aquery->addr.addrV4)); + else + memcpy(&aquery->addr.addrV6, addr, sizeof(aquery->addr.addrV6)); + aquery->addr.family = family; + aquery->callback = callback; + aquery->arg = arg; + aquery->remaining_lookups = channel->lookups; + aquery->timeouts = 0; + + next_lookup(aquery); +} + +static void next_lookup(struct addr_query *aquery) +{ + const char *p; + char name[128]; + int status; + struct hostent *host; + + for (p = aquery->remaining_lookups; *p; p++) + { + switch (*p) + { + case 'b': + ptr_rr_name(name, &aquery->addr); + aquery->remaining_lookups = p + 1; + ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback, + aquery); + return; + case 'f': + status = file_lookup(&aquery->addr, &host); + + /* this status check below previously checked for !ARES_ENOTFOUND, + but we should not assume that this single error code is the one + that can occur, as that is in fact no longer the case */ + if (status == ARES_SUCCESS) + { + end_aquery(aquery, status, host); + return; + } + break; + } + } + end_aquery(aquery, ARES_ENOTFOUND, NULL); +} + +static void addr_callback(void *arg, int status, int timeouts, + unsigned char *abuf, int alen) +{ + struct addr_query *aquery = (struct addr_query *) arg; + struct hostent *host; + size_t addrlen; + + aquery->timeouts += timeouts; + if (status == ARES_SUCCESS) + { + if (aquery->addr.family == AF_INET) + { + addrlen = sizeof(aquery->addr.addrV4); + status = ares_parse_ptr_reply(abuf, alen, &aquery->addr.addrV4, + (int)addrlen, AF_INET, &host); + } + else + { + addrlen = sizeof(aquery->addr.addrV6); + status = ares_parse_ptr_reply(abuf, alen, &aquery->addr.addrV6, + (int)addrlen, AF_INET6, &host); + } + end_aquery(aquery, status, host); + } + else if (status == ARES_EDESTRUCTION) + end_aquery(aquery, status, NULL); + else + next_lookup(aquery); +} + +static void end_aquery(struct addr_query *aquery, int status, + struct hostent *host) +{ + aquery->callback(aquery->arg, status, aquery->timeouts, host); + if (host) + ares_free_hostent(host); + free(aquery); +} + +static int file_lookup(struct ares_addr *addr, struct hostent **host) +{ + FILE *fp; + int status; + int error; + +#ifdef WIN32 + char PATH_HOSTS[MAX_PATH]; + if (IS_NT()) { + char tmp[MAX_PATH]; + HKEY hkeyHosts; + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, + &hkeyHosts) == ERROR_SUCCESS) + { + DWORD dwLength = MAX_PATH; + RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, (LPBYTE)tmp, + &dwLength); + ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH); + RegCloseKey(hkeyHosts); + } + } + else + GetWindowsDirectory(PATH_HOSTS, MAX_PATH); + + strcat(PATH_HOSTS, WIN_PATH_HOSTS); + +#elif defined(WATT32) + extern const char *_w32_GetHostsFile (void); + const char *PATH_HOSTS = _w32_GetHostsFile(); + + if (!PATH_HOSTS) + return ARES_ENOTFOUND; +#endif + + fp = fopen(PATH_HOSTS, "r"); + if (!fp) + { + error = ERRNO; + switch(error) + { + case ENOENT: + case ESRCH: + return ARES_ENOTFOUND; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", + PATH_HOSTS)); + *host = NULL; + return ARES_EFILE; + } + } + while ((status = ares__get_hostent(fp, addr->family, host)) == ARES_SUCCESS) + { + if (addr->family != (*host)->h_addrtype) + { + ares_free_hostent(*host); + continue; + } + if (addr->family == AF_INET) + { + if (memcmp((*host)->h_addr, &addr->addrV4, + sizeof(addr->addrV4)) == 0) + break; + } + else if (addr->family == AF_INET6) + { + if (memcmp((*host)->h_addr, &addr->addrV6, + sizeof(addr->addrV6)) == 0) + break; + } + ares_free_hostent(*host); + } + fclose(fp); + if (status == ARES_EOF) + status = ARES_ENOTFOUND; + if (status != ARES_SUCCESS) + *host = NULL; + return status; +} + +static void ptr_rr_name(char *name, const struct ares_addr *addr) +{ + if (addr->family == AF_INET) + { + unsigned long laddr = ntohl(addr->addrV4.s_addr); + unsigned long a1 = (laddr >> 24UL) & 0xFFUL; + unsigned long a2 = (laddr >> 16UL) & 0xFFUL; + unsigned long a3 = (laddr >> 8UL) & 0xFFUL; + unsigned long a4 = laddr & 0xFFUL; + sprintf(name, "%lu.%lu.%lu.%lu.in-addr.arpa", a4, a3, a2, a1); + } + else + { + unsigned char *bytes = (unsigned char *)&addr->addrV6; + /* There are too many arguments to do this in one line using + * minimally C89-compliant compilers */ + sprintf(name, + "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.", + bytes[15]&0xf, bytes[15] >> 4, bytes[14]&0xf, bytes[14] >> 4, + bytes[13]&0xf, bytes[13] >> 4, bytes[12]&0xf, bytes[12] >> 4, + bytes[11]&0xf, bytes[11] >> 4, bytes[10]&0xf, bytes[10] >> 4, + bytes[9]&0xf, bytes[9] >> 4, bytes[8]&0xf, bytes[8] >> 4); + sprintf(name+strlen(name), + "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa", + bytes[7]&0xf, bytes[7] >> 4, bytes[6]&0xf, bytes[6] >> 4, + bytes[5]&0xf, bytes[5] >> 4, bytes[4]&0xf, bytes[4] >> 4, + bytes[3]&0xf, bytes[3] >> 4, bytes[2]&0xf, bytes[2] >> 4, + bytes[1]&0xf, bytes[1] >> 4, bytes[0]&0xf, bytes[0] >> 4); + } +} diff --git a/src/rt/libuv/src/ares/ares_gethostbyname.c b/src/rt/libuv/src/ares/ares_gethostbyname.c new file mode 100644 index 00000000000..4469ffee233 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_gethostbyname.c @@ -0,0 +1,515 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif + +#include "ares.h" +#include "inet_net_pton.h" +#include "bitncmp.h" +#include "ares_private.h" + +#ifdef WATT32 +#undef WIN32 +#endif + +struct host_query { + /* Arguments passed to ares_gethostbyname() */ + ares_channel channel; + char *name; + ares_host_callback callback; + void *arg; + int sent_family; /* this family is what was is being used */ + int want_family; /* this family is what is asked for in the API */ + const char *remaining_lookups; + int timeouts; +}; + +static void next_lookup(struct host_query *hquery, int status_code); +static void host_callback(void *arg, int status, int timeouts, + unsigned char *abuf, int alen); +static void end_hquery(struct host_query *hquery, int status, + struct hostent *host); +static int fake_hostent(const char *name, int family, + ares_host_callback callback, void *arg); +static int file_lookup(const char *name, int family, struct hostent **host); +static void sort_addresses(struct hostent *host, + const struct apattern *sortlist, int nsort); +static void sort6_addresses(struct hostent *host, + const struct apattern *sortlist, int nsort); +static int get_address_index(const struct in_addr *addr, + const struct apattern *sortlist, int nsort); +static int get6_address_index(const struct ares_in6_addr *addr, + const struct apattern *sortlist, int nsort); + +void ares_gethostbyname(ares_channel channel, const char *name, int family, + ares_host_callback callback, void *arg) +{ + struct host_query *hquery; + + /* Right now we only know how to look up Internet addresses - and unspec + means try both basically. */ + switch (family) { + case AF_INET: + case AF_INET6: + case AF_UNSPEC: + break; + default: + callback(arg, ARES_ENOTIMP, 0, NULL); + return; + } + + if (fake_hostent(name, family, callback, arg)) + return; + + /* Allocate and fill in the host query structure. */ + hquery = malloc(sizeof(struct host_query)); + if (!hquery) + { + callback(arg, ARES_ENOMEM, 0, NULL); + return; + } + hquery->channel = channel; + hquery->name = strdup(name); + hquery->want_family = family; + hquery->sent_family = -1; /* nothing is sent yet */ + if (!hquery->name) { + free(hquery); + callback(arg, ARES_ENOMEM, 0, NULL); + return; + } + hquery->callback = callback; + hquery->arg = arg; + hquery->remaining_lookups = channel->lookups; + hquery->timeouts = 0; + + /* Start performing lookups according to channel->lookups. */ + next_lookup(hquery, ARES_ECONNREFUSED /* initial error code */); +} + +static void next_lookup(struct host_query *hquery, int status_code) +{ + const char *p; + struct hostent *host; + int status = status_code; + + for (p = hquery->remaining_lookups; *p; p++) + { + switch (*p) + { + case 'b': + /* DNS lookup */ + hquery->remaining_lookups = p + 1; + if ((hquery->want_family == AF_INET6) || + (hquery->want_family == AF_UNSPEC)) { + /* if inet6 or unspec, start out with AAAA */ + hquery->sent_family = AF_INET6; + ares_search(hquery->channel, hquery->name, C_IN, T_AAAA, + host_callback, hquery); + } + else { + hquery->sent_family = AF_INET; + ares_search(hquery->channel, hquery->name, C_IN, T_A, + host_callback, hquery); + } + return; + + case 'f': + /* Host file lookup */ + status = file_lookup(hquery->name, hquery->want_family, &host); + + /* this status check below previously checked for !ARES_ENOTFOUND, + but we should not assume that this single error code is the one + that can occur, as that is in fact no longer the case */ + if (status == ARES_SUCCESS) + { + end_hquery(hquery, status, host); + return; + } + status = status_code; /* Use original status code */ + break; + } + } + end_hquery(hquery, status, NULL); +} + +static void host_callback(void *arg, int status, int timeouts, + unsigned char *abuf, int alen) +{ + struct host_query *hquery = (struct host_query *) arg; + ares_channel channel = hquery->channel; + struct hostent *host = NULL; + + hquery->timeouts += timeouts; + if (status == ARES_SUCCESS) + { + if (hquery->sent_family == AF_INET) + { + status = ares_parse_a_reply(abuf, alen, &host, NULL, NULL); + if (host && channel->nsort) + sort_addresses(host, channel->sortlist, channel->nsort); + } + else if (hquery->sent_family == AF_INET6) + { + status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL); + if (status == ARES_ENODATA || status == ARES_EBADRESP) { + /* The query returned something but either there were no AAAA + records (e.g. just CNAME) or the response was malformed. Try + looking up A instead. We should possibly limit this + attempt-next logic to AF_UNSPEC lookups only. */ + hquery->sent_family = AF_INET; + ares_search(hquery->channel, hquery->name, C_IN, T_A, + host_callback, hquery); + return; + } + if (host && channel->nsort) + sort6_addresses(host, channel->sortlist, channel->nsort); + } + end_hquery(hquery, status, host); + } + else if ((status == ARES_ENODATA || status == ARES_EBADRESP || + status == ARES_ETIMEOUT) && hquery->sent_family == AF_INET6) + { + /* The AAAA query yielded no useful result. Now look up an A instead. + We should possibly limit this attempt-next logic to AF_UNSPEC lookups + only. */ + hquery->sent_family = AF_INET; + ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback, + hquery); + } + else if (status == ARES_EDESTRUCTION) + end_hquery(hquery, status, NULL); + else + next_lookup(hquery, status); +} + +static void end_hquery(struct host_query *hquery, int status, + struct hostent *host) +{ + hquery->callback(hquery->arg, status, hquery->timeouts, host); + if (host) + ares_free_hostent(host); + free(hquery->name); + free(hquery); +} + +/* If the name looks like an IP address, fake up a host entry, end the + * query immediately, and return true. Otherwise return false. + */ +static int fake_hostent(const char *name, int family, + ares_host_callback callback, void *arg) +{ + struct hostent hostent; + char *aliases[1] = { NULL }; + char *addrs[2]; + int result = 0; + struct in_addr in; + struct ares_in6_addr in6; + + if (family == AF_INET || family == AF_INET6) + { + /* It only looks like an IP address if it's all numbers and dots. */ + int numdots = 0, valid = 1; + const char *p; + for (p = name; *p; p++) + { + if (!ISDIGIT(*p) && *p != '.') { + valid = 0; + break; + } else if (*p == '.') { + numdots++; + } + } + + /* if we don't have 3 dots, it is illegal + * (although inet_addr doesn't think so). + */ + if (numdots != 3 || !valid) + result = 0; + else + result = ((in.s_addr = inet_addr(name)) == INADDR_NONE ? 0 : 1); + + if (result) + family = AF_INET; + } + if (family == AF_INET6) + result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1); + + if (!result) + return 0; + + if (family == AF_INET) + { + hostent.h_length = (int)sizeof(struct in_addr); + addrs[0] = (char *)∈ + } + else if (family == AF_INET6) + { + hostent.h_length = (int)sizeof(struct ares_in6_addr); + addrs[0] = (char *)&in6; + } + /* Duplicate the name, to avoid a constness violation. */ + hostent.h_name = strdup(name); + if (!hostent.h_name) + { + callback(arg, ARES_ENOMEM, 0, NULL); + return 1; + } + + /* Fill in the rest of the host structure and terminate the query. */ + addrs[1] = NULL; + hostent.h_aliases = aliases; + hostent.h_addrtype = family; + hostent.h_addr_list = addrs; + callback(arg, ARES_SUCCESS, 0, &hostent); + + free((char *)(hostent.h_name)); + return 1; +} + +/* This is an API method */ +int ares_gethostbyname_file(ares_channel channel, const char *name, + int family, struct hostent **host) +{ + int result; + + /* We only take the channel to ensure that ares_init() been called. */ + if(channel == NULL) + { + /* Anything will do, really. This seems fine, and is consistent with + other error cases. */ + *host = NULL; + return ARES_ENOTFOUND; + } + + /* Just chain to the internal implementation we use here; it's exactly + * what we want. + */ + result = file_lookup(name, family, host); + if(result != ARES_SUCCESS) + { + /* We guarantee a NULL hostent on failure. */ + *host = NULL; + } + return result; +} + +static int file_lookup(const char *name, int family, struct hostent **host) +{ + FILE *fp; + char **alias; + int status; + int error; + +#ifdef WIN32 + char PATH_HOSTS[MAX_PATH]; + if (IS_NT()) { + char tmp[MAX_PATH]; + HKEY hkeyHosts; + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, + &hkeyHosts) == ERROR_SUCCESS) + { + DWORD dwLength = MAX_PATH; + RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, (LPBYTE)tmp, + &dwLength); + ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH); + RegCloseKey(hkeyHosts); + } + } + else + GetWindowsDirectory(PATH_HOSTS, MAX_PATH); + + strcat(PATH_HOSTS, WIN_PATH_HOSTS); + +#elif defined(WATT32) + extern const char *_w32_GetHostsFile (void); + const char *PATH_HOSTS = _w32_GetHostsFile(); + + if (!PATH_HOSTS) + return ARES_ENOTFOUND; +#endif + + fp = fopen(PATH_HOSTS, "r"); + if (!fp) + { + error = ERRNO; + switch(error) + { + case ENOENT: + case ESRCH: + return ARES_ENOTFOUND; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", + PATH_HOSTS)); + *host = NULL; + return ARES_EFILE; + } + } + while ((status = ares__get_hostent(fp, family, host)) == ARES_SUCCESS) + { + if (strcasecmp((*host)->h_name, name) == 0) + break; + for (alias = (*host)->h_aliases; *alias; alias++) + { + if (strcasecmp(*alias, name) == 0) + break; + } + if (*alias) + break; + ares_free_hostent(*host); + } + fclose(fp); + if (status == ARES_EOF) + status = ARES_ENOTFOUND; + if (status != ARES_SUCCESS) + *host = NULL; + return status; +} + +static void sort_addresses(struct hostent *host, + const struct apattern *sortlist, int nsort) +{ + struct in_addr a1, a2; + int i1, i2, ind1, ind2; + + /* This is a simple insertion sort, not optimized at all. i1 walks + * through the address list, with the loop invariant that everything + * to the left of i1 is sorted. In the loop body, the value at i1 is moved + * back through the list (via i2) until it is in sorted order. + */ + for (i1 = 0; host->h_addr_list[i1]; i1++) + { + memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr)); + ind1 = get_address_index(&a1, sortlist, nsort); + for (i2 = i1 - 1; i2 >= 0; i2--) + { + memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr)); + ind2 = get_address_index(&a2, sortlist, nsort); + if (ind2 <= ind1) + break; + memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr)); + } + memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct in_addr)); + } +} + +/* Find the first entry in sortlist which matches addr. Return nsort + * if none of them match. + */ +static int get_address_index(const struct in_addr *addr, + const struct apattern *sortlist, + int nsort) +{ + int i; + + for (i = 0; i < nsort; i++) + { + if (sortlist[i].family != AF_INET) + continue; + if (sortlist[i].type == PATTERN_MASK) + { + if ((addr->s_addr & sortlist[i].mask.addr4.s_addr) + == sortlist[i].addrV4.s_addr) + break; + } + else + { + if (!ares_bitncmp(&addr->s_addr, &sortlist[i].addrV4.s_addr, + sortlist[i].mask.bits)) + break; + } + } + return i; +} + +static void sort6_addresses(struct hostent *host, + const struct apattern *sortlist, int nsort) +{ + struct ares_in6_addr a1, a2; + int i1, i2, ind1, ind2; + + /* This is a simple insertion sort, not optimized at all. i1 walks + * through the address list, with the loop invariant that everything + * to the left of i1 is sorted. In the loop body, the value at i1 is moved + * back through the list (via i2) until it is in sorted order. + */ + for (i1 = 0; host->h_addr_list[i1]; i1++) + { + memcpy(&a1, host->h_addr_list[i1], sizeof(struct ares_in6_addr)); + ind1 = get6_address_index(&a1, sortlist, nsort); + for (i2 = i1 - 1; i2 >= 0; i2--) + { + memcpy(&a2, host->h_addr_list[i2], sizeof(struct ares_in6_addr)); + ind2 = get6_address_index(&a2, sortlist, nsort); + if (ind2 <= ind1) + break; + memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct ares_in6_addr)); + } + memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct ares_in6_addr)); + } +} + +/* Find the first entry in sortlist which matches addr. Return nsort + * if none of them match. + */ +static int get6_address_index(const struct ares_in6_addr *addr, + const struct apattern *sortlist, + int nsort) +{ + int i; + + for (i = 0; i < nsort; i++) + { + if (sortlist[i].family != AF_INET6) + continue; + if (!ares_bitncmp(addr, + &sortlist[i].addrV6, + sortlist[i].mask.bits)) + break; + } + return i; +} diff --git a/src/rt/libuv/src/ares/ares_getnameinfo.c b/src/rt/libuv/src/ares/ares_getnameinfo.c new file mode 100644 index 00000000000..b6236862ed0 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_getnameinfo.c @@ -0,0 +1,426 @@ + +/* Copyright 2005 by Dominick Meglio + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ +#include "ares_setup.h" + +#ifdef HAVE_GETSERVBYPORT_R +# if !defined(GETSERVBYPORT_R_ARGS) || \ + (GETSERVBYPORT_R_ARGS < 4) || (GETSERVBYPORT_R_ARGS > 6) +# error "you MUST specifiy a valid number of arguments for getservbyport_r" +# endif +#endif + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#ifdef HAVE_NET_IF_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#include +#include +#include + +#include "ares.h" +#include "ares_ipv6.h" +#include "inet_ntop.h" +#include "ares_private.h" + +struct nameinfo_query { + ares_nameinfo_callback callback; + void *arg; + union { + struct sockaddr_in addr4; + struct sockaddr_in6 addr6; + } addr; + int family; + int flags; + int timeouts; +}; + +#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID +#define IPBUFSIZ \ + (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") + IF_NAMESIZE) +#else +#define IPBUFSIZ \ + (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")) +#endif + +static void nameinfo_callback(void *arg, int status, int timeouts, + struct hostent *host); +static char *lookup_service(unsigned short port, int flags, + char *buf, size_t buflen); +#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID +static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int scopeid, + char *buf, size_t buflen); +#endif +static char *ares_striendstr(const char *s1, const char *s2); + +void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa, + ares_socklen_t salen, + int flags, ares_nameinfo_callback callback, void *arg) +{ + struct sockaddr_in *addr = NULL; + struct sockaddr_in6 *addr6 = NULL; + struct nameinfo_query *niquery; + unsigned int port = 0; + + /* Validate socket address family and length */ + if ((sa->sa_family == AF_INET) && + (salen == sizeof(struct sockaddr_in))) + { + addr = (struct sockaddr_in *)sa; + port = addr->sin_port; + } + else if ((sa->sa_family == AF_INET6) && + (salen == sizeof(struct sockaddr_in6))) + { + addr6 = (struct sockaddr_in6 *)sa; + port = addr6->sin6_port; + } + else + { + callback(arg, ARES_ENOTIMP, 0, NULL, NULL); + return; + } + + /* If neither, assume they want a host */ + if (!(flags & ARES_NI_LOOKUPSERVICE) && !(flags & ARES_NI_LOOKUPHOST)) + flags |= ARES_NI_LOOKUPHOST; + + /* All they want is a service, no need for DNS */ + if ((flags & ARES_NI_LOOKUPSERVICE) && !(flags & ARES_NI_LOOKUPHOST)) + { + char buf[33], *service; + + service = lookup_service((unsigned short)(port & 0xffff), + flags, buf, sizeof(buf)); + callback(arg, ARES_SUCCESS, 0, NULL, service); + return; + } + + /* They want a host lookup */ + if ((flags & ARES_NI_LOOKUPHOST)) + { + /* A numeric host can be handled without DNS */ + if ((flags & ARES_NI_NUMERICHOST)) + { + char ipbuf[IPBUFSIZ]; + char srvbuf[33]; + char *service = NULL; + ipbuf[0] = 0; + + /* Specifying not to lookup a host, but then saying a host + * is required has to be illegal. + */ + if (flags & ARES_NI_NAMEREQD) + { + callback(arg, ARES_EBADFLAGS, 0, NULL, NULL); + return; + } + if (salen == sizeof(struct sockaddr_in6)) + { + ares_inet_ntop(AF_INET6, &addr6->sin6_addr, ipbuf, IPBUFSIZ); + /* If the system supports scope IDs, use it */ +#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID + append_scopeid(addr6, flags, ipbuf, sizeof(ipbuf)); +#endif + } + else + { + ares_inet_ntop(AF_INET, &addr->sin_addr, ipbuf, IPBUFSIZ); + } + /* They also want a service */ + if (flags & ARES_NI_LOOKUPSERVICE) + service = lookup_service((unsigned short)(port & 0xffff), + flags, srvbuf, sizeof(srvbuf)); + callback(arg, ARES_SUCCESS, 0, ipbuf, service); + return; + } + /* This is where a DNS lookup becomes necessary */ + else + { + niquery = malloc(sizeof(struct nameinfo_query)); + if (!niquery) + { + callback(arg, ARES_ENOMEM, 0, NULL, NULL); + return; + } + niquery->callback = callback; + niquery->arg = arg; + niquery->flags = flags; + niquery->timeouts = 0; + if (sa->sa_family == AF_INET) + { + niquery->family = AF_INET; + memcpy(&niquery->addr.addr4, addr, sizeof(addr)); + ares_gethostbyaddr(channel, &addr->sin_addr, + sizeof(struct in_addr), AF_INET, + nameinfo_callback, niquery); + } + else + { + niquery->family = AF_INET6; + memcpy(&niquery->addr.addr6, addr6, sizeof(addr6)); + ares_gethostbyaddr(channel, &addr6->sin6_addr, + sizeof(struct ares_in6_addr), AF_INET6, + nameinfo_callback, niquery); + } + } + } +} + +static void nameinfo_callback(void *arg, int status, int timeouts, + struct hostent *host) +{ + struct nameinfo_query *niquery = (struct nameinfo_query *) arg; + char srvbuf[33]; + char *service = NULL; + + niquery->timeouts += timeouts; + if (status == ARES_SUCCESS) + { + /* They want a service too */ + if (niquery->flags & ARES_NI_LOOKUPSERVICE) + { + if (niquery->family == AF_INET) + service = lookup_service(niquery->addr.addr4.sin_port, + niquery->flags, srvbuf, sizeof(srvbuf)); + else + service = lookup_service(niquery->addr.addr6.sin6_port, + niquery->flags, srvbuf, sizeof(srvbuf)); + } + /* NOFQDN means we have to strip off the domain name portion. We do + this by determining our own domain name, then searching the string + for this domain name and removing it. + */ +#ifdef HAVE_GETHOSTNAME + if (niquery->flags & ARES_NI_NOFQDN) + { + char buf[255]; + char *domain; + gethostname(buf, 255); + if ((domain = strchr(buf, '.')) != NULL) + { + char *end = ares_striendstr(host->h_name, domain); + if (end) + *end = 0; + } + } +#endif + niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, + (char *)(host->h_name), + service); + free(niquery); + return; + } + /* We couldn't find the host, but it's OK, we can use the IP */ + else if (status == ARES_ENOTFOUND && !(niquery->flags & ARES_NI_NAMEREQD)) + { + char ipbuf[IPBUFSIZ]; + if (niquery->family == AF_INET) + ares_inet_ntop(AF_INET, &niquery->addr.addr4.sin_addr, ipbuf, + IPBUFSIZ); + else + { + ares_inet_ntop(AF_INET6, &niquery->addr.addr6.sin6_addr, ipbuf, + IPBUFSIZ); +#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID + append_scopeid(&niquery->addr.addr6, niquery->flags, ipbuf, + sizeof(ipbuf)); +#endif + } + /* They want a service too */ + if (niquery->flags & ARES_NI_LOOKUPSERVICE) + { + if (niquery->family == AF_INET) + service = lookup_service(niquery->addr.addr4.sin_port, + niquery->flags, srvbuf, sizeof(srvbuf)); + else + service = lookup_service(niquery->addr.addr6.sin6_port, + niquery->flags, srvbuf, sizeof(srvbuf)); + } + niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, ipbuf, + service); + free(niquery); + return; + } + niquery->callback(niquery->arg, status, niquery->timeouts, NULL, NULL); + free(niquery); +} + +static char *lookup_service(unsigned short port, int flags, + char *buf, size_t buflen) +{ + const char *proto; + struct servent *sep; +#ifdef HAVE_GETSERVBYPORT_R + struct servent se; +#endif + char tmpbuf[4096]; + + if (port) + { + if (flags & ARES_NI_NUMERICSERV) + sep = NULL; + else + { + if (flags & ARES_NI_UDP) + proto = "udp"; + else if (flags & ARES_NI_SCTP) + proto = "sctp"; + else if (flags & ARES_NI_DCCP) + proto = "dccp"; + else + proto = "tcp"; +#ifdef HAVE_GETSERVBYPORT_R + sep = &se; + memset(tmpbuf, 0, sizeof(tmpbuf)); +#if GETSERVBYPORT_R_ARGS == 6 + if (getservbyport_r(port, proto, &se, (void *)tmpbuf, + sizeof(tmpbuf), &sep) != 0) + sep = NULL; +#elif GETSERVBYPORT_R_ARGS == 5 + sep = getservbyport_r(port, proto, &se, (void *)tmpbuf, + sizeof(tmpbuf)); +#elif GETSERVBYPORT_R_ARGS == 4 + if (getservbyport_r(port, proto, &se, (void *)tmpbuf) != 0) + sep = NULL; +#else + /* Lets just hope the OS uses TLS! */ + sep = getservbyport(port, proto); +#endif +#else + /* Lets just hope the OS uses TLS! */ +#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) + sep = getservbyport(port, (char*)proto); +#else + sep = getservbyport(port, proto); +#endif +#endif + } + if (sep && sep->s_name) + /* get service name */ + strcpy(tmpbuf, sep->s_name); + else + /* get port as a string */ + sprintf(tmpbuf, "%u", (unsigned int)ntohs(port)); + if (strlen(tmpbuf) < buflen) + /* return it if buffer big enough */ + strcpy(buf, tmpbuf); + else + /* avoid reusing previous one */ + buf[0] = '\0'; + return buf; + } + buf[0] = '\0'; + return NULL; +} + +#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID +static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags, + char *buf, size_t buflen) +{ +#ifdef HAVE_IF_INDEXTONAME + int is_ll, is_mcll; +#endif + static const char fmt_u[] = "%u"; + static const char fmt_lu[] = "%lu"; + char tmpbuf[IF_NAMESIZE + 2]; + size_t bufl; + const char *fmt = (sizeof(addr6->sin6_scope_id) > sizeof(unsigned int))? + fmt_lu:fmt_u; + + tmpbuf[0] = '%'; + +#ifdef HAVE_IF_INDEXTONAME + is_ll = IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr); + is_mcll = IN6_IS_ADDR_MC_LINKLOCAL(&addr6->sin6_addr); + if ((flags & ARES_NI_NUMERICSCOPE) || + (!is_ll && !is_mcll)) + { + sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id); + } + else + { + if (if_indextoname(addr6->sin6_scope_id, &tmpbuf[1]) == NULL) + sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id); + } +#else + sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id); + (void) flags; +#endif + tmpbuf[IF_NAMESIZE + 1] = '\0'; + bufl = strlen(buf); + + if(bufl + strlen(tmpbuf) < buflen) + /* only append the scopeid string if it fits in the target buffer */ + strcpy(&buf[bufl], tmpbuf); +} +#endif + +/* Determines if s1 ends with the string in s2 (case-insensitive) */ +static char *ares_striendstr(const char *s1, const char *s2) +{ + const char *c1, *c2, *c1_begin; + int lo1, lo2; + size_t s1_len = strlen(s1), s2_len = strlen(s2); + + /* If the substr is longer than the full str, it can't match */ + if (s2_len > s1_len) + return NULL; + + /* Jump to the end of s1 minus the length of s2 */ + c1_begin = s1+s1_len-s2_len; + c1 = (const char *)c1_begin; + c2 = s2; + while (c2 < s2+s2_len) + { + lo1 = TOLOWER(*c1); + lo2 = TOLOWER(*c2); + if (lo1 != lo2) + return NULL; + else + { + c1++; + c2++; + } + } + if (c2 == c1 && c2 == NULL) + return (char *)c1_begin; + return NULL; +} diff --git a/src/rt/libuv/src/ares/ares_getopt.c b/src/rt/libuv/src/ares/ares_getopt.c new file mode 100644 index 00000000000..1e02d086866 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_getopt.c @@ -0,0 +1,122 @@ +/* + * Original file name getopt.c Initial import into the c-ares source tree + * on 2007-04-11. Lifted from version 5.2 of the 'Open Mash' project with + * the modified BSD license, BSD license without the advertising clause. + * + */ + +/* + * getopt.c -- + * + * Standard UNIX getopt function. Code is from BSD. + * + * Copyright (c) 1987-2001 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * A. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * B. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * C. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS + * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* #if !defined(lint) + * static char sccsid[] = "@(#)getopt.c 8.2 (Berkeley) 4/2/94"; + * #endif + */ + +#include +#include +#include +#include "ares_getopt.h" + +int opterr = 1, /* if error message should be printed */ + optind = 1; /* index into parent argv vector */ +int optopt = 0; /* character checked for validity */ +static int optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG (char *)"" + +/* + * ares_getopt -- + * Parse argc/argv argument vector. + */ +int +ares_getopt(int nargc, char * const nargv[], const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (EOF); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (EOF); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + (oli = strchr(ostr, optopt)) == NULL) { + /* + * if the user didn't specify '-' as an option, + * assume it means EOF. + */ + if (optopt == (int)'-') + return (EOF); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "%s: illegal option -- %c\n", __FILE__, optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "%s: option requires an argument -- %c\n", + __FILE__, optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/src/rt/libuv/src/ares/ares_getopt.h b/src/rt/libuv/src/ares/ares_getopt.h new file mode 100644 index 00000000000..63acb3b4232 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_getopt.h @@ -0,0 +1,53 @@ +#ifndef ARES_GETOPT_H +#define ARES_GETOPT_H + +/* + * Copyright (c) 1987-2001 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * A. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * B. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * C. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS + * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +int ares_getopt(int nargc, char * const nargv[], const char *ostr); + +#undef optarg +#undef optind +#undef opterr +#undef optopt +#undef optreset + +#define optarg ares_optarg +#define optind ares_optind +#define opterr ares_opterr +#define optopt ares_optopt +#define optreset ares_optreset + +extern char *optarg; +extern int optind; +extern int opterr; +extern int optopt; + +#endif /* ARES_GETOPT_H */ diff --git a/src/rt/libuv/src/ares/ares_getsock.c b/src/rt/libuv/src/ares/ares_getsock.c new file mode 100644 index 00000000000..72e467f2e63 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_getsock.c @@ -0,0 +1,72 @@ + +/* Copyright (C) 2005 - 2010, Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#include "ares.h" +#include "ares_private.h" + +int ares_getsock(ares_channel channel, + ares_socket_t *socks, + int numsocks) /* size of the 'socks' array */ +{ + struct server_state *server; + int i; + int sockindex=0; + int bitmap = 0; + unsigned int setbits = 0xffffffff; + + /* Are there any active queries? */ + int active_queries = !ares__is_list_empty(&(channel->all_queries)); + + for (i = 0; + (i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM); + i++) + { + server = &channel->servers[i]; + /* We only need to register interest in UDP sockets if we have + * outstanding queries. + */ + if (active_queries && server->udp_socket != ARES_SOCKET_BAD) + { + if(sockindex >= numsocks) + break; + socks[sockindex] = server->udp_socket; + bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex); + sockindex++; + } + /* We always register for TCP events, because we want to know + * when the other side closes the connection, so we don't waste + * time trying to use a broken connection. + */ + if (server->tcp_socket != ARES_SOCKET_BAD) + { + if(sockindex >= numsocks) + break; + socks[sockindex] = server->tcp_socket; + bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex); + + if (server->qhead && active_queries) + /* then the tcp socket is also writable! */ + bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex); + + sockindex++; + } + } + return bitmap; +} diff --git a/src/rt/libuv/src/ares/ares_init.c b/src/rt/libuv/src/ares/ares_init.c new file mode 100644 index 00000000000..d7954a06b28 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_init.c @@ -0,0 +1,1665 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2007-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef USE_WINSOCK +#include +#endif + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifdef HAVE_NETDB_H +#include +#endif + +#ifdef HAVE_ARPA_INET_H +#include +#endif + +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include "ares.h" +#include "inet_net_pton.h" +#include "ares_library_init.h" +#include "ares_nowarn.h" +#include "ares_private.h" + +#ifdef ANDROID +#include +#endif + +#ifdef WATT32 +#undef WIN32 /* Redefined in MingW/MSVC headers */ +#endif + +static int init_by_options(ares_channel channel, const struct ares_options *options, + int optmask); +static int init_by_environment(ares_channel channel); +static int init_by_resolv_conf(ares_channel channel); +static int init_by_defaults(ares_channel channel); + +#ifndef WATT32 +static int config_nameserver(struct server_state **servers, int *nservers, + char *str); +#endif +static int set_search(ares_channel channel, const char *str); +static int set_options(ares_channel channel, const char *str); +static const char *try_option(const char *p, const char *q, const char *opt); +static int init_id_key(rc4_key* key,int key_data_len); + +#if !defined(WIN32) && !defined(WATT32) +static int sortlist_alloc(struct apattern **sortlist, int *nsort, struct apattern *pat); +static int ip_addr(const char *s, ssize_t len, struct in_addr *addr); +static void natural_mask(struct apattern *pat); +static int config_domain(ares_channel channel, char *str); +static int config_lookup(ares_channel channel, const char *str, + const char *bindch, const char *filech); +static int config_sortlist(struct apattern **sortlist, int *nsort, + const char *str); +static char *try_config(char *s, const char *opt); +#endif + +#define ARES_CONFIG_CHECK(x) (x->lookups && x->nsort > -1 && \ + x->nservers > -1 && \ + x->ndomains > -1 && \ + x->ndots > -1 && x->timeout > -1 && \ + x->tries > -1) + +int ares_init(ares_channel *channelptr) +{ + return ares_init_options(channelptr, NULL, 0); +} + +int ares_init_options(ares_channel *channelptr, struct ares_options *options, + int optmask) +{ + ares_channel channel; + int i; + int status = ARES_SUCCESS; + struct timeval now; + +#ifdef CURLDEBUG + const char *env = getenv("CARES_MEMDEBUG"); + + if (env) + curl_memdebug(env); + env = getenv("CARES_MEMLIMIT"); + if (env) { + char *endptr; + long num = strtol(env, &endptr, 10); + if((endptr != env) && (endptr == env + strlen(env)) && (num > 0)) + curl_memlimit(num); + } +#endif + + if (ares_library_initialized() != ARES_SUCCESS) + return ARES_ENOTINITIALIZED; + + channel = malloc(sizeof(struct ares_channeldata)); + if (!channel) { + *channelptr = NULL; + return ARES_ENOMEM; + } + + now = ares__tvnow(); + + /* Set everything to distinguished values so we know they haven't + * been set yet. + */ + channel->flags = -1; + channel->timeout = -1; + channel->tries = -1; + channel->ndots = -1; + channel->rotate = -1; + channel->udp_port = -1; + channel->tcp_port = -1; + channel->socket_send_buffer_size = -1; + channel->socket_receive_buffer_size = -1; + channel->nservers = -1; + channel->ndomains = -1; + channel->nsort = -1; + channel->tcp_connection_generation = 0; + channel->lookups = NULL; + channel->domains = NULL; + channel->sortlist = NULL; + channel->servers = NULL; + channel->sock_state_cb = NULL; + channel->sock_state_cb_data = NULL; + channel->sock_create_cb = NULL; + channel->sock_create_cb_data = NULL; + + channel->last_server = 0; + channel->last_timeout_processed = (time_t)now.tv_sec; + + memset(&channel->local_dev_name, 0, sizeof(channel->local_dev_name)); + channel->local_ip4 = 0; + memset(&channel->local_ip6, 0, sizeof(channel->local_ip6)); + + /* Initialize our lists of queries */ + ares__init_list_head(&(channel->all_queries)); + for (i = 0; i < ARES_QID_TABLE_SIZE; i++) + { + ares__init_list_head(&(channel->queries_by_qid[i])); + } + for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++) + { + ares__init_list_head(&(channel->queries_by_timeout[i])); + } + + /* Initialize configuration by each of the four sources, from highest + * precedence to lowest. + */ + + if (status == ARES_SUCCESS) { + status = init_by_options(channel, options, optmask); + if (status != ARES_SUCCESS) + DEBUGF(fprintf(stderr, "Error: init_by_options failed: %s\n", + ares_strerror(status))); + } + if (status == ARES_SUCCESS) { + status = init_by_environment(channel); + if (status != ARES_SUCCESS) + DEBUGF(fprintf(stderr, "Error: init_by_environment failed: %s\n", + ares_strerror(status))); + } + if (status == ARES_SUCCESS) { + status = init_by_resolv_conf(channel); + if (status != ARES_SUCCESS) + DEBUGF(fprintf(stderr, "Error: init_by_resolv_conf failed: %s\n", + ares_strerror(status))); + } + + /* + * No matter what failed or succeeded, seed defaults to provide + * useful behavior for things that we missed. + */ + status = init_by_defaults(channel); + if (status != ARES_SUCCESS) + DEBUGF(fprintf(stderr, "Error: init_by_defaults failed: %s\n", + ares_strerror(status))); + + /* Generate random key */ + + if (status == ARES_SUCCESS) { + status = init_id_key(&channel->id_key, ARES_ID_KEY_LEN); + if (status == ARES_SUCCESS) + channel->next_id = ares__generate_new_id(&channel->id_key); + else + DEBUGF(fprintf(stderr, "Error: init_id_key failed: %s\n", + ares_strerror(status))); + } + + if (status != ARES_SUCCESS) + { + /* Something failed; clean up memory we may have allocated. */ + if (channel->servers) + free(channel->servers); + if (channel->domains) + { + for (i = 0; i < channel->ndomains; i++) + free(channel->domains[i]); + free(channel->domains); + } + if (channel->sortlist) + free(channel->sortlist); + if(channel->lookups) + free(channel->lookups); + free(channel); + return status; + } + + /* Trim to one server if ARES_FLAG_PRIMARY is set. */ + if ((channel->flags & ARES_FLAG_PRIMARY) && channel->nservers > 1) + channel->nservers = 1; + + ares__init_servers_state(channel); + + *channelptr = channel; + return ARES_SUCCESS; +} + +/* ares_dup() duplicates a channel handle with all its options and returns a + new channel handle */ +int ares_dup(ares_channel *dest, ares_channel src) +{ + struct ares_options opts; + struct ares_addr_node *servers; + int ipv6_nservers = 0; + int i, rc; + int optmask; + + *dest = NULL; /* in case of failure return NULL explicitly */ + + /* First get the options supported by the old ares_save_options() function, + which is most of them */ + rc = ares_save_options(src, &opts, &optmask); + if(rc) + return rc; + + /* Then create the new channel with those options */ + rc = ares_init_options(dest, &opts, optmask); + + /* destroy the options copy to not leak any memory */ + ares_destroy_options(&opts); + + if(rc) + return rc; + + /* Now clone the options that ares_save_options() doesn't support. */ + (*dest)->sock_create_cb = src->sock_create_cb; + (*dest)->sock_create_cb_data = src->sock_create_cb_data; + + strncpy((*dest)->local_dev_name, src->local_dev_name, sizeof(src->local_dev_name)); + (*dest)->local_ip4 = src->local_ip4; + memcpy((*dest)->local_ip6, src->local_ip6, sizeof(src->local_ip6)); + + /* Full name server cloning required when not all are IPv4 */ + for (i = 0; i < src->nservers; i++) + { + if (src->servers[i].addr.family != AF_INET) { + ipv6_nservers++; + break; + } + } + if (ipv6_nservers) { + rc = ares_get_servers(src, &servers); + if (rc != ARES_SUCCESS) + return rc; + rc = ares_set_servers(*dest, servers); + ares_free_data(servers); + if (rc != ARES_SUCCESS) + return rc; + } + + return ARES_SUCCESS; /* everything went fine */ +} + +/* Save options from initialized channel */ +int ares_save_options(ares_channel channel, struct ares_options *options, + int *optmask) +{ + int i, j; + int ipv4_nservers = 0; + + /* Zero everything out */ + memset(options, 0, sizeof(struct ares_options)); + + if (!ARES_CONFIG_CHECK(channel)) + return ARES_ENODATA; + + /* Traditionally the optmask wasn't saved in the channel struct so it was + recreated here. ROTATE is the first option that has no struct field of + its own in the public config struct */ + (*optmask) = (ARES_OPT_FLAGS|ARES_OPT_TRIES|ARES_OPT_NDOTS| + ARES_OPT_UDP_PORT|ARES_OPT_TCP_PORT|ARES_OPT_SOCK_STATE_CB| + ARES_OPT_SERVERS|ARES_OPT_DOMAINS|ARES_OPT_LOOKUPS| + ARES_OPT_SORTLIST|ARES_OPT_TIMEOUTMS) | + (channel->optmask & ARES_OPT_ROTATE); + + /* Copy easy stuff */ + options->flags = channel->flags; + + /* We return full millisecond resolution but that's only because we don't + set the ARES_OPT_TIMEOUT anymore, only the new ARES_OPT_TIMEOUTMS */ + options->timeout = channel->timeout; + options->tries = channel->tries; + options->ndots = channel->ndots; + options->udp_port = (unsigned short)channel->udp_port; + options->tcp_port = (unsigned short)channel->tcp_port; + options->sock_state_cb = channel->sock_state_cb; + options->sock_state_cb_data = channel->sock_state_cb_data; + + /* Copy IPv4 servers */ + if (channel->nservers) { + for (i = 0; i < channel->nservers; i++) + { + if (channel->servers[i].addr.family == AF_INET) + ipv4_nservers++; + } + if (ipv4_nservers) { + options->servers = malloc(ipv4_nservers * sizeof(struct server_state)); + if (!options->servers) + return ARES_ENOMEM; + for (i = j = 0; i < channel->nservers; i++) + { + if (channel->servers[i].addr.family == AF_INET) + memcpy(&options->servers[j++], + &channel->servers[i].addr.addrV4, + sizeof(channel->servers[i].addr.addrV4)); + } + } + } + options->nservers = ipv4_nservers; + + /* copy domains */ + if (channel->ndomains) { + options->domains = malloc(channel->ndomains * sizeof(char *)); + if (!options->domains) + return ARES_ENOMEM; + + for (i = 0; i < channel->ndomains; i++) + { + options->ndomains = i; + options->domains[i] = strdup(channel->domains[i]); + if (!options->domains[i]) + return ARES_ENOMEM; + } + } + options->ndomains = channel->ndomains; + + /* copy lookups */ + if (channel->lookups) { + options->lookups = strdup(channel->lookups); + if (!options->lookups && channel->lookups) + return ARES_ENOMEM; + } + + /* copy sortlist */ + if (channel->nsort) { + options->sortlist = malloc(channel->nsort * sizeof(struct apattern)); + if (!options->sortlist) + return ARES_ENOMEM; + for (i = 0; i < channel->nsort; i++) + options->sortlist[i] = channel->sortlist[i]; + } + options->nsort = channel->nsort; + + return ARES_SUCCESS; +} + +static int init_by_options(ares_channel channel, + const struct ares_options *options, + int optmask) +{ + int i; + + /* Easy stuff. */ + if ((optmask & ARES_OPT_FLAGS) && channel->flags == -1) + channel->flags = options->flags; + if ((optmask & ARES_OPT_TIMEOUTMS) && channel->timeout == -1) + channel->timeout = options->timeout; + else if ((optmask & ARES_OPT_TIMEOUT) && channel->timeout == -1) + channel->timeout = options->timeout * 1000; + if ((optmask & ARES_OPT_TRIES) && channel->tries == -1) + channel->tries = options->tries; + if ((optmask & ARES_OPT_NDOTS) && channel->ndots == -1) + channel->ndots = options->ndots; + if ((optmask & ARES_OPT_ROTATE) && channel->rotate == -1) + channel->rotate = 1; + if ((optmask & ARES_OPT_UDP_PORT) && channel->udp_port == -1) + channel->udp_port = options->udp_port; + if ((optmask & ARES_OPT_TCP_PORT) && channel->tcp_port == -1) + channel->tcp_port = options->tcp_port; + if ((optmask & ARES_OPT_SOCK_STATE_CB) && channel->sock_state_cb == NULL) + { + channel->sock_state_cb = options->sock_state_cb; + channel->sock_state_cb_data = options->sock_state_cb_data; + } + if ((optmask & ARES_OPT_SOCK_SNDBUF) + && channel->socket_send_buffer_size == -1) + channel->socket_send_buffer_size = options->socket_send_buffer_size; + if ((optmask & ARES_OPT_SOCK_RCVBUF) + && channel->socket_receive_buffer_size == -1) + channel->socket_receive_buffer_size = options->socket_receive_buffer_size; + + /* Copy the IPv4 servers, if given. */ + if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1) + { + /* Avoid zero size allocations at any cost */ + if (options->nservers > 0) + { + channel->servers = + malloc(options->nservers * sizeof(struct server_state)); + if (!channel->servers) + return ARES_ENOMEM; + for (i = 0; i < options->nservers; i++) + { + channel->servers[i].addr.family = AF_INET; + memcpy(&channel->servers[i].addr.addrV4, + &options->servers[i], + sizeof(channel->servers[i].addr.addrV4)); + } + } + channel->nservers = options->nservers; + } + + /* Copy the domains, if given. Keep channel->ndomains consistent so + * we can clean up in case of error. + */ + if ((optmask & ARES_OPT_DOMAINS) && channel->ndomains == -1) + { + /* Avoid zero size allocations at any cost */ + if (options->ndomains > 0) + { + channel->domains = malloc(options->ndomains * sizeof(char *)); + if (!channel->domains) + return ARES_ENOMEM; + for (i = 0; i < options->ndomains; i++) + { + channel->ndomains = i; + channel->domains[i] = strdup(options->domains[i]); + if (!channel->domains[i]) + return ARES_ENOMEM; + } + } + channel->ndomains = options->ndomains; + } + + /* Set lookups, if given. */ + if ((optmask & ARES_OPT_LOOKUPS) && !channel->lookups) + { + channel->lookups = strdup(options->lookups); + if (!channel->lookups) + return ARES_ENOMEM; + } + + /* copy sortlist */ + if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1) && + (options->nsort>0)) { + channel->sortlist = malloc(options->nsort * sizeof(struct apattern)); + if (!channel->sortlist) + return ARES_ENOMEM; + for (i = 0; i < options->nsort; i++) + channel->sortlist[i] = options->sortlist[i]; + channel->nsort = options->nsort; + } + + channel->optmask = optmask; + + return ARES_SUCCESS; +} + +static int init_by_environment(ares_channel channel) +{ + const char *localdomain, *res_options; + int status; + + localdomain = getenv("LOCALDOMAIN"); + if (localdomain && channel->ndomains == -1) + { + status = set_search(channel, localdomain); + if (status != ARES_SUCCESS) + return status; + } + + res_options = getenv("RES_OPTIONS"); + if (res_options) + { + status = set_options(channel, res_options); + if (status != ARES_SUCCESS) + return status; + } + + return ARES_SUCCESS; +} + +#ifdef WIN32 +/* + * Warning: returns a dynamically allocated buffer, the user MUST + * use free() if the function returns 1 + */ +static int get_res_nt(HKEY hKey, const char *subkey, char **obuf) +{ + /* Test for the size we need */ + DWORD size = 0; + int result; + + result = RegQueryValueEx(hKey, subkey, 0, NULL, NULL, &size); + if ((result != ERROR_SUCCESS && result != ERROR_MORE_DATA) || !size) + return 0; + *obuf = malloc(size+1); + if (!*obuf) + return 0; + + if (RegQueryValueEx(hKey, subkey, 0, NULL, + (LPBYTE)*obuf, &size) != ERROR_SUCCESS) + { + free(*obuf); + return 0; + } + if (size == 1) + { + free(*obuf); + return 0; + } + return 1; +} + +static int get_res_interfaces_nt(HKEY hKey, const char *subkey, char **obuf) +{ + char enumbuf[39]; /* GUIDs are 38 chars + 1 for NULL */ + DWORD enum_size = 39; + int idx = 0; + HKEY hVal; + + while (RegEnumKeyEx(hKey, idx++, enumbuf, &enum_size, 0, + NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS) + { + int rc; + + enum_size = 39; + if (RegOpenKeyEx(hKey, enumbuf, 0, KEY_QUERY_VALUE, &hVal) != + ERROR_SUCCESS) + continue; + rc = get_res_nt(hVal, subkey, obuf); + RegCloseKey(hVal); + if (rc) + return 1; + } + return 0; +} + +static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size) +{ + FIXED_INFO *fi, *newfi; + DWORD size = sizeof (*fi); + IP_ADDR_STRING *ipAddr; + int i, count = 0; + int debug = 0; + size_t ip_size = sizeof("255.255.255.255,")-1; + size_t left = ret_size; + char *ret = ret_buf; + HRESULT res; + + fi = malloc(size); + if (!fi) + return 0; + + res = (*ares_fpGetNetworkParams) (fi, &size); + if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS)) + goto quit; + + newfi = realloc(fi, size); + if (!newfi) + goto quit; + + fi = newfi; + res = (*ares_fpGetNetworkParams) (fi, &size); + if (res != ERROR_SUCCESS) + goto quit; + + if (debug) + { + printf ("Host Name: %s\n", fi->HostName); + printf ("Domain Name: %s\n", fi->DomainName); + printf ("DNS Servers:\n" + " %s (primary)\n", fi->DnsServerList.IpAddress.String); + } + if (strlen(fi->DnsServerList.IpAddress.String) > 0 && + inet_addr(fi->DnsServerList.IpAddress.String) != INADDR_NONE && + left > ip_size) + { + ret += sprintf (ret, "%s,", fi->DnsServerList.IpAddress.String); + left -= ret - ret_buf; + count++; + } + + for (i = 0, ipAddr = fi->DnsServerList.Next; ipAddr && left > ip_size; + ipAddr = ipAddr->Next, i++) + { + if (inet_addr(ipAddr->IpAddress.String) != INADDR_NONE) + { + ret += sprintf (ret, "%s,", ipAddr->IpAddress.String); + left -= ret - ret_buf; + count++; + } + if (debug) + printf (" %s (secondary %d)\n", ipAddr->IpAddress.String, i+1); + } + +quit: + if (fi) + free(fi); + + if (debug && left <= ip_size) + printf ("Too many nameservers. Truncating to %d addressess", count); + if (ret > ret_buf) + ret[-1] = '\0'; + return count; +} +#endif + +static int init_by_resolv_conf(ares_channel channel) +{ +#ifndef WATT32 + char *line = NULL; +#endif + int status = -1, nservers = 0, nsort = 0; + struct server_state *servers = NULL; + struct apattern *sortlist = NULL; + +#ifdef WIN32 + + /* + NameServer info via IPHLPAPI (IP helper API): + GetNetworkParams() should be the trusted source for this. + Available in Win-98/2000 and later. If that fail, fall-back to + registry information. + + NameServer Registry: + + On Windows 9X, the DNS server can be found in: +HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP\NameServer + + On Windows NT/2000/XP/2003: +HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer + or +HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer + or +HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\ +NameServer + or +HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\ +DhcpNameServer + */ + + HKEY mykey; + HKEY subkey; + DWORD data_type; + DWORD bytes; + DWORD result; + char buf[256]; + + if (channel->nservers > -1) /* don't override ARES_OPT_SERVER */ + return ARES_SUCCESS; + + if (get_iphlpapi_dns_info(buf,sizeof(buf)) > 0) + { + status = config_nameserver(&servers, &nservers, buf); + if (status == ARES_SUCCESS) + goto okay; + } + + if (IS_NT()) + { + if (RegOpenKeyEx( + HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, + KEY_READ, &mykey + ) == ERROR_SUCCESS) + { + RegOpenKeyEx(mykey, "Interfaces", 0, + KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &subkey); + if (get_res_nt(mykey, NAMESERVER, &line)) + { + status = config_nameserver(&servers, &nservers, line); + free(line); + } + else if (get_res_nt(mykey, DHCPNAMESERVER, &line)) + { + status = config_nameserver(&servers, &nservers, line); + free(line); + } + /* Try the interfaces */ + else if (get_res_interfaces_nt(subkey, NAMESERVER, &line)) + { + status = config_nameserver(&servers, &nservers, line); + free(line); + } + else if (get_res_interfaces_nt(subkey, DHCPNAMESERVER, &line)) + { + status = config_nameserver(&servers, &nservers, line); + free(line); + } + RegCloseKey(subkey); + RegCloseKey(mykey); + } + } + else + { + if (RegOpenKeyEx( + HKEY_LOCAL_MACHINE, WIN_NS_9X, 0, + KEY_READ, &mykey + ) == ERROR_SUCCESS) + { + if ((result = RegQueryValueEx( + mykey, NAMESERVER, NULL, &data_type, + NULL, &bytes + ) + ) == ERROR_SUCCESS || + result == ERROR_MORE_DATA) + { + if (bytes) + { + line = malloc(bytes+1); + if (RegQueryValueEx(mykey, NAMESERVER, NULL, &data_type, + (unsigned char *)line, &bytes) == + ERROR_SUCCESS) + { + status = config_nameserver(&servers, &nservers, line); + } + free(line); + } + } + } + RegCloseKey(mykey); + } + + if (status == ARES_SUCCESS) + status = ARES_EOF; + else + /* Catch the case when all the above checks fail (which happens when there + is no network card or the cable is unplugged) */ + status = ARES_EFILE; + +#elif defined(__riscos__) + + /* Under RISC OS, name servers are listed in the + system variable Inet$Resolvers, space separated. */ + + line = getenv("Inet$Resolvers"); + status = ARES_EOF; + if (line) { + char *resolvers = strdup(line), *pos, *space; + + if (!resolvers) + return ARES_ENOMEM; + + pos = resolvers; + do { + space = strchr(pos, ' '); + if (space) + *space = '\0'; + status = config_nameserver(&servers, &nservers, pos); + if (status != ARES_SUCCESS) + break; + pos = space + 1; + } while (space); + + if (status == ARES_SUCCESS) + status = ARES_EOF; + + free(resolvers); + } + +#elif defined(WATT32) + int i; + + sock_init(); + for (i = 0; def_nameservers[i]; i++) + ; + if (i == 0) + return ARES_SUCCESS; /* use localhost DNS server */ + + nservers = i; + servers = calloc(i, sizeof(struct server_state)); + if (!servers) + return ARES_ENOMEM; + + for (i = 0; def_nameservers[i]; i++) + servers[i].addr.addrV4.s_addr = htonl(def_nameservers[i]); + status = ARES_EOF; + +#elif defined(ANDROID) + char value[PROP_VALUE_MAX]=""; + __system_property_get("net.dns1", value); + status = config_nameserver(&servers, &nservers, value); + if (status == ARES_SUCCESS) + status = ARES_EOF; +#else + { + char *p; + FILE *fp; + size_t linesize; + int error; + + /* Don't read resolv.conf and friends if we don't have to */ + if (ARES_CONFIG_CHECK(channel)) + return ARES_SUCCESS; + + fp = fopen(PATH_RESOLV_CONF, "r"); + if (fp) { + while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) + { + if ((p = try_config(line, "domain"))) + status = config_domain(channel, p); + else if ((p = try_config(line, "lookup")) && !channel->lookups) + status = config_lookup(channel, p, "bind", "file"); + else if ((p = try_config(line, "search"))) + status = set_search(channel, p); + else if ((p = try_config(line, "nameserver")) && channel->nservers == -1) + status = config_nameserver(&servers, &nservers, p); + else if ((p = try_config(line, "sortlist")) && channel->nsort == -1) + status = config_sortlist(&sortlist, &nsort, p); + else if ((p = try_config(line, "options"))) + status = set_options(channel, p); + else + status = ARES_SUCCESS; + if (status != ARES_SUCCESS) + break; + } + fclose(fp); + } + else { + error = ERRNO; + switch(error) { + case ENOENT: + case ESRCH: + status = ARES_EOF; + break; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", PATH_RESOLV_CONF)); + status = ARES_EFILE; + } + } + + if ((status == ARES_EOF) && (!channel->lookups)) { + /* Many systems (Solaris, Linux, BSD's) use nsswitch.conf */ + fp = fopen("/etc/nsswitch.conf", "r"); + if (fp) { + while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) + { + if ((p = try_config(line, "hosts:")) && !channel->lookups) + status = config_lookup(channel, p, "dns", "files"); + } + fclose(fp); + } + else { + error = ERRNO; + switch(error) { + case ENOENT: + case ESRCH: + status = ARES_EOF; + break; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/nsswitch.conf")); + status = ARES_EFILE; + } + } + } + + if ((status == ARES_EOF) && (!channel->lookups)) { + /* Linux / GNU libc 2.x and possibly others have host.conf */ + fp = fopen("/etc/host.conf", "r"); + if (fp) { + while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) + { + if ((p = try_config(line, "order")) && !channel->lookups) + status = config_lookup(channel, p, "bind", "hosts"); + } + fclose(fp); + } + else { + error = ERRNO; + switch(error) { + case ENOENT: + case ESRCH: + status = ARES_EOF; + break; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/host.conf")); + status = ARES_EFILE; + } + } + } + + if ((status == ARES_EOF) && (!channel->lookups)) { + /* Tru64 uses /etc/svc.conf */ + fp = fopen("/etc/svc.conf", "r"); + if (fp) { + while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) + { + if ((p = try_config(line, "hosts=")) && !channel->lookups) + status = config_lookup(channel, p, "bind", "local"); + } + fclose(fp); + } + else { + error = ERRNO; + switch(error) { + case ENOENT: + case ESRCH: + status = ARES_EOF; + break; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/svc.conf")); + status = ARES_EFILE; + } + } + } + + if(line) + free(line); + } + +#endif + + /* Handle errors. */ + if (status != ARES_EOF) + { + if (servers != NULL) + free(servers); + if (sortlist != NULL) + free(sortlist); + return status; + } + + /* If we got any name server entries, fill them in. */ +#ifdef WIN32 +okay: +#endif + if (servers) + { + channel->servers = servers; + channel->nservers = nservers; + } + + /* If we got any sortlist entries, fill them in. */ + if (sortlist) + { + channel->sortlist = sortlist; + channel->nsort = nsort; + } + + return ARES_SUCCESS; +} + +static int init_by_defaults(ares_channel channel) +{ + char *hostname = NULL; + int rc = ARES_SUCCESS; +#ifdef HAVE_GETHOSTNAME + char *dot; +#endif + + if (channel->flags == -1) + channel->flags = 0; + if (channel->timeout == -1) + channel->timeout = DEFAULT_TIMEOUT; + if (channel->tries == -1) + channel->tries = DEFAULT_TRIES; + if (channel->ndots == -1) + channel->ndots = 1; + if (channel->rotate == -1) + channel->rotate = 0; + if (channel->udp_port == -1) + channel->udp_port = htons(NAMESERVER_PORT); + if (channel->tcp_port == -1) + channel->tcp_port = htons(NAMESERVER_PORT); + + if (channel->nservers == -1) { + /* If nobody specified servers, try a local named. */ + channel->servers = malloc(sizeof(struct server_state)); + if (!channel->servers) { + rc = ARES_ENOMEM; + goto error; + } + channel->servers[0].addr.family = AF_INET; + channel->servers[0].addr.addrV4.s_addr = htonl(INADDR_LOOPBACK); + channel->nservers = 1; + } + +#ifdef ENAMETOOLONG +#define toolong(x) (x == -1) && ((ENAMETOOLONG == errno) || (EINVAL == errno)) +#else +#define toolong(x) (x == -1) && (EINVAL == errno) +#endif + + if (channel->ndomains == -1) { + /* Derive a default domain search list from the kernel hostname, + * or set it to empty if the hostname isn't helpful. + */ + size_t len = 64; + int res; + channel->ndomains = 0; /* default to none */ + +#ifdef HAVE_GETHOSTNAME + hostname = malloc(len); + if(!hostname) { + rc = ARES_ENOMEM; + goto error; + } + + do { + res = gethostname(hostname, len); + + if(toolong(res)) { + char *p; + len *= 2; + p = realloc(hostname, len); + if(!p) { + rc = ARES_ENOMEM; + goto error; + } + hostname = p; + continue; + } + else if(res) { + rc = ARES_EBADNAME; + goto error; + } + + } while(0); + + dot = strchr(hostname, '.'); + if (dot) { + /* a dot was found */ + channel->domains = malloc(sizeof(char *)); + if (!channel->domains) { + rc = ARES_ENOMEM; + goto error; + } + channel->domains[0] = strdup(dot + 1); + if (!channel->domains[0]) { + rc = ARES_ENOMEM; + goto error; + } + channel->ndomains = 1; + } +#endif + } + + if (channel->nsort == -1) { + channel->sortlist = NULL; + channel->nsort = 0; + } + + if (!channel->lookups) { + channel->lookups = strdup("fb"); + if (!channel->lookups) + rc = ARES_ENOMEM; + } + + error: + if(rc) { + if(channel->servers) + free(channel->servers); + + if(channel->domains && channel->domains[0]) + free(channel->domains[0]); + if(channel->domains) + free(channel->domains); + if(channel->lookups) + free(channel->lookups); + } + + if(hostname) + free(hostname); + + return rc; +} + +#if !defined(WIN32) && !defined(WATT32) +static int config_domain(ares_channel channel, char *str) +{ + char *q; + + /* Set a single search domain. */ + q = str; + while (*q && !ISSPACE(*q)) + q++; + *q = '\0'; + return set_search(channel, str); +} + +#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 910) && \ + defined(__OPTIMIZE__) && defined(__unix__) && defined(__i386__) + /* workaround icc 9.1 optimizer issue */ +# define vqualifier volatile +#else +# define vqualifier +#endif + +static int config_lookup(ares_channel channel, const char *str, + const char *bindch, const char *filech) +{ + char lookups[3], *l; + const char *vqualifier p; + + /* Set the lookup order. Only the first letter of each work + * is relevant, and it has to be "b" for DNS or "f" for the + * host file. Ignore everything else. + */ + l = lookups; + p = str; + while (*p) + { + if ((*p == *bindch || *p == *filech) && l < lookups + 2) { + if (*p == *bindch) *l++ = 'b'; + else *l++ = 'f'; + } + while (*p && !ISSPACE(*p) && (*p != ',')) + p++; + while (*p && (ISSPACE(*p) || (*p == ','))) + p++; + } + *l = '\0'; + channel->lookups = strdup(lookups); + return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM; +} +#endif /* !WIN32 & !WATT32 */ + +#ifndef WATT32 +static int config_nameserver(struct server_state **servers, int *nservers, + char *str) +{ + struct ares_addr host; + struct server_state *newserv; + char *p, *txtaddr; + /* On Windows, there may be more than one nameserver specified in the same + * registry key, so we parse input as a space or comma seperated list. + */ + for (p = str; p;) + { + /* Skip whitespace and commas. */ + while (*p && (ISSPACE(*p) || (*p == ','))) + p++; + if (!*p) + /* No more input, done. */ + break; + + /* Pointer to start of IPv4 or IPv6 address part. */ + txtaddr = p; + + /* Advance past this address. */ + while (*p && !ISSPACE(*p) && (*p != ',')) + p++; + if (*p) + /* Null terminate this address. */ + *p++ = '\0'; + else + /* Reached end of input, done when this address is processed. */ + p = NULL; + + /* Convert textual address to binary format. */ + if (ares_inet_pton(AF_INET, txtaddr, &host.addrV4) == 1) + host.family = AF_INET; + else if (ares_inet_pton(AF_INET6, txtaddr, &host.addrV6) == 1) + host.family = AF_INET6; + else + continue; + + /* Resize servers state array. */ + newserv = realloc(*servers, (*nservers + 1) * + sizeof(struct server_state)); + if (!newserv) + return ARES_ENOMEM; + + /* Store address data. */ + newserv[*nservers].addr.family = host.family; + if (host.family == AF_INET) + memcpy(&newserv[*nservers].addr.addrV4, &host.addrV4, + sizeof(host.addrV4)); + else + memcpy(&newserv[*nservers].addr.addrV6, &host.addrV6, + sizeof(host.addrV6)); + + /* Update arguments. */ + *servers = newserv; + *nservers += 1; + } + + return ARES_SUCCESS; +} + +#ifndef WIN32 +static int config_sortlist(struct apattern **sortlist, int *nsort, + const char *str) +{ + struct apattern pat; + const char *q; + + /* Add sortlist entries. */ + while (*str && *str != ';') + { + int bits; + char ipbuf[16], ipbufpfx[32]; + /* Find just the IP */ + q = str; + while (*q && *q != '/' && *q != ';' && !ISSPACE(*q)) + q++; + memcpy(ipbuf, str, q-str); + ipbuf[q-str] = '\0'; + /* Find the prefix */ + if (*q == '/') + { + const char *str2 = q+1; + while (*q && *q != ';' && !ISSPACE(*q)) + q++; + memcpy(ipbufpfx, str, q-str); + ipbufpfx[q-str] = '\0'; + str = str2; + } + else + ipbufpfx[0] = '\0'; + /* Lets see if it is CIDR */ + /* First we'll try IPv6 */ + if ((bits = ares_inet_net_pton(AF_INET6, ipbufpfx[0] ? ipbufpfx : ipbuf, + &pat.addrV6, + sizeof(pat.addrV6))) > 0) + { + pat.type = PATTERN_CIDR; + pat.mask.bits = (unsigned short)bits; + pat.family = AF_INET6; + if (!sortlist_alloc(sortlist, nsort, &pat)) + return ARES_ENOMEM; + } + if (ipbufpfx[0] && + (bits = ares_inet_net_pton(AF_INET, ipbufpfx, &pat.addrV4, + sizeof(pat.addrV4))) > 0) + { + pat.type = PATTERN_CIDR; + pat.mask.bits = (unsigned short)bits; + pat.family = AF_INET; + if (!sortlist_alloc(sortlist, nsort, &pat)) + return ARES_ENOMEM; + } + /* See if it is just a regular IP */ + else if (ip_addr(ipbuf, q-str, &pat.addrV4) == 0) + { + if (ipbufpfx[0]) + { + memcpy(ipbuf, str, q-str); + ipbuf[q-str] = '\0'; + if (ip_addr(ipbuf, q-str, &pat.mask.addr4) != 0) + natural_mask(&pat); + } + else + natural_mask(&pat); + pat.family = AF_INET; + pat.type = PATTERN_MASK; + if (!sortlist_alloc(sortlist, nsort, &pat)) + return ARES_ENOMEM; + } + else + { + while (*q && *q != ';' && !ISSPACE(*q)) + q++; + } + str = q; + while (ISSPACE(*str)) + str++; + } + + return ARES_SUCCESS; +} +#endif /* !WIN32 */ +#endif /* !WATT32 */ + +static int set_search(ares_channel channel, const char *str) +{ + int n; + const char *p, *q; + + if(channel->ndomains != -1) { + /* if we already have some domains present, free them first */ + for(n=0; n < channel->ndomains; n++) + free(channel->domains[n]); + free(channel->domains); + channel->domains = NULL; + channel->ndomains = -1; + } + + /* Count the domains given. */ + n = 0; + p = str; + while (*p) + { + while (*p && !ISSPACE(*p)) + p++; + while (ISSPACE(*p)) + p++; + n++; + } + + if (!n) + { + channel->ndomains = 0; + return ARES_SUCCESS; + } + + channel->domains = malloc(n * sizeof(char *)); + if (!channel->domains) + return ARES_ENOMEM; + + /* Now copy the domains. */ + n = 0; + p = str; + while (*p) + { + channel->ndomains = n; + q = p; + while (*q && !ISSPACE(*q)) + q++; + channel->domains[n] = malloc(q - p + 1); + if (!channel->domains[n]) + return ARES_ENOMEM; + memcpy(channel->domains[n], p, q - p); + channel->domains[n][q - p] = 0; + p = q; + while (ISSPACE(*p)) + p++; + n++; + } + channel->ndomains = n; + + return ARES_SUCCESS; +} + +static int set_options(ares_channel channel, const char *str) +{ + const char *p, *q, *val; + + p = str; + while (*p) + { + q = p; + while (*q && !ISSPACE(*q)) + q++; + val = try_option(p, q, "ndots:"); + if (val && channel->ndots == -1) + channel->ndots = aresx_sltosi(strtol(val, NULL, 10)); + val = try_option(p, q, "retrans:"); + if (val && channel->timeout == -1) + channel->timeout = aresx_sltosi(strtol(val, NULL, 10)); + val = try_option(p, q, "retry:"); + if (val && channel->tries == -1) + channel->tries = aresx_sltosi(strtol(val, NULL, 10)); + val = try_option(p, q, "rotate"); + if (val && channel->rotate == -1) + channel->rotate = 1; + p = q; + while (ISSPACE(*p)) + p++; + } + + return ARES_SUCCESS; +} + +static const char *try_option(const char *p, const char *q, const char *opt) +{ + size_t len = strlen(opt); + return ((size_t)(q - p) >= len && !strncmp(p, opt, len)) ? &p[len] : NULL; +} + +#if !defined(WIN32) && !defined(WATT32) +static char *try_config(char *s, const char *opt) +{ + size_t len; + char *p; + char *q; + + if (!s || !opt) + /* no line or no option */ + return NULL; + + /* trim line comment */ + p = s; + while (*p && (*p != '#')) + p++; + *p = '\0'; + + /* trim trailing whitespace */ + q = p - 1; + while ((q >= s) && ISSPACE(*q)) + q--; + *++q = '\0'; + + /* skip leading whitespace */ + p = s; + while (*p && ISSPACE(*p)) + p++; + + if (!*p) + /* empty line */ + return NULL; + + if ((len = strlen(opt)) == 0) + /* empty option */ + return NULL; + + if (strncmp(p, opt, len) != 0) + /* line and option do not match */ + return NULL; + + /* skip over given option name */ + p += len; + + if (!*p) + /* no option value */ + return NULL; + + if ((opt[len-1] != ':') && (opt[len-1] != '=') && !ISSPACE(*p)) + /* whitespace between option name and value is mandatory + for given option names which do not end with ':' or '=' */ + return NULL; + + /* skip over whitespace */ + while (*p && ISSPACE(*p)) + p++; + + if (!*p) + /* no option value */ + return NULL; + + /* return pointer to option value */ + return p; +} + +static int sortlist_alloc(struct apattern **sortlist, int *nsort, + struct apattern *pat) +{ + struct apattern *newsort; + newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern)); + if (!newsort) + return 0; + newsort[*nsort] = *pat; + *sortlist = newsort; + (*nsort)++; + return 1; +} + +static int ip_addr(const char *ipbuf, ssize_t len, struct in_addr *addr) +{ + + /* Four octets and three periods yields at most 15 characters. */ + if (len > 15) + return -1; + + addr->s_addr = inet_addr(ipbuf); + if (addr->s_addr == INADDR_NONE && strcmp(ipbuf, "255.255.255.255") != 0) + return -1; + return 0; +} + +static void natural_mask(struct apattern *pat) +{ + struct in_addr addr; + + /* Store a host-byte-order copy of pat in a struct in_addr. Icky, + * but portable. + */ + addr.s_addr = ntohl(pat->addrV4.s_addr); + + /* This is out of date in the CIDR world, but some people might + * still rely on it. + */ + if (IN_CLASSA(addr.s_addr)) + pat->mask.addr4.s_addr = htonl(IN_CLASSA_NET); + else if (IN_CLASSB(addr.s_addr)) + pat->mask.addr4.s_addr = htonl(IN_CLASSB_NET); + else + pat->mask.addr4.s_addr = htonl(IN_CLASSC_NET); +} +#endif /* !WIN32 && !WATT32 */ + +/* initialize an rc4 key. If possible a cryptographically secure random key + is generated using a suitable function (for example win32's RtlGenRandom as + described in + http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx + otherwise the code defaults to cross-platform albeit less secure mechanism + using rand +*/ +static void randomize_key(unsigned char* key,int key_data_len) +{ + int randomized = 0; + int counter=0; +#ifdef WIN32 + BOOLEAN res; + if (ares_fpSystemFunction036) + { + res = (*ares_fpSystemFunction036) (key, key_data_len); + if (res) + randomized = 1; + } +#else /* !WIN32 */ +#ifdef RANDOM_FILE + FILE *f = fopen(RANDOM_FILE, "rb"); + if(f) { + counter = aresx_uztosi(fread(key, 1, key_data_len, f)); + fclose(f); + } +#endif +#endif /* WIN32 */ + + if ( !randomized ) { + for (;counterstate[0]; + for(counter = 0; counter < 256; counter++) + /* unnecessary AND but it keeps some compilers happier */ + state[counter] = (unsigned char)(counter & 0xff); + randomize_key(key->state,key_data_len); + key->x = 0; + key->y = 0; + index1 = 0; + index2 = 0; + for(counter = 0; counter < 256; counter++) + { + index2 = (unsigned char)((key_data_ptr[index1] + state[counter] + + index2) % 256); + ARES_SWAP_BYTE(&state[counter], &state[index2]); + + index1 = (unsigned char)((index1 + 1) % key_data_len); + } + free(key_data_ptr); + return ARES_SUCCESS; +} + +unsigned short ares__generate_new_id(rc4_key* key) +{ + unsigned short r=0; + ares__rc4(key, (unsigned char *)&r, sizeof(r)); + return r; +} + +void ares_set_local_ip4(ares_channel channel, unsigned int local_ip) +{ + channel->local_ip4 = local_ip; +} + +/* local_ip6 should be 16 bytes in length */ +void ares_set_local_ip6(ares_channel channel, + const unsigned char* local_ip6) +{ + memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6)); +} + +/* local_dev_name should be null terminated. */ +void ares_set_local_dev(ares_channel channel, + const char* local_dev_name) +{ + strncpy(channel->local_dev_name, local_dev_name, + sizeof(channel->local_dev_name)); + channel->local_dev_name[sizeof(channel->local_dev_name) - 1] = 0; +} + + +void ares_set_socket_callback(ares_channel channel, + ares_sock_create_callback cb, + void *data) +{ + channel->sock_create_cb = cb; + channel->sock_create_cb_data = data; +} + +void ares__init_servers_state(ares_channel channel) +{ + struct server_state *server; + int i; + + for (i = 0; i < channel->nservers; i++) + { + server = &channel->servers[i]; + server->udp_socket = ARES_SOCKET_BAD; + server->tcp_socket = ARES_SOCKET_BAD; + server->tcp_connection_generation = ++channel->tcp_connection_generation; + server->tcp_lenbuf_pos = 0; + server->tcp_buffer_pos = 0; + server->tcp_buffer = NULL; + server->tcp_length = 0; + server->qhead = NULL; + server->qtail = NULL; + ares__init_list_head(&server->queries_to_server); + server->channel = channel; + server->is_broken = 0; + } +} diff --git a/src/rt/libuv/src/ares/ares_ipv6.h b/src/rt/libuv/src/ares/ares_ipv6.h new file mode 100644 index 00000000000..6f1022a76f5 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_ipv6.h @@ -0,0 +1,78 @@ + +/* Copyright (C) 2005 by Dominick Meglio + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#ifndef ARES_IPV6_H +#define ARES_IPV6_H + +#ifndef HAVE_PF_INET6 +#define PF_INET6 AF_INET6 +#endif + +#ifndef HAVE_STRUCT_SOCKADDR_IN6 +struct sockaddr_in6 +{ + unsigned short sin6_family; + unsigned short sin6_port; + unsigned long sin6_flowinfo; + struct ares_in6_addr sin6_addr; + unsigned int sin6_scope_id; +}; +#endif + +#ifndef HAVE_STRUCT_ADDRINFO +struct addrinfo +{ + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + ares_socklen_t ai_addrlen; /* Follow rfc3493 struct addrinfo */ + char *ai_canonname; + struct sockaddr *ai_addr; + struct addrinfo *ai_next; +}; +#endif + +#ifndef NS_IN6ADDRSZ +#if SIZEOF_STRUCT_IN6_ADDR == 0 +/* We cannot have it set to zero, so we pick a fixed value here */ +#define NS_IN6ADDRSZ 16 +#else +#define NS_IN6ADDRSZ SIZEOF_STRUCT_IN6_ADDR +#endif +#endif + +#ifndef NS_INADDRSZ +#define NS_INADDRSZ SIZEOF_STRUCT_IN_ADDR +#endif + +#ifndef NS_INT16SZ +#define NS_INT16SZ 2 +#endif + +#ifndef IF_NAMESIZE +#ifdef IFNAMSIZ +#define IF_NAMESIZE IFNAMSIZ +#else +#define IF_NAMESIZE 256 +#endif +#endif + +/* Defined in ares_net_pton.c for no particular reason. */ +extern const struct ares_in6_addr ares_in6addr_any; /* :: */ + + +#endif /* ARES_IPV6_H */ diff --git a/src/rt/libuv/src/ares/ares_library_init.c b/src/rt/libuv/src/ares/ares_library_init.c new file mode 100644 index 00000000000..1a875da1504 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_library_init.c @@ -0,0 +1,132 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2004-2009 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#include "ares.h" +#include "ares_library_init.h" +#include "ares_private.h" + +/* library-private global and unique instance vars */ + +#ifdef USE_WINSOCK +fpGetNetworkParams_t ares_fpGetNetworkParams = ZERO_NULL; +fpSystemFunction036_t ares_fpSystemFunction036 = ZERO_NULL; +#endif + +/* library-private global vars with source visibility restricted to this file */ + +static unsigned int ares_initialized; +static int ares_init_flags; + +#ifdef USE_WINSOCK +static HMODULE hnd_iphlpapi; +static HMODULE hnd_advapi32; +#endif + + +static int ares_win32_init(void) +{ +#ifdef USE_WINSOCK + + hnd_iphlpapi = 0; + hnd_iphlpapi = LoadLibrary("iphlpapi.dll"); + if (!hnd_iphlpapi) + return ARES_ELOADIPHLPAPI; + + ares_fpGetNetworkParams = (fpGetNetworkParams_t) + GetProcAddress(hnd_iphlpapi, "GetNetworkParams"); + if (!ares_fpGetNetworkParams) + { + FreeLibrary(hnd_iphlpapi); + return ARES_EADDRGETNETWORKPARAMS; + } + + /* + * When advapi32.dll is unavailable or advapi32.dll has no SystemFunction036, + * also known as RtlGenRandom, which is the case for Windows versions prior + * to WinXP then c-ares uses portable rand() function. Then don't error here. + */ + + hnd_advapi32 = 0; + hnd_advapi32 = LoadLibrary("advapi32.dll"); + if (hnd_advapi32) + { + ares_fpSystemFunction036 = (fpSystemFunction036_t) + GetProcAddress(hnd_advapi32, "SystemFunction036"); + } + +#endif + return ARES_SUCCESS; +} + + +static void ares_win32_cleanup(void) +{ +#ifdef USE_WINSOCK + if (hnd_advapi32) + FreeLibrary(hnd_advapi32); + if (hnd_iphlpapi) + FreeLibrary(hnd_iphlpapi); +#endif +} + + +int ares_library_init(int flags) +{ + int res; + + if (ares_initialized) + return ARES_SUCCESS; + ares_initialized++; + + if (flags & ARES_LIB_INIT_WIN32) + { + res = ares_win32_init(); + if (res != ARES_SUCCESS) + return res; + } + + ares_init_flags = flags; + + return ARES_SUCCESS; +} + + +void ares_library_cleanup(void) +{ + if (!ares_initialized) + return; + ares_initialized--; + + if (ares_init_flags & ARES_LIB_INIT_WIN32) + ares_win32_cleanup(); + + ares_init_flags = ARES_LIB_INIT_NONE; +} + + +int ares_library_initialized(void) +{ +#ifdef USE_WINSOCK + if (!ares_initialized) + return ARES_ENOTINITIALIZED; +#endif + return ARES_SUCCESS; +} + + diff --git a/src/rt/libuv/src/ares/ares_library_init.h b/src/rt/libuv/src/ares/ares_library_init.h new file mode 100644 index 00000000000..29d5c9e73ff --- /dev/null +++ b/src/rt/libuv/src/ares/ares_library_init.h @@ -0,0 +1,39 @@ +#ifndef HEADER_CARES_LIBRARY_INIT_H +#define HEADER_CARES_LIBRARY_INIT_H + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2004-2009 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef USE_WINSOCK + +#include + +typedef DWORD (WINAPI *fpGetNetworkParams_t) (FIXED_INFO*, DWORD*); +typedef BOOLEAN (APIENTRY *fpSystemFunction036_t) (void*, ULONG); + +/* Forward-declaration of variables defined in ares_library_init.c */ +/* that are global and unique instances for whole c-ares library. */ + +extern fpGetNetworkParams_t ares_fpGetNetworkParams; +extern fpSystemFunction036_t ares_fpSystemFunction036; + +#endif /* USE_WINSOCK */ + +#endif /* HEADER_CARES_LIBRARY_INIT_H */ + diff --git a/src/rt/libuv/src/ares/ares_llist.c b/src/rt/libuv/src/ares/ares_llist.c new file mode 100644 index 00000000000..c0acd90a8e8 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_llist.c @@ -0,0 +1,86 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#include "ares.h" +#include "ares_private.h" + +/* Routines for managing doubly-linked circular linked lists with a + * dummy head. + */ + +/* Initialize a new head node */ +void ares__init_list_head(struct list_node* head) { + head->prev = head; + head->next = head; + head->data = NULL; +} + +/* Initialize a list node */ +void ares__init_list_node(struct list_node* node, void* d) { + node->prev = NULL; + node->next = NULL; + node->data = d; +} + +/* Returns true iff the given list is empty */ +int ares__is_list_empty(struct list_node* head) { + return ((head->next == head) && (head->prev == head)); +} + +/* Inserts new_node before old_node */ +void ares__insert_in_list(struct list_node* new_node, + struct list_node* old_node) { + new_node->next = old_node; + new_node->prev = old_node->prev; + old_node->prev->next = new_node; + old_node->prev = new_node; +} + +/* Removes the node from the list it's in, if any */ +void ares__remove_from_list(struct list_node* node) { + if (node->next != NULL) { + node->prev->next = node->next; + node->next->prev = node->prev; + node->prev = NULL; + node->next = NULL; + } +} + +/* Swap the contents of two lists */ +void ares__swap_lists(struct list_node* head_a, + struct list_node* head_b) { + int is_a_empty = ares__is_list_empty(head_a); + int is_b_empty = ares__is_list_empty(head_b); + struct list_node old_a = *head_a; + struct list_node old_b = *head_b; + + if (is_a_empty) { + ares__init_list_head(head_b); + } else { + *head_b = old_a; + old_a.next->prev = head_b; + old_a.prev->next = head_b; + } + if (is_b_empty) { + ares__init_list_head(head_a); + } else { + *head_a = old_b; + old_b.next->prev = head_a; + old_b.prev->next = head_a; + } +} diff --git a/src/rt/libuv/src/ares/ares_llist.h b/src/rt/libuv/src/ares/ares_llist.h new file mode 100644 index 00000000000..b09f0de6d71 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_llist.h @@ -0,0 +1,42 @@ +#ifndef __ARES_LLIST_H +#define __ARES_LLIST_H + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + + +/* Node definition for circular, doubly-linked list */ +struct list_node { + struct list_node *prev; + struct list_node *next; + void* data; +}; + +void ares__init_list_head(struct list_node* head); + +void ares__init_list_node(struct list_node* node, void* d); + +int ares__is_list_empty(struct list_node* head); + +void ares__insert_in_list(struct list_node* new_node, + struct list_node* old_node); + +void ares__remove_from_list(struct list_node* node); + +void ares__swap_lists(struct list_node* head_a, + struct list_node* head_b); + +#endif /* __ARES_LLIST_H */ diff --git a/src/rt/libuv/src/ares/ares_mkquery.c b/src/rt/libuv/src/ares/ares_mkquery.c new file mode 100644 index 00000000000..e33f13ff223 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_mkquery.c @@ -0,0 +1,195 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include "ares.h" +#include "ares_dns.h" +#include "ares_private.h" + +/* Header format, from RFC 1035: + * 1 1 1 1 1 1 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | ID | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * |QR| Opcode |AA|TC|RD|RA| Z | RCODE | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | QDCOUNT | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | ANCOUNT | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | NSCOUNT | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | ARCOUNT | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * + * AA, TC, RA, and RCODE are only set in responses. Brief description + * of the remaining fields: + * ID Identifier to match responses with queries + * QR Query (0) or response (1) + * Opcode For our purposes, always QUERY + * RD Recursion desired + * Z Reserved (zero) + * QDCOUNT Number of queries + * ANCOUNT Number of answers + * NSCOUNT Number of name server records + * ARCOUNT Number of additional records + * + * Question format, from RFC 1035: + * 1 1 1 1 1 1 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | | + * / QNAME / + * / / + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | QTYPE | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | QCLASS | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * + * The query name is encoded as a series of labels, each represented + * as a one-byte length (maximum 63) followed by the text of the + * label. The list is terminated by a label of length zero (which can + * be thought of as the root domain). + */ + +int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id, + int rd, unsigned char **buf, int *buflen) +{ + int len; + unsigned char *q; + const char *p; + + /* Set our results early, in case we bail out early with an error. */ + *buflen = 0; + *buf = NULL; + + /* Compute the length of the encoded name so we can check buflen. + * Start counting at 1 for the zero-length label at the end. */ + len = 1; + for (p = name; *p; p++) + { + if (*p == '\\' && *(p + 1) != 0) + p++; + len++; + } + /* If there are n periods in the name, there are n + 1 labels, and + * thus n + 1 length fields, unless the name is empty or ends with a + * period. So add 1 unless name is empty or ends with a period. + */ + if (*name && *(p - 1) != '.') + len++; + + /* Immediately reject names that are longer than the maximum of 255 + * bytes that's specified in RFC 1035 ("To simplify implementations, + * the total length of a domain name (i.e., label octets and label + * length octets) is restricted to 255 octets or less."). We aren't + * doing this just to be a stickler about RFCs. For names that are + * too long, 'dnscache' closes its TCP connection to us immediately + * (when using TCP) and ignores the request when using UDP, and + * BIND's named returns ServFail (TCP or UDP). Sending a request + * that we know will cause 'dnscache' to close the TCP connection is + * painful, since that makes any other outstanding requests on that + * connection fail. And sending a UDP request that we know + * 'dnscache' will ignore is bad because resources will be tied up + * until we time-out the request. + */ + if (len > MAXCDNAME) + return ARES_EBADNAME; + + *buflen = len + HFIXEDSZ + QFIXEDSZ; + *buf = malloc(*buflen); + if (!*buf) + return ARES_ENOMEM; + + /* Set up the header. */ + q = *buf; + memset(q, 0, HFIXEDSZ); + DNS_HEADER_SET_QID(q, id); + DNS_HEADER_SET_OPCODE(q, QUERY); + if (rd) { + DNS_HEADER_SET_RD(q, 1); + } + else { + DNS_HEADER_SET_RD(q, 0); + } + DNS_HEADER_SET_QDCOUNT(q, 1); + + /* A name of "." is a screw case for the loop below, so adjust it. */ + if (strcmp(name, ".") == 0) + name++; + + /* Start writing out the name after the header. */ + q += HFIXEDSZ; + while (*name) + { + if (*name == '.') + return ARES_EBADNAME; + + /* Count the number of bytes in this label. */ + len = 0; + for (p = name; *p && *p != '.'; p++) + { + if (*p == '\\' && *(p + 1) != 0) + p++; + len++; + } + if (len > MAXLABEL) + return ARES_EBADNAME; + + /* Encode the length and copy the data. */ + *q++ = (unsigned char)len; + for (p = name; *p && *p != '.'; p++) + { + if (*p == '\\' && *(p + 1) != 0) + p++; + *q++ = *p; + } + + /* Go to the next label and repeat, unless we hit the end. */ + if (!*p) + break; + name = p + 1; + } + + /* Add the zero-length label at the end. */ + *q++ = 0; + + /* Finish off the question with the type and class. */ + DNS_QUESTION_SET_TYPE(q, type); + DNS_QUESTION_SET_CLASS(q, dnsclass); + + return ARES_SUCCESS; +} diff --git a/src/rt/libuv/src/ares/ares_nowarn.c b/src/rt/libuv/src/ares/ares_nowarn.c new file mode 100644 index 00000000000..52d079e6409 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_nowarn.c @@ -0,0 +1,59 @@ + +/* Copyright (C) 2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + + +#include "ares_setup.h" + +#include "ares_nowarn.h" + +#define CARES_MASK_UINT (~(unsigned int) 0) +#define CARES_MASK_SINT (CARES_MASK_UINT >> 1) + +/* +** size_t to signed int +*/ + +int aresx_uztosi(size_t uznum) +{ +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:810) /* conversion may lose significant bits */ +#endif + + return (int)(uznum & (size_t) CARES_MASK_SINT); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif +} + +/* +** signed long to signed int +*/ + +int aresx_sltosi(long slnum) +{ +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:810) /* conversion may lose significant bits */ +#endif + + return (int)(slnum & (long) CARES_MASK_SINT); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif +} diff --git a/src/rt/libuv/src/ares/ares_nowarn.h b/src/rt/libuv/src/ares/ares_nowarn.h new file mode 100644 index 00000000000..fb804951065 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_nowarn.h @@ -0,0 +1,24 @@ +#ifndef HEADER_CARES_NOWARN_H +#define HEADER_CARES_NOWARN_H + + +/* Copyright (C) 2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +int aresx_uztosi(size_t uznum); + +int aresx_sltosi(long slnum); + +#endif /* HEADER_CARES_NOWARN_H */ diff --git a/src/rt/libuv/src/ares/ares_options.c b/src/rt/libuv/src/ares/ares_options.c new file mode 100644 index 00000000000..70280526869 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_options.c @@ -0,0 +1,253 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2008-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + + +#include "ares_setup.h" + +#ifdef HAVE_ARPA_INET_H +# include +#endif + +#include "ares.h" +#include "ares_data.h" +#include "inet_net_pton.h" +#include "ares_private.h" + + +int ares_get_servers(ares_channel channel, + struct ares_addr_node **servers) +{ + struct ares_addr_node *srvr_head = NULL; + struct ares_addr_node *srvr_last = NULL; + struct ares_addr_node *srvr_curr; + int status = ARES_SUCCESS; + int i; + + if (!channel) + return ARES_ENODATA; + + for (i = 0; i < channel->nservers; i++) + { + /* Allocate storage for this server node appending it to the list */ + srvr_curr = ares_malloc_data(ARES_DATATYPE_ADDR_NODE); + if (!srvr_curr) + { + status = ARES_ENOMEM; + break; + } + if (srvr_last) + { + srvr_last->next = srvr_curr; + } + else + { + srvr_head = srvr_curr; + } + srvr_last = srvr_curr; + + /* Fill this server node data */ + srvr_curr->family = channel->servers[i].addr.family; + if (srvr_curr->family == AF_INET) + memcpy(&srvr_curr->addrV4, &channel->servers[i].addr.addrV4, + sizeof(srvr_curr->addrV4)); + else + memcpy(&srvr_curr->addrV6, &channel->servers[i].addr.addrV6, + sizeof(srvr_curr->addrV6)); + } + + if (status != ARES_SUCCESS) + { + if (srvr_head) + { + ares_free_data(srvr_head); + srvr_head = NULL; + } + } + + *servers = srvr_head; + + return status; +} + + +int ares_set_servers(ares_channel channel, + struct ares_addr_node *servers) +{ + struct ares_addr_node *srvr; + int num_srvrs = 0; + int i; + + if (ares_library_initialized() != ARES_SUCCESS) + return ARES_ENOTINITIALIZED; + + if (!channel) + return ARES_ENODATA; + + ares__destroy_servers_state(channel); + + for (srvr = servers; srvr; srvr = srvr->next) + { + num_srvrs++; + } + + if (num_srvrs > 0) + { + /* Allocate storage for servers state */ + channel->servers = malloc(num_srvrs * sizeof(struct server_state)); + if (!channel->servers) + { + return ARES_ENOMEM; + } + channel->nservers = num_srvrs; + /* Fill servers state address data */ + for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next) + { + channel->servers[i].addr.family = srvr->family; + if (srvr->family == AF_INET) + memcpy(&channel->servers[i].addr.addrV4, &srvr->addrV4, + sizeof(srvr->addrV4)); + else + memcpy(&channel->servers[i].addr.addrV6, &srvr->addrV6, + sizeof(srvr->addrV6)); + } + /* Initialize servers state remaining data */ + ares__init_servers_state(channel); + } + + return ARES_SUCCESS; +} + +/* Incomming string format: host[:port][,host[:port]]... */ +int ares_set_servers_csv(ares_channel channel, + const char* _csv) +{ + int i; + char* csv = NULL; + char* ptr; + char* start_host; + long port; + bool found_port; + int rv = ARES_SUCCESS; + struct ares_addr_node *servers = NULL; + struct ares_addr_node *last = NULL; + + if (ares_library_initialized() != ARES_SUCCESS) + return ARES_ENOTINITIALIZED; + + if (!channel) + return ARES_ENODATA; + + ares__destroy_servers_state(channel); + + i = strlen(_csv); + if (i == 0) + return ARES_SUCCESS; /* blank all servers */ + + csv = malloc(i + 2); + strcpy(csv, _csv); + if (csv[i-1] != ',') { /* make parsing easier by ensuring ending ',' */ + csv[i] = ','; + csv[i+1] = 0; + } + + start_host = csv; + found_port = false; + for (ptr = csv; *ptr; ptr++) { + if (*ptr == ',') { + char* pp = ptr - 1; + struct in_addr in4; + struct ares_in6_addr in6; + struct ares_addr_node *s = NULL; + + *ptr = 0; /* null terminate host:port string */ + /* Got an entry..see if port was specified. */ + while (pp > start_host) { + if (*pp == ':') + break; /* yes */ + if (!ISDIGIT(*pp)) { + /* Found end of digits before we found :, so wasn't a port */ + pp = ptr; + break; + } + pp--; + } + if ((pp != start_host) && ((pp + 1) < ptr)) { + /* Found it. */ + found_port = true; + port = strtol(pp + 1, NULL, 10); + *pp = 0; /* null terminate host */ + } + /* resolve host, try ipv4 first, rslt is in network byte order */ + rv = ares_inet_pton(AF_INET, start_host, &in4); + if (!rv) { + /* Ok, try IPv6 then */ + rv = ares_inet_pton(AF_INET6, start_host, &in6); + if (!rv) { + rv = ARES_EBADSTR; + goto out; + } + /* was ipv6, add new server */ + s = malloc(sizeof(*s)); + if (!s) { + rv = ARES_ENOMEM; + goto out; + } + s->family = AF_INET6; + memcpy(&s->addr, &in6, sizeof(struct ares_in6_addr)); + } + else { + /* was ipv4, add new server */ + s = malloc(sizeof(*s)); + if (!s) { + rv = ARES_ENOMEM; + goto out; + } + s->family = AF_INET; + memcpy(&s->addr, &in4, sizeof(struct in_addr)); + } + if (s) { + /* TODO: Add port to ares_addr_node and assign it here. */ + + s->next = NULL; + if (last) { + last->next = s; + } + else { + servers = s; + last = s; + } + } + + /* Set up for next one */ + found_port = false; + start_host = ptr + 1; + } + } + + rv = ares_set_servers(channel, servers); + + out: + if (csv) + free(csv); + while (servers) { + struct ares_addr_node *s = servers; + servers = servers->next; + free(s); + } + + return rv; +} diff --git a/src/rt/libuv/src/ares/ares_parse_a_reply.c b/src/rt/libuv/src/ares/ares_parse_a_reply.c new file mode 100644 index 00000000000..93012549c90 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_parse_a_reply.c @@ -0,0 +1,258 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#ifdef HAVE_STRINGS_H +# include +#endif + +#include +#include +#ifdef HAVE_LIMITS_H +# include +#endif + +#include "ares.h" +#include "ares_dns.h" +#include "ares_private.h" + +int ares_parse_a_reply(const unsigned char *abuf, int alen, + struct hostent **host, + struct ares_addrttl *addrttls, int *naddrttls) +{ + unsigned int qdcount, ancount; + int status, i, rr_type, rr_class, rr_len, rr_ttl, naddrs; + int cname_ttl = INT_MAX; /* the TTL imposed by the CNAME chain */ + int naliases; + long len; + const unsigned char *aptr; + char *hostname, *rr_name, *rr_data, **aliases; + struct in_addr *addrs; + struct hostent *hostent; + const int max_addr_ttls = (addrttls && naddrttls) ? *naddrttls : 0; + + /* Set *host to NULL for all failure cases. */ + if (host) + *host = NULL; + /* Same with *naddrttls. */ + if (naddrttls) + *naddrttls = 0; + + /* Give up if abuf doesn't have room for a header. */ + if (alen < HFIXEDSZ) + return ARES_EBADRESP; + + /* Fetch the question and answer count from the header. */ + qdcount = DNS_HEADER_QDCOUNT(abuf); + ancount = DNS_HEADER_ANCOUNT(abuf); + if (qdcount != 1) + return ARES_EBADRESP; + + /* Expand the name from the question, and skip past the question. */ + aptr = abuf + HFIXEDSZ; + status = ares__expand_name_for_response(aptr, abuf, alen, &hostname, &len); + if (status != ARES_SUCCESS) + return status; + if (aptr + len + QFIXEDSZ > abuf + alen) + { + free(hostname); + return ARES_EBADRESP; + } + aptr += len + QFIXEDSZ; + + if (host) + { + /* Allocate addresses and aliases; ancount gives an upper bound for + both. */ + addrs = malloc(ancount * sizeof(struct in_addr)); + if (!addrs) + { + free(hostname); + return ARES_ENOMEM; + } + aliases = malloc((ancount + 1) * sizeof(char *)); + if (!aliases) + { + free(hostname); + free(addrs); + return ARES_ENOMEM; + } + } + else + { + addrs = NULL; + aliases = NULL; + } + + naddrs = 0; + naliases = 0; + + /* Examine each answer resource record (RR) in turn. */ + for (i = 0; i < (int)ancount; i++) + { + /* Decode the RR up to the data field. */ + status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len); + if (status != ARES_SUCCESS) + break; + aptr += len; + if (aptr + RRFIXEDSZ > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + rr_type = DNS_RR_TYPE(aptr); + rr_class = DNS_RR_CLASS(aptr); + rr_len = DNS_RR_LEN(aptr); + rr_ttl = DNS_RR_TTL(aptr); + aptr += RRFIXEDSZ; + + if (rr_class == C_IN && rr_type == T_A + && rr_len == sizeof(struct in_addr) + && strcasecmp(rr_name, hostname) == 0) + { + if (addrs) + { + if (aptr + sizeof(struct in_addr) > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + memcpy(&addrs[naddrs], aptr, sizeof(struct in_addr)); + } + if (naddrs < max_addr_ttls) + { + struct ares_addrttl * const at = &addrttls[naddrs]; + if (aptr + sizeof(struct in_addr) > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + memcpy(&at->ipaddr, aptr, sizeof(struct in_addr)); + at->ttl = rr_ttl; + } + naddrs++; + status = ARES_SUCCESS; + } + + if (rr_class == C_IN && rr_type == T_CNAME) + { + /* Record the RR name as an alias. */ + if (aliases) + aliases[naliases] = rr_name; + else + free(rr_name); + naliases++; + + /* Decode the RR data and replace the hostname with it. */ + status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data, + &len); + if (status != ARES_SUCCESS) + break; + free(hostname); + hostname = rr_data; + + /* Take the min of the TTLs we see in the CNAME chain. */ + if (cname_ttl > rr_ttl) + cname_ttl = rr_ttl; + } + else + free(rr_name); + + aptr += rr_len; + if (aptr > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + } + + if (status == ARES_SUCCESS && naddrs == 0 && naliases == 0) + /* the check for naliases to be zero is to make sure CNAME responses + don't get caught here */ + status = ARES_ENODATA; + if (status == ARES_SUCCESS) + { + /* We got our answer. */ + if (naddrttls) + { + const int n = naddrs < max_addr_ttls ? naddrs : max_addr_ttls; + for (i = 0; i < n; i++) + { + /* Ensure that each A TTL is no larger than the CNAME TTL. */ + if (addrttls[i].ttl > cname_ttl) + addrttls[i].ttl = cname_ttl; + } + *naddrttls = n; + } + if (aliases) + aliases[naliases] = NULL; + if (host) + { + /* Allocate memory to build the host entry. */ + hostent = malloc(sizeof(struct hostent)); + if (hostent) + { + hostent->h_addr_list = malloc((naddrs + 1) * sizeof(char *)); + if (hostent->h_addr_list) + { + /* Fill in the hostent and return successfully. */ + hostent->h_name = hostname; + hostent->h_aliases = aliases; + hostent->h_addrtype = AF_INET; + hostent->h_length = sizeof(struct in_addr); + for (i = 0; i < naddrs; i++) + hostent->h_addr_list[i] = (char *) &addrs[i]; + hostent->h_addr_list[naddrs] = NULL; + *host = hostent; + return ARES_SUCCESS; + } + free(hostent); + } + status = ARES_ENOMEM; + } + } + if (aliases) + { + for (i = 0; i < naliases; i++) + free(aliases[i]); + free(aliases); + } + free(addrs); + free(hostname); + return status; +} diff --git a/src/rt/libuv/src/ares/ares_parse_aaaa_reply.c b/src/rt/libuv/src/ares/ares_parse_aaaa_reply.c new file mode 100644 index 00000000000..a0f524daa5f --- /dev/null +++ b/src/rt/libuv/src/ares/ares_parse_aaaa_reply.c @@ -0,0 +1,256 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright 2005 Dominick Meglio + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#ifdef HAVE_STRINGS_H +# include +#endif + +#include +#include +#ifdef HAVE_LIMITS_H +# include +#endif + +#include "ares.h" +#include "ares_dns.h" +#include "inet_net_pton.h" +#include "ares_private.h" + +int ares_parse_aaaa_reply(const unsigned char *abuf, int alen, + struct hostent **host, struct ares_addr6ttl *addrttls, + int *naddrttls) +{ + unsigned int qdcount, ancount; + int status, i, rr_type, rr_class, rr_len, rr_ttl, naddrs; + int cname_ttl = INT_MAX; /* the TTL imposed by the CNAME chain */ + int naliases; + long len; + const unsigned char *aptr; + char *hostname, *rr_name, *rr_data, **aliases; + struct ares_in6_addr *addrs; + struct hostent *hostent; + const int max_addr_ttls = (addrttls && naddrttls) ? *naddrttls : 0; + + /* Set *host to NULL for all failure cases. */ + if (host) + *host = NULL; + /* Same with *naddrttls. */ + if (naddrttls) + *naddrttls = 0; + + /* Give up if abuf doesn't have room for a header. */ + if (alen < HFIXEDSZ) + return ARES_EBADRESP; + + /* Fetch the question and answer count from the header. */ + qdcount = DNS_HEADER_QDCOUNT(abuf); + ancount = DNS_HEADER_ANCOUNT(abuf); + if (qdcount != 1) + return ARES_EBADRESP; + + /* Expand the name from the question, and skip past the question. */ + aptr = abuf + HFIXEDSZ; + status = ares__expand_name_for_response(aptr, abuf, alen, &hostname, &len); + if (status != ARES_SUCCESS) + return status; + if (aptr + len + QFIXEDSZ > abuf + alen) + { + free(hostname); + return ARES_EBADRESP; + } + aptr += len + QFIXEDSZ; + + /* Allocate addresses and aliases; ancount gives an upper bound for both. */ + if (host) + { + addrs = malloc(ancount * sizeof(struct ares_in6_addr)); + if (!addrs) + { + free(hostname); + return ARES_ENOMEM; + } + aliases = malloc((ancount + 1) * sizeof(char *)); + if (!aliases) + { + free(hostname); + free(addrs); + return ARES_ENOMEM; + } + } + else + { + addrs = NULL; + aliases = NULL; + } + naddrs = 0; + naliases = 0; + + /* Examine each answer resource record (RR) in turn. */ + for (i = 0; i < (int)ancount; i++) + { + /* Decode the RR up to the data field. */ + status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len); + if (status != ARES_SUCCESS) + break; + aptr += len; + if (aptr + RRFIXEDSZ > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + rr_type = DNS_RR_TYPE(aptr); + rr_class = DNS_RR_CLASS(aptr); + rr_len = DNS_RR_LEN(aptr); + rr_ttl = DNS_RR_TTL(aptr); + aptr += RRFIXEDSZ; + + if (rr_class == C_IN && rr_type == T_AAAA + && rr_len == sizeof(struct ares_in6_addr) + && strcasecmp(rr_name, hostname) == 0) + { + if (addrs) + { + if (aptr + sizeof(struct ares_in6_addr) > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + memcpy(&addrs[naddrs], aptr, sizeof(struct ares_in6_addr)); + } + if (naddrs < max_addr_ttls) + { + struct ares_addr6ttl * const at = &addrttls[naddrs]; + if (aptr + sizeof(struct ares_in6_addr) > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + memcpy(&at->ip6addr, aptr, sizeof(struct ares_in6_addr)); + at->ttl = rr_ttl; + } + naddrs++; + status = ARES_SUCCESS; + } + + if (rr_class == C_IN && rr_type == T_CNAME) + { + /* Record the RR name as an alias. */ + if (aliases) + aliases[naliases] = rr_name; + else + free(rr_name); + naliases++; + + /* Decode the RR data and replace the hostname with it. */ + status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data, + &len); + if (status != ARES_SUCCESS) + break; + free(hostname); + hostname = rr_data; + + /* Take the min of the TTLs we see in the CNAME chain. */ + if (cname_ttl > rr_ttl) + cname_ttl = rr_ttl; + } + else + free(rr_name); + + aptr += rr_len; + if (aptr > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + } + + if (status == ARES_SUCCESS && naddrs == 0) + status = ARES_ENODATA; + if (status == ARES_SUCCESS) + { + /* We got our answer. */ + if (naddrttls) + { + const int n = naddrs < max_addr_ttls ? naddrs : max_addr_ttls; + for (i = 0; i < n; i++) + { + /* Ensure that each A TTL is no larger than the CNAME TTL. */ + if (addrttls[i].ttl > cname_ttl) + addrttls[i].ttl = cname_ttl; + } + *naddrttls = n; + } + if (aliases) + aliases[naliases] = NULL; + if (host) + { + /* Allocate memory to build the host entry. */ + hostent = malloc(sizeof(struct hostent)); + if (hostent) + { + hostent->h_addr_list = malloc((naddrs + 1) * sizeof(char *)); + if (hostent->h_addr_list) + { + /* Fill in the hostent and return successfully. */ + hostent->h_name = hostname; + hostent->h_aliases = aliases; + hostent->h_addrtype = AF_INET6; + hostent->h_length = sizeof(struct ares_in6_addr); + for (i = 0; i < naddrs; i++) + hostent->h_addr_list[i] = (char *) &addrs[i]; + hostent->h_addr_list[naddrs] = NULL; + *host = hostent; + return ARES_SUCCESS; + } + free(hostent); + } + status = ARES_ENOMEM; + } + } + if (aliases) + { + for (i = 0; i < naliases; i++) + free(aliases[i]); + free(aliases); + } + free(addrs); + free(hostname); + return status; +} diff --git a/src/rt/libuv/src/ares/ares_parse_mx_reply.c b/src/rt/libuv/src/ares/ares_parse_mx_reply.c new file mode 100644 index 00000000000..186ddd348d7 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_parse_mx_reply.c @@ -0,0 +1,170 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2010 Jeremy Lal + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include "ares.h" +#include "ares_dns.h" +#include "ares_data.h" +#include "ares_private.h" + +int +ares_parse_mx_reply (const unsigned char *abuf, int alen, + struct ares_mx_reply **mx_out) +{ + unsigned int qdcount, ancount, i; + const unsigned char *aptr, *vptr; + int status, rr_type, rr_class, rr_len; + long len; + char *hostname = NULL, *rr_name = NULL; + struct ares_mx_reply *mx_head = NULL; + struct ares_mx_reply *mx_last = NULL; + struct ares_mx_reply *mx_curr; + + /* Set *mx_out to NULL for all failure cases. */ + *mx_out = NULL; + + /* Give up if abuf doesn't have room for a header. */ + if (alen < HFIXEDSZ) + return ARES_EBADRESP; + + /* Fetch the question and answer count from the header. */ + qdcount = DNS_HEADER_QDCOUNT (abuf); + ancount = DNS_HEADER_ANCOUNT (abuf); + if (qdcount != 1) + return ARES_EBADRESP; + if (ancount == 0) + return ARES_ENODATA; + + /* Expand the name from the question, and skip past the question. */ + aptr = abuf + HFIXEDSZ; + status = ares_expand_name (aptr, abuf, alen, &hostname, &len); + if (status != ARES_SUCCESS) + return status; + + if (aptr + len + QFIXEDSZ > abuf + alen) + { + free (hostname); + return ARES_EBADRESP; + } + aptr += len + QFIXEDSZ; + + /* Examine each answer resource record (RR) in turn. */ + for (i = 0; i < ancount; i++) + { + /* Decode the RR up to the data field. */ + status = ares_expand_name (aptr, abuf, alen, &rr_name, &len); + if (status != ARES_SUCCESS) + { + break; + } + aptr += len; + if (aptr + RRFIXEDSZ > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + rr_type = DNS_RR_TYPE (aptr); + rr_class = DNS_RR_CLASS (aptr); + rr_len = DNS_RR_LEN (aptr); + aptr += RRFIXEDSZ; + + /* Check if we are really looking at a MX record */ + if (rr_class == C_IN && rr_type == T_MX) + { + /* parse the MX record itself */ + if (rr_len < 2) + { + status = ARES_EBADRESP; + break; + } + + /* Allocate storage for this MX answer appending it to the list */ + mx_curr = ares_malloc_data(ARES_DATATYPE_MX_REPLY); + if (!mx_curr) + { + status = ARES_ENOMEM; + break; + } + if (mx_last) + { + mx_last->next = mx_curr; + } + else + { + mx_head = mx_curr; + } + mx_last = mx_curr; + + vptr = aptr; + mx_curr->priority = ntohs (*((unsigned short *)vptr)); + vptr += sizeof(unsigned short); + + status = ares_expand_name (vptr, abuf, alen, &mx_curr->host, &len); + if (status != ARES_SUCCESS) + break; + } + + /* Don't lose memory in the next iteration */ + free (rr_name); + rr_name = NULL; + + /* Move on to the next record */ + aptr += rr_len; + } + + if (hostname) + free (hostname); + if (rr_name) + free (rr_name); + + /* clean up on error */ + if (status != ARES_SUCCESS) + { + if (mx_head) + ares_free_data (mx_head); + return status; + } + + /* everything looks fine, return the data */ + *mx_out = mx_head; + + return ARES_SUCCESS; +} diff --git a/src/rt/libuv/src/ares/ares_parse_ns_reply.c b/src/rt/libuv/src/ares/ares_parse_ns_reply.c new file mode 100644 index 00000000000..25c632994a5 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_parse_ns_reply.c @@ -0,0 +1,182 @@ +/* $Id */ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +/* + * ares_parse_ns_reply created by Vlad Dinulescu + * on behalf of AVIRA Gmbh - http://www.avira.com + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include "ares.h" +#include "ares_dns.h" +#include "ares_private.h" + +int ares_parse_ns_reply( const unsigned char* abuf, int alen, + struct hostent** host ) +{ + unsigned int qdcount, ancount; + int status, i, rr_type, rr_class, rr_len; + int nameservers_num; + long len; + const unsigned char *aptr; + char* hostname, *rr_name, *rr_data, **nameservers; + struct hostent *hostent; + + /* Set *host to NULL for all failure cases. */ + *host = NULL; + + /* Give up if abuf doesn't have room for a header. */ + if ( alen < HFIXEDSZ ) + return ARES_EBADRESP; + + /* Fetch the question and answer count from the header. */ + qdcount = DNS_HEADER_QDCOUNT( abuf ); + ancount = DNS_HEADER_ANCOUNT( abuf ); + if ( qdcount != 1 ) + return ARES_EBADRESP; + + /* Expand the name from the question, and skip past the question. */ + aptr = abuf + HFIXEDSZ; + status = ares__expand_name_for_response( aptr, abuf, alen, &hostname, &len); + if ( status != ARES_SUCCESS ) + return status; + if ( aptr + len + QFIXEDSZ > abuf + alen ) + { + free( hostname ); + return ARES_EBADRESP; + } + aptr += len + QFIXEDSZ; + + /* Allocate nameservers array; ancount gives an upper bound */ + nameservers = malloc( ( ancount + 1 ) * sizeof( char * ) ); + if ( !nameservers ) + { + free( hostname ); + return ARES_ENOMEM; + } + nameservers_num = 0; + + /* Examine each answer resource record (RR) in turn. */ + for ( i = 0; i < ( int ) ancount; i++ ) + { + /* Decode the RR up to the data field. */ + status = ares__expand_name_for_response( aptr, abuf, alen, &rr_name, &len ); + if ( status != ARES_SUCCESS ) + break; + aptr += len; + if ( aptr + RRFIXEDSZ > abuf + alen ) + { + status = ARES_EBADRESP; + break; + } + rr_type = DNS_RR_TYPE( aptr ); + rr_class = DNS_RR_CLASS( aptr ); + rr_len = DNS_RR_LEN( aptr ); + aptr += RRFIXEDSZ; + + if ( rr_class == C_IN && rr_type == T_NS ) + { + /* Decode the RR data and add it to the nameservers list */ + status = ares__expand_name_for_response( aptr, abuf, alen, &rr_data, + &len); + if ( status != ARES_SUCCESS ) + { + break; + } + + nameservers[nameservers_num] = malloc(strlen(rr_data)+1); + + if (nameservers[nameservers_num]==NULL) + { + free(rr_name); + free(rr_data); + status=ARES_ENOMEM; + break; + } + strcpy(nameservers[nameservers_num],rr_data); + free(rr_data); + + nameservers_num++; + } + + free( rr_name ); + + aptr += rr_len; + if ( aptr > abuf + alen ) + { + status = ARES_EBADRESP; + break; + } + } + + if ( status == ARES_SUCCESS && nameservers_num == 0 ) + { + status = ARES_ENODATA; + } + if ( status == ARES_SUCCESS ) + { + /* We got our answer. Allocate memory to build the host entry. */ + nameservers[nameservers_num] = NULL; + hostent = malloc( sizeof( struct hostent ) ); + if ( hostent ) + { + hostent->h_addr_list = malloc( 1 * sizeof( char * ) ); + if ( hostent->h_addr_list ) + { + /* Fill in the hostent and return successfully. */ + hostent->h_name = hostname; + hostent->h_aliases = nameservers; + hostent->h_addrtype = AF_INET; + hostent->h_length = sizeof( struct in_addr ); + hostent->h_addr_list[0] = NULL; + *host = hostent; + return ARES_SUCCESS; + } + free( hostent ); + } + status = ARES_ENOMEM; + } + for ( i = 0; i < nameservers_num; i++ ) + free( nameservers[i] ); + free( nameservers ); + free( hostname ); + return status; +} diff --git a/src/rt/libuv/src/ares/ares_parse_ptr_reply.c b/src/rt/libuv/src/ares/ares_parse_ptr_reply.c new file mode 100644 index 00000000000..ccd68a26da1 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_parse_ptr_reply.c @@ -0,0 +1,208 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#ifdef HAVE_STRINGS_H +# include +#endif + +#include +#include +#include "ares.h" +#include "ares_dns.h" +#include "ares_private.h" + +int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr, + int addrlen, int family, struct hostent **host) +{ + unsigned int qdcount, ancount; + int status, i, rr_type, rr_class, rr_len; + long len; + const unsigned char *aptr; + char *ptrname, *hostname, *rr_name, *rr_data; + struct hostent *hostent; + int aliascnt = 0; + int alias_alloc = 8; + char ** aliases; + + /* Set *host to NULL for all failure cases. */ + *host = NULL; + + /* Give up if abuf doesn't have room for a header. */ + if (alen < HFIXEDSZ) + return ARES_EBADRESP; + + /* Fetch the question and answer count from the header. */ + qdcount = DNS_HEADER_QDCOUNT(abuf); + ancount = DNS_HEADER_ANCOUNT(abuf); + if (qdcount != 1) + return ARES_EBADRESP; + + /* Expand the name from the question, and skip past the question. */ + aptr = abuf + HFIXEDSZ; + status = ares__expand_name_for_response(aptr, abuf, alen, &ptrname, &len); + if (status != ARES_SUCCESS) + return status; + if (aptr + len + QFIXEDSZ > abuf + alen) + { + free(ptrname); + return ARES_EBADRESP; + } + aptr += len + QFIXEDSZ; + + /* Examine each answer resource record (RR) in turn. */ + hostname = NULL; + aliases = malloc(alias_alloc * sizeof(char *)); + if (!aliases) + { + free(ptrname); + return ARES_ENOMEM; + } + for (i = 0; i < (int)ancount; i++) + { + /* Decode the RR up to the data field. */ + status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len); + if (status != ARES_SUCCESS) + break; + aptr += len; + if (aptr + RRFIXEDSZ > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + rr_type = DNS_RR_TYPE(aptr); + rr_class = DNS_RR_CLASS(aptr); + rr_len = DNS_RR_LEN(aptr); + aptr += RRFIXEDSZ; + + if (rr_class == C_IN && rr_type == T_PTR + && strcasecmp(rr_name, ptrname) == 0) + { + /* Decode the RR data and set hostname to it. */ + status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data, + &len); + if (status != ARES_SUCCESS) + break; + if (hostname) + free(hostname); + hostname = rr_data; + aliases[aliascnt] = malloc((strlen(rr_data)+1) * sizeof(char *)); + if (!aliases[aliascnt]) + { + status = ARES_ENOMEM; + break; + } + strncpy(aliases[aliascnt], rr_data, strlen(rr_data)+1); + aliascnt++; + if (aliascnt >= alias_alloc) { + char **ptr; + alias_alloc *= 2; + ptr = realloc(aliases, alias_alloc * sizeof(char *)); + if(!ptr) { + status = ARES_ENOMEM; + break; + } + aliases = ptr; + } + } + + if (rr_class == C_IN && rr_type == T_CNAME) + { + /* Decode the RR data and replace ptrname with it. */ + status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data, + &len); + if (status != ARES_SUCCESS) + break; + free(ptrname); + ptrname = rr_data; + } + + free(rr_name); + aptr += rr_len; + if (aptr > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + } + + if (status == ARES_SUCCESS && !hostname) + status = ARES_ENODATA; + if (status == ARES_SUCCESS) + { + /* We got our answer. Allocate memory to build the host entry. */ + hostent = malloc(sizeof(struct hostent)); + if (hostent) + { + hostent->h_addr_list = malloc(2 * sizeof(char *)); + if (hostent->h_addr_list) + { + hostent->h_addr_list[0] = malloc(addrlen); + if (hostent->h_addr_list[0]) + { + hostent->h_aliases = malloc((aliascnt+1) * sizeof (char *)); + if (hostent->h_aliases) + { + /* Fill in the hostent and return successfully. */ + hostent->h_name = hostname; + for (i=0 ; ih_aliases[i] = aliases[i]; + hostent->h_aliases[aliascnt] = NULL; + hostent->h_addrtype = family; + hostent->h_length = addrlen; + memcpy(hostent->h_addr_list[0], addr, addrlen); + hostent->h_addr_list[1] = NULL; + *host = hostent; + free(aliases); + free(ptrname); + return ARES_SUCCESS; + } + free(hostent->h_addr_list[0]); + } + free(hostent->h_addr_list); + } + free(hostent); + } + status = ARES_ENOMEM; + } + for (i=0 ; i + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include "ares.h" +#include "ares_dns.h" +#include "ares_data.h" +#include "ares_private.h" + +/* AIX portability check */ +#ifndef T_SRV +# define T_SRV 33 /* server selection */ +#endif + +int +ares_parse_srv_reply (const unsigned char *abuf, int alen, + struct ares_srv_reply **srv_out) +{ + unsigned int qdcount, ancount, i; + const unsigned char *aptr, *vptr; + int status, rr_type, rr_class, rr_len; + long len; + char *hostname = NULL, *rr_name = NULL; + struct ares_srv_reply *srv_head = NULL; + struct ares_srv_reply *srv_last = NULL; + struct ares_srv_reply *srv_curr; + + /* Set *srv_out to NULL for all failure cases. */ + *srv_out = NULL; + + /* Give up if abuf doesn't have room for a header. */ + if (alen < HFIXEDSZ) + return ARES_EBADRESP; + + /* Fetch the question and answer count from the header. */ + qdcount = DNS_HEADER_QDCOUNT (abuf); + ancount = DNS_HEADER_ANCOUNT (abuf); + if (qdcount != 1) + return ARES_EBADRESP; + if (ancount == 0) + return ARES_ENODATA; + + /* Expand the name from the question, and skip past the question. */ + aptr = abuf + HFIXEDSZ; + status = ares_expand_name (aptr, abuf, alen, &hostname, &len); + if (status != ARES_SUCCESS) + return status; + + if (aptr + len + QFIXEDSZ > abuf + alen) + { + free (hostname); + return ARES_EBADRESP; + } + aptr += len + QFIXEDSZ; + + /* Examine each answer resource record (RR) in turn. */ + for (i = 0; i < ancount; i++) + { + /* Decode the RR up to the data field. */ + status = ares_expand_name (aptr, abuf, alen, &rr_name, &len); + if (status != ARES_SUCCESS) + { + break; + } + aptr += len; + if (aptr + RRFIXEDSZ > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + rr_type = DNS_RR_TYPE (aptr); + rr_class = DNS_RR_CLASS (aptr); + rr_len = DNS_RR_LEN (aptr); + aptr += RRFIXEDSZ; + + /* Check if we are really looking at a SRV record */ + if (rr_class == C_IN && rr_type == T_SRV) + { + /* parse the SRV record itself */ + if (rr_len < 6) + { + status = ARES_EBADRESP; + break; + } + + /* Allocate storage for this SRV answer appending it to the list */ + srv_curr = ares_malloc_data(ARES_DATATYPE_SRV_REPLY); + if (!srv_curr) + { + status = ARES_ENOMEM; + break; + } + if (srv_last) + { + srv_last->next = srv_curr; + } + else + { + srv_head = srv_curr; + } + srv_last = srv_curr; + + vptr = aptr; + srv_curr->priority = ntohs (*((unsigned short *)vptr)); + vptr += sizeof(unsigned short); + srv_curr->weight = ntohs (*((unsigned short *)vptr)); + vptr += sizeof(unsigned short); + srv_curr->port = ntohs (*((unsigned short *)vptr)); + vptr += sizeof(unsigned short); + + status = ares_expand_name (vptr, abuf, alen, &srv_curr->host, &len); + if (status != ARES_SUCCESS) + break; + } + + /* Don't lose memory in the next iteration */ + free (rr_name); + rr_name = NULL; + + /* Move on to the next record */ + aptr += rr_len; + } + + if (hostname) + free (hostname); + if (rr_name) + free (rr_name); + + /* clean up on error */ + if (status != ARES_SUCCESS) + { + if (srv_head) + ares_free_data (srv_head); + return status; + } + + /* everything looks fine, return the data */ + *srv_out = srv_head; + + return ARES_SUCCESS; +} diff --git a/src/rt/libuv/src/ares/ares_parse_txt_reply.c b/src/rt/libuv/src/ares/ares_parse_txt_reply.c new file mode 100644 index 00000000000..51653328eb0 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_parse_txt_reply.c @@ -0,0 +1,201 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2009 by Jakub Hrozek + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#ifdef HAVE_STRINGS_H +# include +#endif + +#include +#include + +#include "ares.h" +#include "ares_dns.h" +#include "ares_data.h" +#include "ares_private.h" + +int +ares_parse_txt_reply (const unsigned char *abuf, int alen, + struct ares_txt_reply **txt_out) +{ + size_t substr_len, str_len; + unsigned int qdcount, ancount, i; + const unsigned char *aptr; + const unsigned char *strptr; + int status, rr_type, rr_class, rr_len; + long len; + char *hostname = NULL, *rr_name = NULL; + struct ares_txt_reply *txt_head = NULL; + struct ares_txt_reply *txt_last = NULL; + struct ares_txt_reply *txt_curr; + + /* Set *txt_out to NULL for all failure cases. */ + *txt_out = NULL; + + /* Give up if abuf doesn't have room for a header. */ + if (alen < HFIXEDSZ) + return ARES_EBADRESP; + + /* Fetch the question and answer count from the header. */ + qdcount = DNS_HEADER_QDCOUNT (abuf); + ancount = DNS_HEADER_ANCOUNT (abuf); + if (qdcount != 1) + return ARES_EBADRESP; + if (ancount == 0) + return ARES_ENODATA; + + /* Expand the name from the question, and skip past the question. */ + aptr = abuf + HFIXEDSZ; + status = ares_expand_name (aptr, abuf, alen, &hostname, &len); + if (status != ARES_SUCCESS) + return status; + + if (aptr + len + QFIXEDSZ > abuf + alen) + { + free (hostname); + return ARES_EBADRESP; + } + aptr += len + QFIXEDSZ; + + /* Examine each answer resource record (RR) in turn. */ + for (i = 0; i < ancount; i++) + { + /* Decode the RR up to the data field. */ + status = ares_expand_name (aptr, abuf, alen, &rr_name, &len); + if (status != ARES_SUCCESS) + { + break; + } + aptr += len; + if (aptr + RRFIXEDSZ > abuf + alen) + { + status = ARES_EBADRESP; + break; + } + rr_type = DNS_RR_TYPE (aptr); + rr_class = DNS_RR_CLASS (aptr); + rr_len = DNS_RR_LEN (aptr); + aptr += RRFIXEDSZ; + + /* Check if we are really looking at a TXT record */ + if (rr_class == C_IN && rr_type == T_TXT) + { + /* Allocate storage for this TXT answer appending it to the list */ + txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY); + if (!txt_curr) + { + status = ARES_ENOMEM; + break; + } + if (txt_last) + { + txt_last->next = txt_curr; + } + else + { + txt_head = txt_curr; + } + txt_last = txt_curr; + + /* + * There may be multiple substrings in a single TXT record. Each + * substring may be up to 255 characters in length, with a + * "length byte" indicating the size of the substring payload. + * RDATA contains both the length-bytes and payloads of all + * substrings contained therein. + */ + + /* Compute total length to allow a single memory allocation */ + strptr = aptr; + while (strptr < (aptr + rr_len)) + { + substr_len = (unsigned char)*strptr; + txt_curr->length += substr_len; + strptr += substr_len + 1; + } + + /* Including null byte */ + txt_curr->txt = malloc (txt_curr->length + 1); + if (txt_curr->txt == NULL) + { + status = ARES_ENOMEM; + break; + } + + /* Step through the list of substrings, concatenating them */ + str_len = 0; + strptr = aptr; + while (strptr < (aptr + rr_len)) + { + substr_len = (unsigned char)*strptr; + strptr++; + memcpy ((char *) txt_curr->txt + str_len, strptr, substr_len); + str_len += substr_len; + strptr += substr_len; + } + /* Make sure we NULL-terminate */ + *((char *) txt_curr->txt + txt_curr->length) = '\0'; + } + + /* Don't lose memory in the next iteration */ + free (rr_name); + rr_name = NULL; + + /* Move on to the next record */ + aptr += rr_len; + } + + if (hostname) + free (hostname); + if (rr_name) + free (rr_name); + + /* clean up on error */ + if (status != ARES_SUCCESS) + { + if (txt_head) + ares_free_data (txt_head); + return status; + } + + /* everything looks fine, return the data */ + *txt_out = txt_head; + + return ARES_SUCCESS; +} diff --git a/src/rt/libuv/src/ares/ares_private.h b/src/rt/libuv/src/ares/ares_private.h new file mode 100644 index 00000000000..bf21abd8259 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_private.h @@ -0,0 +1,351 @@ +#ifndef __ARES_PRIVATE_H +#define __ARES_PRIVATE_H + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2004-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +/* + * Define WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) +#define WIN32 +#endif + +#include +#include + +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifdef WATT32 +#include +#include +#define writev(s,v,c) writev_s(s,v,c) +#define HAVE_WRITEV 1 +#endif + +#ifdef NETWARE +#include +#endif + +#define DEFAULT_TIMEOUT 5000 /* milliseconds */ +#define DEFAULT_TRIES 4 +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + +#if defined(WIN32) && !defined(WATT32) + +#define IS_NT() ((int)GetVersion() > 0) +#define WIN_NS_9X "System\\CurrentControlSet\\Services\\VxD\\MSTCP" +#define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters" +#define NAMESERVER "NameServer" +#define DHCPNAMESERVER "DhcpNameServer" +#define DATABASEPATH "DatabasePath" +#define WIN_PATH_HOSTS "\\hosts" + +#elif defined(WATT32) + +#define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf" + +#elif defined(NETWARE) + +#define PATH_RESOLV_CONF "sys:/etc/resolv.cfg" +#define PATH_HOSTS "sys:/etc/hosts" + +#elif defined(__riscos__) + +#define PATH_HOSTS "InetDBase:Hosts" + +#else + +#define PATH_RESOLV_CONF "/etc/resolv.conf" +#ifdef ETC_INET +#define PATH_HOSTS "/etc/inet/hosts" +#else +#define PATH_HOSTS "/etc/hosts" +#endif + +#endif + +#define ARES_ID_KEY_LEN 31 + +#include "ares_ipv6.h" +#include "ares_llist.h" + +#ifndef HAVE_STRDUP +# include "ares_strdup.h" +# define strdup(ptr) ares_strdup(ptr) +#endif + +#ifndef HAVE_STRCASECMP +# include "ares_strcasecmp.h" +# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2) +#endif + +#ifndef HAVE_STRNCASECMP +# include "ares_strcasecmp.h" +# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n) +#endif + +#ifndef HAVE_WRITEV +# include "ares_writev.h" +# define writev(s,ptr,cnt) ares_writev(s,ptr,cnt) +#endif + +struct ares_addr { + int family; + union { + struct in_addr addr4; + struct ares_in6_addr addr6; + } addr; +}; +#define addrV4 addr.addr4 +#define addrV6 addr.addr6 + +struct query; + +struct send_request { + /* Remaining data to send */ + const unsigned char *data; + size_t len; + + /* The query for which we're sending this data */ + struct query* owner_query; + /* The buffer we're using, if we have our own copy of the packet */ + unsigned char *data_storage; + + /* Next request in queue */ + struct send_request *next; +}; + +struct server_state { + struct ares_addr addr; + ares_socket_t udp_socket; + ares_socket_t tcp_socket; + + /* Mini-buffer for reading the length word */ + unsigned char tcp_lenbuf[2]; + int tcp_lenbuf_pos; + int tcp_length; + + /* Buffer for reading actual TCP data */ + unsigned char *tcp_buffer; + int tcp_buffer_pos; + + /* TCP output queue */ + struct send_request *qhead; + struct send_request *qtail; + + /* Which incarnation of this connection is this? We don't want to + * retransmit requests into the very same socket, but if the server + * closes on us and we re-open the connection, then we do want to + * re-send. */ + int tcp_connection_generation; + + /* Circular, doubly-linked list of outstanding queries to this server */ + struct list_node queries_to_server; + + /* Link back to owning channel */ + ares_channel channel; + + /* Is this server broken? We mark connections as broken when a + * request that is queued for sending times out. + */ + int is_broken; +}; + +/* State to represent a DNS query */ +struct query { + /* Query ID from qbuf, for faster lookup, and current timeout */ + unsigned short qid; + struct timeval timeout; + + /* + * Links for the doubly-linked lists in which we insert a query. + * These circular, doubly-linked lists that are hash-bucketed based + * the attributes we care about, help making most important + * operations O(1). + */ + struct list_node queries_by_qid; /* hopefully in same cache line as qid */ + struct list_node queries_by_timeout; + struct list_node queries_to_server; + struct list_node all_queries; + + /* Query buf with length at beginning, for TCP transmission */ + unsigned char *tcpbuf; + int tcplen; + + /* Arguments passed to ares_send() (qbuf points into tcpbuf) */ + const unsigned char *qbuf; + int qlen; + ares_callback callback; + void *arg; + + /* Query status */ + int try; /* Number of times we tried this query already. */ + int server; /* Server this query has last been sent to. */ + struct query_server_info *server_info; /* per-server state */ + int using_tcp; + int error_status; + int timeouts; /* number of timeouts we saw for this request */ +}; + +/* Per-server state for a query */ +struct query_server_info { + int skip_server; /* should we skip server, due to errors, etc? */ + int tcp_connection_generation; /* into which TCP connection did we send? */ +}; + +/* An IP address pattern; matches an IP address X if X & mask == addr */ +#define PATTERN_MASK 0x1 +#define PATTERN_CIDR 0x2 + +struct apattern { + union + { + struct in_addr addr4; + struct ares_in6_addr addr6; + } addr; + union + { + struct in_addr addr4; + struct ares_in6_addr addr6; + unsigned short bits; + } mask; + int family; + unsigned short type; +}; + +typedef struct rc4_key +{ + unsigned char state[256]; + unsigned char x; + unsigned char y; +} rc4_key; + +struct ares_channeldata { + /* Configuration data */ + int flags; + int timeout; /* in milliseconds */ + int tries; + int ndots; + int rotate; /* if true, all servers specified are used */ + int udp_port; + int tcp_port; + int socket_send_buffer_size; + int socket_receive_buffer_size; + char **domains; + int ndomains; + struct apattern *sortlist; + int nsort; + char *lookups; + + /* For binding to local devices and/or IP addresses. Leave + * them null/zero for no binding. + */ + char local_dev_name[32]; + unsigned int local_ip4; + unsigned char local_ip6[16]; + + int optmask; /* the option bitfield passed in at init time */ + + /* Server addresses and communications state */ + struct server_state *servers; + int nservers; + + /* ID to use for next query */ + unsigned short next_id; + /* key to use when generating new ids */ + rc4_key id_key; + + /* Generation number to use for the next TCP socket open/close */ + int tcp_connection_generation; + + /* The time at which we last called process_timeouts(). Uses integer seconds + just to draw the line somewhere. */ + time_t last_timeout_processed; + + /* Last server we sent a query to. */ + int last_server; + + /* Circular, doubly-linked list of queries, bucketed various ways.... */ + /* All active queries in a single list: */ + struct list_node all_queries; + /* Queries bucketed by qid, for quickly dispatching DNS responses: */ +#define ARES_QID_TABLE_SIZE 2048 + struct list_node queries_by_qid[ARES_QID_TABLE_SIZE]; + /* Queries bucketed by timeout, for quickly handling timeouts: */ +#define ARES_TIMEOUT_TABLE_SIZE 1024 + struct list_node queries_by_timeout[ARES_TIMEOUT_TABLE_SIZE]; + + ares_sock_state_cb sock_state_cb; + void *sock_state_cb_data; + + ares_sock_create_callback sock_create_cb; + void *sock_create_cb_data; +}; + +/* return true if now is exactly check time or later */ +int ares__timedout(struct timeval *now, + struct timeval *check); +/* add the specific number of milliseconds to the time in the first argument */ +int ares__timeadd(struct timeval *now, + int millisecs); +/* return time offset between now and (future) check, in milliseconds */ +long ares__timeoffset(struct timeval *now, + struct timeval *check); +/* returns ARES_SUCCESS if library has been initialized */ +int ares_library_initialized(void); +void ares__rc4(rc4_key* key,unsigned char *buffer_ptr, int buffer_len); +void ares__send_query(ares_channel channel, struct query *query, + struct timeval *now); +void ares__close_sockets(ares_channel channel, struct server_state *server); +int ares__get_hostent(FILE *fp, int family, struct hostent **host); +int ares__read_line(FILE *fp, char **buf, size_t *bufsize); +void ares__free_query(struct query *query); +unsigned short ares__generate_new_id(rc4_key* key); +struct timeval ares__tvnow(void); +int ares__expand_name_for_response(const unsigned char *encoded, + const unsigned char *abuf, int alen, + char **s, long *enclen); +void ares__init_servers_state(ares_channel channel); +void ares__destroy_servers_state(ares_channel channel); +#if 0 /* Not used */ +long ares__tvdiff(struct timeval t1, struct timeval t2); +#endif + +#define ARES_SWAP_BYTE(a,b) \ + { unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; } + +#define SOCK_STATE_CALLBACK(c, s, r, w) \ + do { \ + if ((c)->sock_state_cb) \ + (c)->sock_state_cb((c)->sock_state_cb_data, (s), (r), (w)); \ + } while (0) + +#ifdef CURLDEBUG +/* This is low-level hard-hacking memory leak tracking and similar. Using the + libcurl lowlevel code from within library is ugly and only works when + c-ares is built and linked with a similarly curldebug-enabled libcurl, + but we do this anyway for convenience. */ +#include "../lib/memdebug.h" +#endif + +#endif /* __ARES_PRIVATE_H */ diff --git a/src/rt/libuv/src/ares/ares_process.c b/src/rt/libuv/src/ares/ares_process.c new file mode 100644 index 00000000000..7d04effa8a3 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_process.c @@ -0,0 +1,1296 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * Copyright (C) 2004-2010 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_SYS_UIO_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_NETINET_TCP_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#ifdef HAVE_SYS_TIME_H +# include +#endif + +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif +#ifdef HAVE_SYS_IOCTL_H +# include +#endif +#ifdef NETWARE +# include +#endif + +#include +#include +#include +#include +#include +#include + +#include "ares.h" +#include "ares_dns.h" +#include "ares_private.h" + + +static int try_again(int errnum); +static void write_tcp_data(ares_channel channel, fd_set *write_fds, + ares_socket_t write_fd, struct timeval *now); +static void read_tcp_data(ares_channel channel, fd_set *read_fds, + ares_socket_t read_fd, struct timeval *now); +static void read_udp_packets(ares_channel channel, fd_set *read_fds, + ares_socket_t read_fd, struct timeval *now); +static void advance_tcp_send_queue(ares_channel channel, int whichserver, + ssize_t num_bytes); +static void process_timeouts(ares_channel channel, struct timeval *now); +static void process_broken_connections(ares_channel channel, + struct timeval *now); +static void process_answer(ares_channel channel, unsigned char *abuf, + int alen, int whichserver, int tcp, + struct timeval *now); +static void handle_error(ares_channel channel, int whichserver, + struct timeval *now); +static void skip_server(ares_channel channel, struct query *query, + int whichserver); +static void next_server(ares_channel channel, struct query *query, + struct timeval *now); +static int open_tcp_socket(ares_channel channel, struct server_state *server); +static int open_udp_socket(ares_channel channel, struct server_state *server); +static int same_questions(const unsigned char *qbuf, int qlen, + const unsigned char *abuf, int alen); +static int same_address(struct sockaddr *sa, struct ares_addr *aa); +static void end_query(ares_channel channel, struct query *query, int status, + unsigned char *abuf, int alen); + +/* return true if now is exactly check time or later */ +int ares__timedout(struct timeval *now, + struct timeval *check) +{ + long secs = (now->tv_sec - check->tv_sec); + + if(secs > 0) + return 1; /* yes, timed out */ + if(secs < 0) + return 0; /* nope, not timed out */ + + /* if the full seconds were identical, check the sub second parts */ + return (now->tv_usec - check->tv_usec >= 0); +} + +/* add the specific number of milliseconds to the time in the first argument */ +int ares__timeadd(struct timeval *now, + int millisecs) +{ + now->tv_sec += millisecs/1000; + now->tv_usec += (millisecs%1000)*1000; + + if(now->tv_usec >= 1000000) { + ++(now->tv_sec); + now->tv_usec -= 1000000; + } + + return 0; +} + +/* return time offset between now and (future) check, in milliseconds */ +long ares__timeoffset(struct timeval *now, + struct timeval *check) +{ + return (check->tv_sec - now->tv_sec)*1000 + + (check->tv_usec - now->tv_usec)/1000; +} + + +/* + * generic process function + */ +static void processfds(ares_channel channel, + fd_set *read_fds, ares_socket_t read_fd, + fd_set *write_fds, ares_socket_t write_fd) +{ + struct timeval now = ares__tvnow(); + + write_tcp_data(channel, write_fds, write_fd, &now); + read_tcp_data(channel, read_fds, read_fd, &now); + read_udp_packets(channel, read_fds, read_fd, &now); + process_timeouts(channel, &now); + process_broken_connections(channel, &now); +} + +/* Something interesting happened on the wire, or there was a timeout. + * See what's up and respond accordingly. + */ +void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds) +{ + processfds(channel, read_fds, ARES_SOCKET_BAD, write_fds, ARES_SOCKET_BAD); +} + +/* Something interesting happened on the wire, or there was a timeout. + * See what's up and respond accordingly. + */ +void ares_process_fd(ares_channel channel, + ares_socket_t read_fd, /* use ARES_SOCKET_BAD or valid + file descriptors */ + ares_socket_t write_fd) +{ + processfds(channel, NULL, read_fd, NULL, write_fd); +} + + +/* Return 1 if the specified error number describes a readiness error, or 0 + * otherwise. This is mostly for HP-UX, which could return EAGAIN or + * EWOULDBLOCK. See this man page + * + * http://devrsrc1.external.hp.com/STKS/cgi-bin/man2html? + * manpage=/usr/share/man/man2.Z/send.2 + */ +static int try_again(int errnum) +{ +#if !defined EWOULDBLOCK && !defined EAGAIN +#error "Neither EWOULDBLOCK nor EAGAIN defined" +#endif + switch (errnum) + { +#ifdef EWOULDBLOCK + case EWOULDBLOCK: + return 1; +#endif +#if defined EAGAIN && EAGAIN != EWOULDBLOCK + case EAGAIN: + return 1; +#endif + } + return 0; +} + +/* If any TCP sockets select true for writing, write out queued data + * we have for them. + */ +static void write_tcp_data(ares_channel channel, + fd_set *write_fds, + ares_socket_t write_fd, + struct timeval *now) +{ + struct server_state *server; + struct send_request *sendreq; + struct iovec *vec; + int i; + ssize_t scount; + ssize_t wcount; + size_t n; + + if(!write_fds && (write_fd == ARES_SOCKET_BAD)) + /* no possible action */ + return; + + for (i = 0; i < channel->nservers; i++) + { + /* Make sure server has data to send and is selected in write_fds or + write_fd. */ + server = &channel->servers[i]; + if (!server->qhead || server->tcp_socket == ARES_SOCKET_BAD || + server->is_broken) + continue; + + if(write_fds) { + if(!FD_ISSET(server->tcp_socket, write_fds)) + continue; + } + else { + if(server->tcp_socket != write_fd) + continue; + } + + if(write_fds) + /* If there's an error and we close this socket, then open + * another with the same fd to talk to another server, then we + * don't want to think that it was the new socket that was + * ready. This is not disastrous, but is likely to result in + * extra system calls and confusion. */ + FD_CLR(server->tcp_socket, write_fds); + + /* Count the number of send queue items. */ + n = 0; + for (sendreq = server->qhead; sendreq; sendreq = sendreq->next) + n++; + + /* Allocate iovecs so we can send all our data at once. */ + vec = malloc(n * sizeof(struct iovec)); + if (vec) + { + /* Fill in the iovecs and send. */ + n = 0; + for (sendreq = server->qhead; sendreq; sendreq = sendreq->next) + { + vec[n].iov_base = (char *) sendreq->data; + vec[n].iov_len = sendreq->len; + n++; + } + wcount = (ssize_t)writev(server->tcp_socket, vec, (int)n); + free(vec); + if (wcount < 0) + { + if (!try_again(SOCKERRNO)) + handle_error(channel, i, now); + continue; + } + + /* Advance the send queue by as many bytes as we sent. */ + advance_tcp_send_queue(channel, i, wcount); + } + else + { + /* Can't allocate iovecs; just send the first request. */ + sendreq = server->qhead; + + scount = swrite(server->tcp_socket, sendreq->data, sendreq->len); + if (scount < 0) + { + if (!try_again(SOCKERRNO)) + handle_error(channel, i, now); + continue; + } + + /* Advance the send queue by as many bytes as we sent. */ + advance_tcp_send_queue(channel, i, scount); + } + } +} + +/* Consume the given number of bytes from the head of the TCP send queue. */ +static void advance_tcp_send_queue(ares_channel channel, int whichserver, + ssize_t num_bytes) +{ + struct send_request *sendreq; + struct server_state *server = &channel->servers[whichserver]; + while (num_bytes > 0) + { + sendreq = server->qhead; + if ((size_t)num_bytes >= sendreq->len) + { + num_bytes -= sendreq->len; + server->qhead = sendreq->next; + if (server->qhead == NULL) + { + SOCK_STATE_CALLBACK(channel, server->tcp_socket, 1, 0); + server->qtail = NULL; + } + if (sendreq->data_storage != NULL) + free(sendreq->data_storage); + free(sendreq); + } + else + { + sendreq->data += num_bytes; + sendreq->len -= num_bytes; + num_bytes = 0; + } + } +} + +/* If any TCP socket selects true for reading, read some data, + * allocate a buffer if we finish reading the length word, and process + * a packet if we finish reading one. + */ +static void read_tcp_data(ares_channel channel, fd_set *read_fds, + ares_socket_t read_fd, struct timeval *now) +{ + struct server_state *server; + int i; + ssize_t count; + + if(!read_fds && (read_fd == ARES_SOCKET_BAD)) + /* no possible action */ + return; + + for (i = 0; i < channel->nservers; i++) + { + /* Make sure the server has a socket and is selected in read_fds. */ + server = &channel->servers[i]; + if (server->tcp_socket == ARES_SOCKET_BAD || server->is_broken) + continue; + + if(read_fds) { + if(!FD_ISSET(server->tcp_socket, read_fds)) + continue; + } + else { + if(server->tcp_socket != read_fd) + continue; + } + + if(read_fds) + /* If there's an error and we close this socket, then open + * another with the same fd to talk to another server, then we + * don't want to think that it was the new socket that was + * ready. This is not disastrous, but is likely to result in + * extra system calls and confusion. */ + FD_CLR(server->tcp_socket, read_fds); + + if (server->tcp_lenbuf_pos != 2) + { + /* We haven't yet read a length word, so read that (or + * what's left to read of it). + */ + count = sread(server->tcp_socket, + server->tcp_lenbuf + server->tcp_lenbuf_pos, + 2 - server->tcp_lenbuf_pos); + if (count <= 0) + { + if (!(count == -1 && try_again(SOCKERRNO))) + handle_error(channel, i, now); + continue; + } + + server->tcp_lenbuf_pos += (int)count; + if (server->tcp_lenbuf_pos == 2) + { + /* We finished reading the length word. Decode the + * length and allocate a buffer for the data. + */ + server->tcp_length = server->tcp_lenbuf[0] << 8 + | server->tcp_lenbuf[1]; + server->tcp_buffer = malloc(server->tcp_length); + if (!server->tcp_buffer) + handle_error(channel, i, now); + server->tcp_buffer_pos = 0; + } + } + else + { + /* Read data into the allocated buffer. */ + count = sread(server->tcp_socket, + server->tcp_buffer + server->tcp_buffer_pos, + server->tcp_length - server->tcp_buffer_pos); + if (count <= 0) + { + if (!(count == -1 && try_again(SOCKERRNO))) + handle_error(channel, i, now); + continue; + } + + server->tcp_buffer_pos += (int)count; + if (server->tcp_buffer_pos == server->tcp_length) + { + /* We finished reading this answer; process it and + * prepare to read another length word. + */ + process_answer(channel, server->tcp_buffer, server->tcp_length, + i, 1, now); + if (server->tcp_buffer) + free(server->tcp_buffer); + server->tcp_buffer = NULL; + server->tcp_lenbuf_pos = 0; + server->tcp_buffer_pos = 0; + } + } + } +} + +/* If any UDP sockets select true for reading, process them. */ +static void read_udp_packets(ares_channel channel, fd_set *read_fds, + ares_socket_t read_fd, struct timeval *now) +{ + struct server_state *server; + int i; + ssize_t count; + unsigned char buf[PACKETSZ + 1]; +#ifdef HAVE_RECVFROM + ares_socklen_t fromlen; + union { + struct sockaddr sa; + struct sockaddr_in sa4; + struct sockaddr_in6 sa6; + } from; +#endif + + if(!read_fds && (read_fd == ARES_SOCKET_BAD)) + /* no possible action */ + return; + + for (i = 0; i < channel->nservers; i++) + { + /* Make sure the server has a socket and is selected in read_fds. */ + server = &channel->servers[i]; + + if (server->udp_socket == ARES_SOCKET_BAD || server->is_broken) + continue; + + if(read_fds) { + if(!FD_ISSET(server->udp_socket, read_fds)) + continue; + } + else { + if(server->udp_socket != read_fd) + continue; + } + + if(read_fds) + /* If there's an error and we close this socket, then open + * another with the same fd to talk to another server, then we + * don't want to think that it was the new socket that was + * ready. This is not disastrous, but is likely to result in + * extra system calls and confusion. */ + FD_CLR(server->udp_socket, read_fds); + + /* To reduce event loop overhead, read and process as many + * packets as we can. */ + do { +#ifdef HAVE_RECVFROM + if (server->addr.family == AF_INET) + fromlen = sizeof(from.sa4); + else + fromlen = sizeof(from.sa6); + count = (ssize_t)recvfrom(server->udp_socket, (void *)buf, sizeof(buf), + 0, &from.sa, &fromlen); +#else + count = sread(server->udp_socket, buf, sizeof(buf)); +#endif + if (count == -1 && try_again(SOCKERRNO)) + continue; + else if (count <= 0) + handle_error(channel, i, now); +#ifdef HAVE_RECVFROM + else if (!same_address(&from.sa, &server->addr)) + /* The address the response comes from does not match + * the address we sent the request to. Someone may be + * attempting to perform a cache poisoning attack. */ + break; +#endif + else + process_answer(channel, buf, (int)count, i, 0, now); + } while (count > 0); + } +} + +/* If any queries have timed out, note the timeout and move them on. */ +static void process_timeouts(ares_channel channel, struct timeval *now) +{ + time_t t; /* the time of the timeouts we're processing */ + struct query *query; + struct list_node* list_head; + struct list_node* list_node; + + /* Process all the timeouts that have fired since the last time we + * processed timeouts. If things are going well, then we'll have + * hundreds/thousands of queries that fall into future buckets, and + * only a handful of requests that fall into the "now" bucket, so + * this should be quite quick. + */ + for (t = channel->last_timeout_processed; t <= now->tv_sec; t++) + { + list_head = &(channel->queries_by_timeout[t % ARES_TIMEOUT_TABLE_SIZE]); + for (list_node = list_head->next; list_node != list_head; ) + { + query = list_node->data; + list_node = list_node->next; /* in case the query gets deleted */ + if (query->timeout.tv_sec && ares__timedout(now, &query->timeout)) + { + query->error_status = ARES_ETIMEOUT; + ++query->timeouts; + next_server(channel, query, now); + } + } + } + channel->last_timeout_processed = now->tv_sec; +} + +/* Handle an answer from a server. */ +static void process_answer(ares_channel channel, unsigned char *abuf, + int alen, int whichserver, int tcp, + struct timeval *now) +{ + int tc, rcode; + unsigned short id; + struct query *query; + struct list_node* list_head; + struct list_node* list_node; + + /* If there's no room in the answer for a header, we can't do much + * with it. */ + if (alen < HFIXEDSZ) + return; + + /* Grab the query ID, truncate bit, and response code from the packet. */ + id = DNS_HEADER_QID(abuf); + tc = DNS_HEADER_TC(abuf); + rcode = DNS_HEADER_RCODE(abuf); + + /* Find the query corresponding to this packet. The queries are + * hashed/bucketed by query id, so this lookup should be quick. + * Note that both the query id and the questions must be the same; + * when the query id wraps around we can have multiple outstanding + * queries with the same query id, so we need to check both the id and + * question. + */ + query = NULL; + list_head = &(channel->queries_by_qid[id % ARES_QID_TABLE_SIZE]); + for (list_node = list_head->next; list_node != list_head; + list_node = list_node->next) + { + struct query *q = list_node->data; + if ((q->qid == id) && same_questions(q->qbuf, q->qlen, abuf, alen)) + { + query = q; + break; + } + } + if (!query) + return; + + /* If we got a truncated UDP packet and are not ignoring truncation, + * don't accept the packet, and switch the query to TCP if we hadn't + * done so already. + */ + if ((tc || alen > PACKETSZ) && !tcp && !(channel->flags & ARES_FLAG_IGNTC)) + { + if (!query->using_tcp) + { + query->using_tcp = 1; + ares__send_query(channel, query, now); + } + return; + } + + /* Limit alen to PACKETSZ if we aren't using TCP (only relevant if we + * are ignoring truncation. + */ + if (alen > PACKETSZ && !tcp) + alen = PACKETSZ; + + /* If we aren't passing through all error packets, discard packets + * with SERVFAIL, NOTIMP, or REFUSED response codes. + */ + if (!(channel->flags & ARES_FLAG_NOCHECKRESP)) + { + if (rcode == SERVFAIL || rcode == NOTIMP || rcode == REFUSED) + { + skip_server(channel, query, whichserver); + if (query->server == whichserver) + next_server(channel, query, now); + return; + } + } + + end_query(channel, query, ARES_SUCCESS, abuf, alen); +} + +/* Close all the connections that are no longer usable. */ +static void process_broken_connections(ares_channel channel, + struct timeval *now) +{ + int i; + for (i = 0; i < channel->nservers; i++) + { + struct server_state *server = &channel->servers[i]; + if (server->is_broken) + { + handle_error(channel, i, now); + } + } +} + +static void handle_error(ares_channel channel, int whichserver, + struct timeval *now) +{ + struct server_state *server; + struct query *query; + struct list_node list_head; + struct list_node* list_node; + + server = &channel->servers[whichserver]; + + /* Reset communications with this server. */ + ares__close_sockets(channel, server); + + /* Tell all queries talking to this server to move on and not try + * this server again. We steal the current list of queries that were + * in-flight to this server, since when we call next_server this can + * cause the queries to be re-sent to this server, which will + * re-insert these queries in that same server->queries_to_server + * list. + */ + ares__init_list_head(&list_head); + ares__swap_lists(&list_head, &(server->queries_to_server)); + for (list_node = list_head.next; list_node != &list_head; ) + { + query = list_node->data; + list_node = list_node->next; /* in case the query gets deleted */ + assert(query->server == whichserver); + skip_server(channel, query, whichserver); + next_server(channel, query, now); + } + /* Each query should have removed itself from our temporary list as + * it re-sent itself or finished up... + */ + assert(ares__is_list_empty(&list_head)); +} + +static void skip_server(ares_channel channel, struct query *query, + int whichserver) { + /* The given server gave us problems with this query, so if we have + * the luxury of using other servers, then let's skip the + * potentially broken server and just use the others. If we only + * have one server and we need to retry then we should just go ahead + * and re-use that server, since it's our only hope; perhaps we + * just got unlucky, and retrying will work (eg, the server timed + * out our TCP connection just as we were sending another request). + */ + if (channel->nservers > 1) + { + query->server_info[whichserver].skip_server = 1; + } +} + +static void next_server(ares_channel channel, struct query *query, + struct timeval *now) +{ + /* We need to try each server channel->tries times. We have channel->nservers + * servers to try. In total, we need to do channel->nservers * channel->tries + * attempts. Use query->try to remember how many times we already attempted + * this query. Use modular arithmetic to find the next server to try. */ + while (++(query->try) < (channel->nservers * channel->tries)) + { + struct server_state *server; + + /* Move on to the next server. */ + query->server = (query->server + 1) % channel->nservers; + server = &channel->servers[query->server]; + + /* We don't want to use this server if (1) we decided this + * connection is broken, and thus about to be closed, (2) + * we've decided to skip this server because of earlier + * errors we encountered, or (3) we already sent this query + * over this exact connection. + */ + if (!server->is_broken && + !query->server_info[query->server].skip_server && + !(query->using_tcp && + (query->server_info[query->server].tcp_connection_generation == + server->tcp_connection_generation))) + { + ares__send_query(channel, query, now); + return; + } + + /* You might think that with TCP we only need one try. However, + * even when using TCP, servers can time-out our connection just + * as we're sending a request, or close our connection because + * they die, or never send us a reply because they get wedged or + * tickle a bug that drops our request. + */ + } + + /* If we are here, all attempts to perform query failed. */ + end_query(channel, query, query->error_status, NULL, 0); +} + +void ares__send_query(ares_channel channel, struct query *query, + struct timeval *now) +{ + struct send_request *sendreq; + struct server_state *server; + int timeplus; + + server = &channel->servers[query->server]; + if (query->using_tcp) + { + /* Make sure the TCP socket for this server is set up and queue + * a send request. + */ + if (server->tcp_socket == ARES_SOCKET_BAD) + { + if (open_tcp_socket(channel, server) == -1) + { + skip_server(channel, query, query->server); + next_server(channel, query, now); + return; + } + } + sendreq = calloc(1, sizeof(struct send_request)); + if (!sendreq) + { + end_query(channel, query, ARES_ENOMEM, NULL, 0); + return; + } + /* To make the common case fast, we avoid copies by using the + * query's tcpbuf for as long as the query is alive. In the rare + * case where the query ends while it's queued for transmission, + * then we give the sendreq its own copy of the request packet + * and put it in sendreq->data_storage. + */ + sendreq->data_storage = NULL; + sendreq->data = query->tcpbuf; + sendreq->len = query->tcplen; + sendreq->owner_query = query; + sendreq->next = NULL; + if (server->qtail) + server->qtail->next = sendreq; + else + { + SOCK_STATE_CALLBACK(channel, server->tcp_socket, 1, 1); + server->qhead = sendreq; + } + server->qtail = sendreq; + query->server_info[query->server].tcp_connection_generation = + server->tcp_connection_generation; + } + else + { + if (server->udp_socket == ARES_SOCKET_BAD) + { + if (open_udp_socket(channel, server) == -1) + { + skip_server(channel, query, query->server); + next_server(channel, query, now); + return; + } + } + if (swrite(server->udp_socket, query->qbuf, query->qlen) == -1) + { + /* FIXME: Handle EAGAIN here since it likely can happen. */ + skip_server(channel, query, query->server); + next_server(channel, query, now); + return; + } + } + timeplus = channel->timeout << (query->try / channel->nservers); + timeplus = (timeplus * (9 + (rand () & 7))) / 16; + query->timeout = *now; + ares__timeadd(&query->timeout, + timeplus); + /* Keep track of queries bucketed by timeout, so we can process + * timeout events quickly. + */ + ares__remove_from_list(&(query->queries_by_timeout)); + ares__insert_in_list( + &(query->queries_by_timeout), + &(channel->queries_by_timeout[query->timeout.tv_sec % + ARES_TIMEOUT_TABLE_SIZE])); + + /* Keep track of queries bucketed by server, so we can process server + * errors quickly. + */ + ares__remove_from_list(&(query->queries_to_server)); + ares__insert_in_list(&(query->queries_to_server), + &(server->queries_to_server)); +} + +/* + * setsocknonblock sets the given socket to either blocking or non-blocking + * mode based on the 'nonblock' boolean argument. This function is highly + * portable. + */ +static int setsocknonblock(ares_socket_t sockfd, /* operate on this */ + int nonblock /* TRUE or FALSE */) +{ +#if defined(USE_BLOCKING_SOCKETS) + + return 0; /* returns success */ + +#elif defined(HAVE_FCNTL_O_NONBLOCK) + + /* most recent unix versions */ + int flags; + flags = fcntl(sockfd, F_GETFL, 0); + if (FALSE != nonblock) + return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); + else + return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK)); + +#elif defined(HAVE_IOCTL_FIONBIO) + + /* older unix versions */ + int flags; + flags = nonblock; + return ioctl(sockfd, FIONBIO, &flags); + +#elif defined(HAVE_IOCTLSOCKET_FIONBIO) + +#ifdef WATT32 + char flags; +#else + /* Windows */ + unsigned long flags; +#endif + flags = nonblock; + return ioctlsocket(sockfd, FIONBIO, &flags); + +#elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO) + + /* Amiga */ + return IoctlSocket(sockfd, FIONBIO, (long)nonblock); + +#elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK) + + /* BeOS */ + long b = nonblock ? 1 : 0; + return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); + +#else +# error "no non-blocking method was found/used/set" +#endif +} + +static int configure_socket(ares_socket_t s, int family, ares_channel channel) +{ + union { + struct sockaddr sa; + struct sockaddr_in sa4; + struct sockaddr_in6 sa6; + } local; + + setsocknonblock(s, TRUE); + +#if defined(FD_CLOEXEC) && !defined(MSDOS) + /* Configure the socket fd as close-on-exec. */ + if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) + return -1; +#endif + + /* Set the socket's send and receive buffer sizes. */ + if ((channel->socket_send_buffer_size > 0) && + setsockopt(s, SOL_SOCKET, SO_SNDBUF, + (void *)&channel->socket_send_buffer_size, + sizeof(channel->socket_send_buffer_size)) == -1) + return -1; + + if ((channel->socket_receive_buffer_size > 0) && + setsockopt(s, SOL_SOCKET, SO_RCVBUF, + (void *)&channel->socket_receive_buffer_size, + sizeof(channel->socket_receive_buffer_size)) == -1) + return -1; + +#ifdef SO_BINDTODEVICE + if (channel->local_dev_name[0]) { + if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, + channel->local_dev_name, sizeof(channel->local_dev_name))) { + /* Only root can do this, and usually not fatal if it doesn't work, so */ + /* just continue on. */ + } + } +#endif + + if (family == AF_INET) { + if (channel->local_ip4) { + memset(&local.sa4, 0, sizeof(local.sa4)); + local.sa4.sin_family = AF_INET; + local.sa4.sin_addr.s_addr = htonl(channel->local_ip4); + if (bind(s, &local.sa, sizeof(local.sa4)) < 0) + return -1; + } + } + else if (family == AF_INET6) { + if (memcmp(channel->local_ip6, &ares_in6addr_any, sizeof(channel->local_ip6)) != 0) { + memset(&local.sa6, 0, sizeof(local.sa6)); + local.sa6.sin6_family = AF_INET6; + memcpy(&local.sa6.sin6_addr, channel->local_ip6, sizeof(channel->local_ip6)); + if (bind(s, &local.sa, sizeof(local.sa6)) < 0) + return -1; + } + } + + return 0; +} + +static int open_tcp_socket(ares_channel channel, struct server_state *server) +{ + ares_socket_t s; + int opt; + ares_socklen_t salen; + union { + struct sockaddr_in sa4; + struct sockaddr_in6 sa6; + } saddr; + struct sockaddr *sa; + + switch (server->addr.family) + { + case AF_INET: + sa = (void *)&saddr.sa4; + salen = sizeof(saddr.sa4); + memset(sa, 0, salen); + saddr.sa4.sin_family = AF_INET; + saddr.sa4.sin_port = (unsigned short)(channel->tcp_port & 0xffff); + memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4, + sizeof(server->addr.addrV4)); + break; + case AF_INET6: + sa = (void *)&saddr.sa6; + salen = sizeof(saddr.sa6); + memset(sa, 0, salen); + saddr.sa6.sin6_family = AF_INET6; + saddr.sa6.sin6_port = (unsigned short)(channel->tcp_port & 0xffff); + memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6, + sizeof(server->addr.addrV6)); + break; + default: + return -1; + } + + /* Acquire a socket. */ + s = socket(server->addr.family, SOCK_STREAM, 0); + if (s == ARES_SOCKET_BAD) + return -1; + + /* Configure it. */ + if (configure_socket(s, server->addr.family, channel) < 0) + { + sclose(s); + return -1; + } + +#ifdef TCP_NODELAY + /* + * Disable the Nagle algorithm (only relevant for TCP sockets, and thus not + * in configure_socket). In general, in DNS lookups we're pretty much + * interested in firing off a single request and then waiting for a reply, + * so batching isn't very interesting. + */ + opt = 1; + if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, + (void *)&opt, sizeof(opt)) == -1) + { + sclose(s); + return -1; + } +#endif + + /* Connect to the server. */ + if (connect(s, sa, salen) == -1) + { + int err = SOCKERRNO; + + if (err != EINPROGRESS && err != EWOULDBLOCK) + { + sclose(s); + return -1; + } + } + + if (channel->sock_create_cb) + { + int err = channel->sock_create_cb(s, SOCK_STREAM, + channel->sock_create_cb_data); + if (err < 0) + { + sclose(s); + return err; + } + } + + SOCK_STATE_CALLBACK(channel, s, 1, 0); + server->tcp_buffer_pos = 0; + server->tcp_socket = s; + server->tcp_connection_generation = ++channel->tcp_connection_generation; + return 0; +} + +static int open_udp_socket(ares_channel channel, struct server_state *server) +{ + ares_socket_t s; + ares_socklen_t salen; + union { + struct sockaddr_in sa4; + struct sockaddr_in6 sa6; + } saddr; + struct sockaddr *sa; + + switch (server->addr.family) + { + case AF_INET: + sa = (void *)&saddr.sa4; + salen = sizeof(saddr.sa4); + memset(sa, 0, salen); + saddr.sa4.sin_family = AF_INET; + saddr.sa4.sin_port = (unsigned short)(channel->udp_port & 0xffff); + memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4, + sizeof(server->addr.addrV4)); + break; + case AF_INET6: + sa = (void *)&saddr.sa6; + salen = sizeof(saddr.sa6); + memset(sa, 0, salen); + saddr.sa6.sin6_family = AF_INET6; + saddr.sa6.sin6_port = (unsigned short)(channel->udp_port & 0xffff); + memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6, + sizeof(server->addr.addrV6)); + break; + default: + return -1; + } + + /* Acquire a socket. */ + s = socket(server->addr.family, SOCK_DGRAM, 0); + if (s == ARES_SOCKET_BAD) + return -1; + + /* Set the socket non-blocking. */ + if (configure_socket(s, server->addr.family, channel) < 0) + { + sclose(s); + return -1; + } + + /* Connect to the server. */ + if (connect(s, sa, salen) == -1) + { + int err = SOCKERRNO; + + if (err != EINPROGRESS && err != EWOULDBLOCK) + { + sclose(s); + return -1; + } + } + + if (channel->sock_create_cb) + { + int err = channel->sock_create_cb(s, SOCK_DGRAM, + channel->sock_create_cb_data); + if (err < 0) + { + sclose(s); + return err; + } + } + + SOCK_STATE_CALLBACK(channel, s, 1, 0); + + server->udp_socket = s; + return 0; +} + +static int same_questions(const unsigned char *qbuf, int qlen, + const unsigned char *abuf, int alen) +{ + struct { + const unsigned char *p; + int qdcount; + char *name; + long namelen; + int type; + int dnsclass; + } q, a; + int i, j; + + if (qlen < HFIXEDSZ || alen < HFIXEDSZ) + return 0; + + /* Extract qdcount from the request and reply buffers and compare them. */ + q.qdcount = DNS_HEADER_QDCOUNT(qbuf); + a.qdcount = DNS_HEADER_QDCOUNT(abuf); + if (q.qdcount != a.qdcount) + return 0; + + /* For each question in qbuf, find it in abuf. */ + q.p = qbuf + HFIXEDSZ; + for (i = 0; i < q.qdcount; i++) + { + /* Decode the question in the query. */ + if (ares_expand_name(q.p, qbuf, qlen, &q.name, &q.namelen) + != ARES_SUCCESS) + return 0; + q.p += q.namelen; + if (q.p + QFIXEDSZ > qbuf + qlen) + { + free(q.name); + return 0; + } + q.type = DNS_QUESTION_TYPE(q.p); + q.dnsclass = DNS_QUESTION_CLASS(q.p); + q.p += QFIXEDSZ; + + /* Search for this question in the answer. */ + a.p = abuf + HFIXEDSZ; + for (j = 0; j < a.qdcount; j++) + { + /* Decode the question in the answer. */ + if (ares_expand_name(a.p, abuf, alen, &a.name, &a.namelen) + != ARES_SUCCESS) + { + free(q.name); + return 0; + } + a.p += a.namelen; + if (a.p + QFIXEDSZ > abuf + alen) + { + free(q.name); + free(a.name); + return 0; + } + a.type = DNS_QUESTION_TYPE(a.p); + a.dnsclass = DNS_QUESTION_CLASS(a.p); + a.p += QFIXEDSZ; + + /* Compare the decoded questions. */ + if (strcasecmp(q.name, a.name) == 0 && q.type == a.type + && q.dnsclass == a.dnsclass) + { + free(a.name); + break; + } + free(a.name); + } + + free(q.name); + if (j == a.qdcount) + return 0; + } + return 1; +} + +static int same_address(struct sockaddr *sa, struct ares_addr *aa) +{ + void *addr1; + void *addr2; + + if (sa->sa_family == aa->family) + { + switch (aa->family) + { + case AF_INET: + addr1 = &aa->addrV4; + addr2 = &((struct sockaddr_in *)sa)->sin_addr; + if (memcmp(addr1, addr2, sizeof(aa->addrV4)) == 0) + return 1; /* match */ + break; + case AF_INET6: + addr1 = &aa->addrV6; + addr2 = &((struct sockaddr_in6 *)sa)->sin6_addr; + if (memcmp(addr1, addr2, sizeof(aa->addrV6)) == 0) + return 1; /* match */ + break; + default: + break; + } + } + return 0; /* different */ +} + +static void end_query (ares_channel channel, struct query *query, int status, + unsigned char *abuf, int alen) +{ + int i; + + /* First we check to see if this query ended while one of our send + * queues still has pointers to it. + */ + for (i = 0; i < channel->nservers; i++) + { + struct server_state *server = &channel->servers[i]; + struct send_request *sendreq; + for (sendreq = server->qhead; sendreq; sendreq = sendreq->next) + if (sendreq->owner_query == query) + { + sendreq->owner_query = NULL; + assert(sendreq->data_storage == NULL); + if (status == ARES_SUCCESS) + { + /* We got a reply for this query, but this queued + * sendreq points into this soon-to-be-gone query's + * tcpbuf. Probably this means we timed out and queued + * the query for retransmission, then received a + * response before actually retransmitting. This is + * perfectly fine, so we want to keep the connection + * running smoothly if we can. But in the worst case + * we may have sent only some prefix of the query, + * with some suffix of the query left to send. Also, + * the buffer may be queued on multiple queues. To + * prevent dangling pointers to the query's tcpbuf and + * handle these cases, we just give such sendreqs + * their own copy of the query packet. + */ + sendreq->data_storage = malloc(sendreq->len); + if (sendreq->data_storage != NULL) + { + memcpy(sendreq->data_storage, sendreq->data, sendreq->len); + sendreq->data = sendreq->data_storage; + } + } + if ((status != ARES_SUCCESS) || (sendreq->data_storage == NULL)) + { + /* We encountered an error (probably a timeout, + * suggesting the DNS server we're talking to is + * probably unreachable, wedged, or severely + * overloaded) or we couldn't copy the request, so + * mark the connection as broken. When we get to + * process_broken_connections() we'll close the + * connection and try to re-send requests to another + * server. + */ + server->is_broken = 1; + /* Just to be paranoid, zero out this sendreq... */ + sendreq->data = NULL; + sendreq->len = 0; + } + } + } + + /* Invoke the callback */ + query->callback(query->arg, status, query->timeouts, abuf, alen); + ares__free_query(query); + + /* Simple cleanup policy: if no queries are remaining, close all + * network sockets unless STAYOPEN is set. + */ + if (!(channel->flags & ARES_FLAG_STAYOPEN) && + ares__is_list_empty(&(channel->all_queries))) + { + for (i = 0; i < channel->nservers; i++) + ares__close_sockets(channel, &channel->servers[i]); + } +} + +void ares__free_query(struct query *query) +{ + /* Remove the query from all the lists in which it is linked */ + ares__remove_from_list(&(query->queries_by_qid)); + ares__remove_from_list(&(query->queries_by_timeout)); + ares__remove_from_list(&(query->queries_to_server)); + ares__remove_from_list(&(query->all_queries)); + /* Zero out some important stuff, to help catch bugs */ + query->callback = NULL; + query->arg = NULL; + /* Deallocate the memory associated with the query */ + free(query->tcpbuf); + free(query->server_info); + free(query); +} diff --git a/src/rt/libuv/src/ares/ares_query.c b/src/rt/libuv/src/ares/ares_query.c new file mode 100644 index 00000000000..63652e229d2 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_query.c @@ -0,0 +1,183 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include "ares.h" +#include "ares_dns.h" +#include "ares_private.h" + +struct qquery { + ares_callback callback; + void *arg; +}; + +static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen); + +void ares__rc4(rc4_key* key, unsigned char *buffer_ptr, int buffer_len) +{ + unsigned char x; + unsigned char y; + unsigned char* state; + unsigned char xorIndex; + short counter; + + x = key->x; + y = key->y; + + state = &key->state[0]; + for(counter = 0; counter < buffer_len; counter ++) + { + x = (unsigned char)((x + 1) % 256); + y = (unsigned char)((state[x] + y) % 256); + ARES_SWAP_BYTE(&state[x], &state[y]); + + xorIndex = (unsigned char)((state[x] + state[y]) % 256); + + buffer_ptr[counter] = (unsigned char)(buffer_ptr[counter]^state[xorIndex]); + } + key->x = x; + key->y = y; +} + +static struct query* find_query_by_id(ares_channel channel, unsigned short id) +{ + unsigned short qid; + struct list_node* list_head; + struct list_node* list_node; + DNS_HEADER_SET_QID(((unsigned char*)&qid), id); + + /* Find the query corresponding to this packet. */ + list_head = &(channel->queries_by_qid[qid % ARES_QID_TABLE_SIZE]); + for (list_node = list_head->next; list_node != list_head; + list_node = list_node->next) + { + struct query *q = list_node->data; + if (q->qid == qid) + return q; + } + return NULL; +} + + +/* a unique query id is generated using an rc4 key. Since the id may already + be used by a running query (as infrequent as it may be), a lookup is + performed per id generation. In practice this search should happen only + once per newly generated id +*/ +static unsigned short generate_unique_id(ares_channel channel) +{ + unsigned short id; + + do { + id = ares__generate_new_id(&channel->id_key); + } while (find_query_by_id(channel, id)); + + return (unsigned short)id; +} + +void ares_query(ares_channel channel, const char *name, int dnsclass, + int type, ares_callback callback, void *arg) +{ + struct qquery *qquery; + unsigned char *qbuf; + int qlen, rd, status; + + /* Compose the query. */ + rd = !(channel->flags & ARES_FLAG_NORECURSE); + status = ares_mkquery(name, dnsclass, type, channel->next_id, rd, &qbuf, + &qlen); + if (status != ARES_SUCCESS) + { + if (qbuf != NULL) free(qbuf); + callback(arg, status, 0, NULL, 0); + return; + } + + channel->next_id = generate_unique_id(channel); + + /* Allocate and fill in the query structure. */ + qquery = malloc(sizeof(struct qquery)); + if (!qquery) + { + ares_free_string(qbuf); + callback(arg, ARES_ENOMEM, 0, NULL, 0); + return; + } + qquery->callback = callback; + qquery->arg = arg; + + /* Send it off. qcallback will be called when we get an answer. */ + ares_send(channel, qbuf, qlen, qcallback, qquery); + ares_free_string(qbuf); +} + +static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen) +{ + struct qquery *qquery = (struct qquery *) arg; + unsigned int ancount; + int rcode; + + if (status != ARES_SUCCESS) + qquery->callback(qquery->arg, status, timeouts, abuf, alen); + else + { + /* Pull the response code and answer count from the packet. */ + rcode = DNS_HEADER_RCODE(abuf); + ancount = DNS_HEADER_ANCOUNT(abuf); + + /* Convert errors. */ + switch (rcode) + { + case NOERROR: + status = (ancount > 0) ? ARES_SUCCESS : ARES_ENODATA; + break; + case FORMERR: + status = ARES_EFORMERR; + break; + case SERVFAIL: + status = ARES_ESERVFAIL; + break; + case NXDOMAIN: + status = ARES_ENOTFOUND; + break; + case NOTIMP: + status = ARES_ENOTIMP; + break; + case REFUSED: + status = ARES_EREFUSED; + break; + } + qquery->callback(qquery->arg, status, timeouts, abuf, alen); + } + free(qquery); +} diff --git a/src/rt/libuv/src/ares/ares_rules.h b/src/rt/libuv/src/ares/ares_rules.h new file mode 100644 index 00000000000..f94c5b59165 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_rules.h @@ -0,0 +1,144 @@ +#ifndef __CARES_RULES_H +#define __CARES_RULES_H + + +/* Copyright (C) 2009 by Daniel Stenberg et al + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +/* ================================================================ */ +/* COMPILE TIME SANITY CHECKS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * All checks done in this file are intentionally placed in a public + * header file which is pulled by ares.h when an application is + * being built using an already built c-ares library. Additionally + * this file is also included and used when building the library. + * + * If compilation fails on this file it is certainly sure that the + * problem is elsewhere. It could be a problem in the ares_build.h + * header file, or simply that you are using different compilation + * settings than those used to build the library. + * + * Nothing in this file is intended to be modified or adjusted by the + * c-ares library user nor by the c-ares library builder. + * + * Do not deactivate any check, these are done to make sure that the + * library is properly built and used. + * + * You can find further help on the c-ares development mailing list: + * http://cool.haxx.se/mailman/listinfo/c-ares/ + * + * NOTE 2 + * ------ + * + * Some of the following compile time checks are based on the fact + * that the dimension of a constant array can not be a negative one. + * In this way if the compile time verification fails, the compilation + * will fail issuing an error. The error description wording is compiler + * dependent but it will be quite similar to one of the following: + * + * "negative subscript or subscript is too large" + * "array must have at least one element" + * "-1 is an illegal array size" + * "size of array is negative" + * + * If you are building an application which tries to use an already + * built c-ares library and you are getting this kind of errors on + * this file, it is a clear indication that there is a mismatch between + * how the library was built and how you are trying to use it for your + * application. Your already compiled or binary library provider is the + * only one who can give you the details you need to properly use it. + */ + +/* + * Verify that some macros are actually defined. + */ + +#ifndef CARES_SIZEOF_LONG +# error "CARES_SIZEOF_LONG definition is missing!" + Error Compilation_aborted_CARES_SIZEOF_LONG_is_missing +#endif + +#ifndef CARES_TYPEOF_ARES_SOCKLEN_T +# error "CARES_TYPEOF_ARES_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing +#endif + +#ifndef CARES_SIZEOF_ARES_SOCKLEN_T +# error "CARES_SIZEOF_ARES_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_is_missing +#endif + +/* + * Macros private to this header file. + */ + +#define CareschkszEQ(t, s) sizeof(t) == s ? 1 : -1 + +#define CareschkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1 + +/* + * Verify that the size previously defined and expected for long + * is the same as the one reported by sizeof() at compile time. + */ + +typedef char + __cares_rule_01__ + [CareschkszEQ(long, CARES_SIZEOF_LONG)]; + +/* + * Verify that the size previously defined and expected for + * ares_socklen_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __cares_rule_02__ + [CareschkszEQ(ares_socklen_t, CARES_SIZEOF_ARES_SOCKLEN_T)]; + +/* + * Verify at compile time that the size of ares_socklen_t as reported + * by sizeof() is greater or equal than the one reported for int for + * the current compilation. + */ + +typedef char + __cares_rule_03__ + [CareschkszGE(ares_socklen_t, int)]; + +/* ================================================================ */ +/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */ +/* ================================================================ */ + +/* + * Get rid of macros private to this header file. + */ + +#undef CareschkszEQ +#undef CareschkszGE + +/* + * Get rid of macros not intended to exist beyond this point. + */ + +#undef CARES_PULL_WS2TCPIP_H +#undef CARES_PULL_SYS_TYPES_H +#undef CARES_PULL_SYS_SOCKET_H + +#undef CARES_TYPEOF_ARES_SOCKLEN_T + +#endif /* __CARES_RULES_H */ diff --git a/src/rt/libuv/src/ares/ares_search.c b/src/rt/libuv/src/ares/ares_search.c new file mode 100644 index 00000000000..608cb153d32 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_search.c @@ -0,0 +1,322 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#include +#include +#include +#include +#include + +#ifdef HAVE_STRINGS_H +# include +#endif + +#include "ares.h" +#include "ares_private.h" + +struct search_query { + /* Arguments passed to ares_search */ + ares_channel channel; + char *name; /* copied into an allocated buffer */ + int dnsclass; + int type; + ares_callback callback; + void *arg; + + int status_as_is; /* error status from trying as-is */ + int next_domain; /* next search domain to try */ + int trying_as_is; /* current query is for name as-is */ + int timeouts; /* number of timeouts we saw for this request */ + int ever_got_nodata; /* did we ever get ARES_ENODATA along the way? */ +}; + +static void search_callback(void *arg, int status, int timeouts, + unsigned char *abuf, int alen); +static void end_squery(struct search_query *squery, int status, + unsigned char *abuf, int alen); +static int cat_domain(const char *name, const char *domain, char **s); +static int single_domain(ares_channel channel, const char *name, char **s); + +void ares_search(ares_channel channel, const char *name, int dnsclass, + int type, ares_callback callback, void *arg) +{ + struct search_query *squery; + char *s; + const char *p; + int status, ndots; + + /* If name only yields one domain to search, then we don't have + * to keep extra state, so just do an ares_query(). + */ + status = single_domain(channel, name, &s); + if (status != ARES_SUCCESS) + { + callback(arg, status, 0, NULL, 0); + return; + } + if (s) + { + ares_query(channel, s, dnsclass, type, callback, arg); + free(s); + return; + } + + /* Allocate a search_query structure to hold the state necessary for + * doing multiple lookups. + */ + squery = malloc(sizeof(struct search_query)); + if (!squery) + { + callback(arg, ARES_ENOMEM, 0, NULL, 0); + return; + } + squery->channel = channel; + squery->name = strdup(name); + if (!squery->name) + { + free(squery); + callback(arg, ARES_ENOMEM, 0, NULL, 0); + return; + } + squery->dnsclass = dnsclass; + squery->type = type; + squery->status_as_is = -1; + squery->callback = callback; + squery->arg = arg; + squery->timeouts = 0; + squery->ever_got_nodata = 0; + + /* Count the number of dots in name. */ + ndots = 0; + for (p = name; *p; p++) + { + if (*p == '.') + ndots++; + } + + /* If ndots is at least the channel ndots threshold (usually 1), + * then we try the name as-is first. Otherwise, we try the name + * as-is last. + */ + if (ndots >= channel->ndots) + { + /* Try the name as-is first. */ + squery->next_domain = 0; + squery->trying_as_is = 1; + ares_query(channel, name, dnsclass, type, search_callback, squery); + } + else + { + /* Try the name as-is last; start with the first search domain. */ + squery->next_domain = 1; + squery->trying_as_is = 0; + status = cat_domain(name, channel->domains[0], &s); + if (status == ARES_SUCCESS) + { + ares_query(channel, s, dnsclass, type, search_callback, squery); + free(s); + } + else + { + /* failed, free the malloc()ed memory */ + free(squery->name); + free(squery); + callback(arg, status, 0, NULL, 0); + } + } +} + +static void search_callback(void *arg, int status, int timeouts, + unsigned char *abuf, int alen) +{ + struct search_query *squery = (struct search_query *) arg; + ares_channel channel = squery->channel; + char *s; + + squery->timeouts += timeouts; + + /* Stop searching unless we got a non-fatal error. */ + if (status != ARES_ENODATA && status != ARES_ESERVFAIL + && status != ARES_ENOTFOUND) + end_squery(squery, status, abuf, alen); + else + { + /* Save the status if we were trying as-is. */ + if (squery->trying_as_is) + squery->status_as_is = status; + + /* + * If we ever get ARES_ENODATA along the way, record that; if the search + * should run to the very end and we got at least one ARES_ENODATA, + * then callers like ares_gethostbyname() may want to try a T_A search + * even if the last domain we queried for T_AAAA resource records + * returned ARES_ENOTFOUND. + */ + if (status == ARES_ENODATA) + squery->ever_got_nodata = 1; + + if (squery->next_domain < channel->ndomains) + { + /* Try the next domain. */ + status = cat_domain(squery->name, + channel->domains[squery->next_domain], &s); + if (status != ARES_SUCCESS) + end_squery(squery, status, NULL, 0); + else + { + squery->trying_as_is = 0; + squery->next_domain++; + ares_query(channel, s, squery->dnsclass, squery->type, + search_callback, squery); + free(s); + } + } + else if (squery->status_as_is == -1) + { + /* Try the name as-is at the end. */ + squery->trying_as_is = 1; + ares_query(channel, squery->name, squery->dnsclass, squery->type, + search_callback, squery); + } + else { + if (squery->status_as_is == ARES_ENOTFOUND && squery->ever_got_nodata) { + end_squery(squery, ARES_ENODATA, NULL, 0); + } + else + end_squery(squery, squery->status_as_is, NULL, 0); + } + } +} + +static void end_squery(struct search_query *squery, int status, + unsigned char *abuf, int alen) +{ + squery->callback(squery->arg, status, squery->timeouts, abuf, alen); + free(squery->name); + free(squery); +} + +/* Concatenate two domains. */ +static int cat_domain(const char *name, const char *domain, char **s) +{ + size_t nlen = strlen(name); + size_t dlen = strlen(domain); + + *s = malloc(nlen + 1 + dlen + 1); + if (!*s) + return ARES_ENOMEM; + memcpy(*s, name, nlen); + (*s)[nlen] = '.'; + memcpy(*s + nlen + 1, domain, dlen); + (*s)[nlen + 1 + dlen] = 0; + return ARES_SUCCESS; +} + +/* Determine if this name only yields one query. If it does, set *s to + * the string we should query, in an allocated buffer. If not, set *s + * to NULL. + */ +static int single_domain(ares_channel channel, const char *name, char **s) +{ + size_t len = strlen(name); + const char *hostaliases; + FILE *fp; + char *line = NULL; + int status; + size_t linesize; + const char *p, *q; + int error; + + /* If the name contains a trailing dot, then the single query is the name + * sans the trailing dot. + */ + if (name[len - 1] == '.') + { + *s = strdup(name); + return (*s) ? ARES_SUCCESS : ARES_ENOMEM; + } + + if (!(channel->flags & ARES_FLAG_NOALIASES) && !strchr(name, '.')) + { + /* The name might be a host alias. */ + hostaliases = getenv("HOSTALIASES"); + if (hostaliases) + { + fp = fopen(hostaliases, "r"); + if (fp) + { + while ((status = ares__read_line(fp, &line, &linesize)) + == ARES_SUCCESS) + { + if (strncasecmp(line, name, len) != 0 || + !ISSPACE(line[len])) + continue; + p = line + len; + while (ISSPACE(*p)) + p++; + if (*p) + { + q = p + 1; + while (*q && !ISSPACE(*q)) + q++; + *s = malloc(q - p + 1); + if (*s) + { + memcpy(*s, p, q - p); + (*s)[q - p] = 0; + } + free(line); + fclose(fp); + return (*s) ? ARES_SUCCESS : ARES_ENOMEM; + } + } + free(line); + fclose(fp); + if (status != ARES_SUCCESS && status != ARES_EOF) + return status; + } + else + { + error = errno; + switch(error) + { + case ENOENT: + case ESRCH: + break; + default: + DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n", + error, strerror(error))); + DEBUGF(fprintf(stderr, "Error opening file: %s\n", + hostaliases)); + *s = NULL; + return ARES_EFILE; + } + } + } + } + + if (channel->flags & ARES_FLAG_NOSEARCH || channel->ndomains == 0) + { + /* No domain search to do; just try the name as-is. */ + *s = strdup(name); + return (*s) ? ARES_SUCCESS : ARES_ENOMEM; + } + + *s = NULL; + return ARES_SUCCESS; +} diff --git a/src/rt/libuv/src/ares/ares_send.c b/src/rt/libuv/src/ares/ares_send.c new file mode 100644 index 00000000000..9f24d339a8a --- /dev/null +++ b/src/rt/libuv/src/ares/ares_send.c @@ -0,0 +1,134 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include +#include "ares.h" +#include "ares_dns.h" +#include "ares_private.h" + +void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen, + ares_callback callback, void *arg) +{ + struct query *query; + int i; + struct timeval now; + + /* Verify that the query is at least long enough to hold the header. */ + if (qlen < HFIXEDSZ || qlen >= (1 << 16)) + { + callback(arg, ARES_EBADQUERY, 0, NULL, 0); + return; + } + + /* Allocate space for query and allocated fields. */ + query = malloc(sizeof(struct query)); + if (!query) + { + callback(arg, ARES_ENOMEM, 0, NULL, 0); + return; + } + query->tcpbuf = malloc(qlen + 2); + if (!query->tcpbuf) + { + free(query); + callback(arg, ARES_ENOMEM, 0, NULL, 0); + return; + } + query->server_info = malloc(channel->nservers * + sizeof(query->server_info[0])); + if (!query->server_info) + { + free(query->tcpbuf); + free(query); + callback(arg, ARES_ENOMEM, 0, NULL, 0); + return; + } + + /* Compute the query ID. Start with no timeout. */ + query->qid = (unsigned short)DNS_HEADER_QID(qbuf); + query->timeout.tv_sec = 0; + query->timeout.tv_usec = 0; + + /* Form the TCP query buffer by prepending qlen (as two + * network-order bytes) to qbuf. + */ + query->tcpbuf[0] = (unsigned char)((qlen >> 8) & 0xff); + query->tcpbuf[1] = (unsigned char)(qlen & 0xff); + memcpy(query->tcpbuf + 2, qbuf, qlen); + query->tcplen = qlen + 2; + + /* Fill in query arguments. */ + query->qbuf = query->tcpbuf + 2; + query->qlen = qlen; + query->callback = callback; + query->arg = arg; + + /* Initialize query status. */ + query->try = 0; + + /* Choose the server to send the query to. If rotation is enabled, keep track + * of the next server we want to use. */ + query->server = channel->last_server; + if (channel->rotate == 1) + channel->last_server = (channel->last_server + 1) % channel->nservers; + + for (i = 0; i < channel->nservers; i++) + { + query->server_info[i].skip_server = 0; + query->server_info[i].tcp_connection_generation = 0; + } + query->using_tcp = (channel->flags & ARES_FLAG_USEVC) || qlen > PACKETSZ; + query->error_status = ARES_ECONNREFUSED; + query->timeouts = 0; + + /* Initialize our list nodes. */ + ares__init_list_node(&(query->queries_by_qid), query); + ares__init_list_node(&(query->queries_by_timeout), query); + ares__init_list_node(&(query->queries_to_server), query); + ares__init_list_node(&(query->all_queries), query); + + /* Chain the query into the list of all queries. */ + ares__insert_in_list(&(query->all_queries), &(channel->all_queries)); + /* Keep track of queries bucketed by qid, so we can process DNS + * responses quickly. + */ + ares__insert_in_list( + &(query->queries_by_qid), + &(channel->queries_by_qid[query->qid % ARES_QID_TABLE_SIZE])); + + /* Perform the first query action. */ + now = ares__tvnow(); + ares__send_query(channel, query, &now); +} diff --git a/src/rt/libuv/src/ares/ares_setup.h b/src/rt/libuv/src/ares/ares_setup.h new file mode 100644 index 00000000000..9cec52af76e --- /dev/null +++ b/src/rt/libuv/src/ares/ares_setup.h @@ -0,0 +1,191 @@ +#ifndef HEADER_CARES_SETUP_H +#define HEADER_CARES_SETUP_H + +/* $Id$ */ + +/* Copyright (C) 2004 - 2009 by Daniel Stenberg et al + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +/* + * Define WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) +#define WIN32 +#endif + +/* + * Include configuration script results or hand-crafted + * configuration file for platforms which lack config tool. + */ + +#ifdef HAVE_CONFIG_H +#include "ares_config.h" +#endif /* HAVE_CONFIG_H */ + +/* ================================================================ */ +/* Definition of preprocessor macros/symbols which modify compiler */ +/* behaviour or generated code characteristics must be done here, */ +/* as appropriate, before any system header file is included. It is */ +/* also possible to have them defined in the config file included */ +/* before this point. As a result of all this we frown inclusion of */ +/* system header files in our config files, avoid this at any cost. */ +/* ================================================================ */ + +/* + * AIX 4.3 and newer needs _THREAD_SAFE defined to build + * proper reentrant code. Others may also need it. + */ + +#ifdef NEED_THREAD_SAFE +# ifndef _THREAD_SAFE +# define _THREAD_SAFE +# endif +#endif + +/* + * Tru64 needs _REENTRANT set for a few function prototypes and + * things to appear in the system header files. Unixware needs it + * to build proper reentrant code. Others may also need it. + */ + +#ifdef NEED_REENTRANT +# ifndef _REENTRANT +# define _REENTRANT +# endif +#endif + +/* ================================================================ */ +/* If you need to include a system header file for your platform, */ +/* please, do it beyond the point further indicated in this file. */ +/* ================================================================ */ + +#if 0 /* libuv disabled */ +/* + * c-ares external interface definitions are also used internally, + * and might also include required system header files to define them. + */ + +#include + +/* + * Compile time sanity checks must also be done when building the library. + */ + +#include +#endif + +/* ================================================================= */ +/* No system header file shall be included in this file before this */ +/* point. The only allowed ones are those included from ares_build.h */ +/* ================================================================= */ + +/* + * Include header files for windows builds before redefining anything. + * Use this preproessor block only to include or exclude windows.h, + * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs + * to any other further and independent block. Under Cygwin things work + * just as under linux (e.g. ) and the winsock headers should + * never be included when __CYGWIN__ is defined. configure script takes + * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H, + * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined. + */ + +#ifdef HAVE_WINDOWS_H +# ifdef HAVE_WINSOCK2_H +# include +# ifdef HAVE_WS2TCPIP_H +# include +# endif +# else +# ifdef HAVE_WINSOCK_H +# include +# endif +# endif +# include +#endif + +/* + * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else + * define USE_WINSOCK to 1 if we have and use WINSOCK API, else + * undefine USE_WINSOCK. + */ + +#undef USE_WINSOCK + +#ifdef HAVE_WINSOCK2_H +# define USE_WINSOCK 2 +#else +# ifdef HAVE_WINSOCK_H +# define USE_WINSOCK 1 +# endif +#endif + +/* + * Work-arounds for systems without configure support + */ + +#ifndef HAVE_CONFIG_H + +#if !defined(HAVE_SYS_TIME_H) && !defined(_MSC_VER) && !defined(__WATCOMC__) +#define HAVE_SYS_TIME_H +#endif + +#if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) +#define HAVE_UNISTD_H 1 +#endif + +#if !defined(HAVE_SYS_UIO_H) && !defined(WIN32) && !defined(MSDOS) +#define HAVE_SYS_UIO_H +#endif + +#endif /* HAVE_CONFIG_H */ + +#ifdef __POCC__ +# include +# include +# define ESRCH 3 +#endif + +/* + * Recent autoconf versions define these symbols in ares_config.h. We don't + * want them (since they collide with the libcurl ones when we build + * --enable-debug) so we undef them again here. + */ + +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef VERSION +#undef PACKAGE + +/* IPv6 compatibility */ +#if !defined(HAVE_AF_INET6) +#if defined(HAVE_PF_INET6) +#define AF_INET6 PF_INET6 +#else +#define AF_INET6 AF_MAX+1 +#endif +#endif + +/* + * Include macros and defines that should only be processed once. + */ + +#ifndef __SETUP_ONCE_H +#include "setup_once.h" +#endif + +#endif /* HEADER_CARES_SETUP_H */ diff --git a/src/rt/libuv/src/ares/ares_strcasecmp.c b/src/rt/libuv/src/ares/ares_strcasecmp.c new file mode 100644 index 00000000000..f9c85e20966 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_strcasecmp.c @@ -0,0 +1,66 @@ + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include "ares_strcasecmp.h" + +#ifndef HAVE_STRCASECMP +int ares_strcasecmp(const char *a, const char *b) +{ +#if defined(HAVE_STRCMPI) + return strcmpi(a, b); +#elif defined(HAVE_STRICMP) + return stricmp(a, b); +#else + size_t i; + + for (i = 0; i < (size_t)-1; i++) { + int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i]; + int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i]; + if (c1 != c2) + return c1-c2; + if (!c1) + break; + } + return 0; +#endif +} +#endif + +#ifndef HAVE_STRNCASECMP +int ares_strncasecmp(const char *a, const char *b, size_t n) +{ +#if defined(HAVE_STRNCMPI) + return strncmpi(a, b, n); +#elif defined(HAVE_STRNICMP) + return strnicmp(a, b, n); +#else + size_t i; + + for (i = 0; i < n; i++) { + int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i]; + int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i]; + if (c1 != c2) + return c1-c2; + if (!c1) + break; + } + return 0; +#endif +} +#endif + diff --git a/src/rt/libuv/src/ares/ares_strcasecmp.h b/src/rt/libuv/src/ares/ares_strcasecmp.h new file mode 100644 index 00000000000..57d86f96342 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_strcasecmp.h @@ -0,0 +1,30 @@ +#ifndef HEADER_CARES_STRCASECMP_H +#define HEADER_CARES_STRCASECMP_H + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifndef HAVE_STRCASECMP +extern int ares_strcasecmp(const char *a, const char *b); +#endif + +#ifndef HAVE_STRNCASECMP +extern int ares_strncasecmp(const char *a, const char *b, size_t n); +#endif + +#endif /* HEADER_CARES_STRCASECMP_H */ diff --git a/src/rt/libuv/src/ares/ares_strdup.c b/src/rt/libuv/src/ares/ares_strdup.c new file mode 100644 index 00000000000..18043274e99 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_strdup.c @@ -0,0 +1,42 @@ + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include "ares_strdup.h" + +#ifndef HAVE_STRDUP +char *ares_strdup(const char *s1) +{ + size_t sz; + char * s2; + + if(s1) { + sz = strlen(s1); + if(sz < (size_t)-1) { + sz++; + if(sz < ((size_t)-1) / sizeof(char)) { + s2 = malloc(sz * sizeof(char)); + if(s2) { + memcpy(s2, s1, sz * sizeof(char)); + return s2; + } + } + } + } + return (char *)NULL; +} +#endif diff --git a/src/rt/libuv/src/ares/ares_strdup.h b/src/rt/libuv/src/ares/ares_strdup.h new file mode 100644 index 00000000000..c413a941c51 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_strdup.h @@ -0,0 +1,26 @@ +#ifndef HEADER_CARES_STRDUP_H +#define HEADER_CARES_STRDUP_H + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifndef HAVE_STRDUP +extern char *ares_strdup(const char *s1); +#endif + +#endif /* HEADER_CARES_STRDUP_H */ diff --git a/src/rt/libuv/src/ares/ares_strerror.c b/src/rt/libuv/src/ares/ares_strerror.c new file mode 100644 index 00000000000..c3ecbd7b43c --- /dev/null +++ b/src/rt/libuv/src/ares/ares_strerror.c @@ -0,0 +1,56 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include +#include "ares.h" + +const char *ares_strerror(int code) +{ + /* Return a string literal from a table. */ + const char *errtext[] = { + "Successful completion", + "DNS server returned answer with no data", + "DNS server claims query was misformatted", + "DNS server returned general failure", + "Domain name not found", + "DNS server does not implement requested operation", + "DNS server refused query", + "Misformatted DNS query", + "Misformatted domain name", + "Unsupported address family", + "Misformatted DNS reply", + "Could not contact DNS servers", + "Timeout while contacting DNS servers", + "End of file", + "Error reading file", + "Out of memory", + "Channel is being destroyed", + "Misformatted string", + "Illegal flags specified", + "Given hostname is not numeric", + "Illegal hints flags specified", + "c-ares library initialization not yet performed", + "Error loading iphlpapi.dll", + "Could not find GetNetworkParams function", + "DNS query cancelled" + }; + + if(code >= 0 && code < (int)(sizeof(errtext) / sizeof(*errtext))) + return errtext[code]; + else + return "unknown"; +} diff --git a/src/rt/libuv/src/ares/ares_timeout.c b/src/rt/libuv/src/ares/ares_timeout.c new file mode 100644 index 00000000000..2da4f5f4a18 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_timeout.c @@ -0,0 +1,80 @@ + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#include + +#include "ares.h" +#include "ares_private.h" + +/* WARNING: Beware that this is linear in the number of outstanding + * requests! You are probably far better off just calling ares_process() + * once per second, rather than calling ares_timeout() to figure out + * when to next call ares_process(). + */ +struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv, + struct timeval *tvbuf) +{ + struct query *query; + struct list_node* list_head; + struct list_node* list_node; + struct timeval now; + struct timeval nextstop; + long offset, min_offset; + + /* No queries, no timeout (and no fetch of the current time). */ + if (ares__is_list_empty(&(channel->all_queries))) + return maxtv; + + /* Find the minimum timeout for the current set of queries. */ + now = ares__tvnow(); + min_offset = -1; + + list_head = &(channel->all_queries); + for (list_node = list_head->next; list_node != list_head; + list_node = list_node->next) + { + query = list_node->data; + if (query->timeout.tv_sec == 0) + continue; + offset = ares__timeoffset(&now, &query->timeout); + if (offset < 0) + offset = 0; + if (min_offset == -1 || offset < min_offset) + min_offset = offset; + } + + if(min_offset != -1) { + nextstop.tv_sec = min_offset/1000; + nextstop.tv_usec = (min_offset%1000)*1000; + } + + /* If we found a minimum timeout and it's sooner than the one specified in + * maxtv (if any), return it. Otherwise go with maxtv. + */ + if (min_offset != -1 && (!maxtv || ares__timedout(maxtv, &nextstop))) + { + *tvbuf = nextstop; + return tvbuf; + } + else + return maxtv; +} diff --git a/src/rt/libuv/src/ares/ares_version.c b/src/rt/libuv/src/ares/ares_version.c new file mode 100644 index 00000000000..4f8c42f2c9a --- /dev/null +++ b/src/rt/libuv/src/ares/ares_version.c @@ -0,0 +1,11 @@ + +#include "ares_setup.h" +#include "ares.h" + +const char *ares_version(int *version) +{ + if(version) + *version = ARES_VERSION; + + return ARES_VERSION_STR; +} diff --git a/src/rt/libuv/src/ares/ares_writev.c b/src/rt/libuv/src/ares/ares_writev.c new file mode 100644 index 00000000000..9e8e2d65741 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_writev.c @@ -0,0 +1,79 @@ + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" + +#ifdef HAVE_LIMITS_H +# include +#endif + +#include "ares.h" +#include "ares_private.h" + +#ifndef HAVE_WRITEV +ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt) +{ + char *buffer, *bp; + int i; + size_t bytes = 0; + ssize_t result; + + /* Validate iovcnt */ + if (iovcnt <= 0) + { + SET_ERRNO(EINVAL); + return (-1); + } + + /* Validate and find the sum of the iov_len values in the iov array */ + for (i = 0; i < iovcnt; i++) + { + if (iov[i].iov_len > INT_MAX - bytes) + { + SET_ERRNO(EINVAL); + return (-1); + } + bytes += iov[i].iov_len; + } + + if (bytes == 0) + return (0); + + /* Allocate a temporary buffer to hold the data */ + buffer = malloc(bytes); + if (!buffer) + { + SET_ERRNO(ENOMEM); + return (-1); + } + + /* Copy the data into buffer */ + for (bp = buffer, i = 0; i < iovcnt; ++i) + { + memcpy (bp, iov[i].iov_base, iov[i].iov_len); + bp += iov[i].iov_len; + } + + /* Send buffer contents */ + result = swrite(s, buffer, bytes); + + free(buffer); + + return (result); +} +#endif + diff --git a/src/rt/libuv/src/ares/ares_writev.h b/src/rt/libuv/src/ares/ares_writev.h new file mode 100644 index 00000000000..1a23a0f3d10 --- /dev/null +++ b/src/rt/libuv/src/ares/ares_writev.h @@ -0,0 +1,36 @@ +#ifndef HEADER_CARES_WRITEV_H +#define HEADER_CARES_WRITEV_H + + +/* Copyright 1998 by the Massachusetts Institute of Technology. + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#include "ares_setup.h" +#include "ares.h" + +#ifndef HAVE_WRITEV + +/* Structure for scatter/gather I/O. */ +struct iovec +{ + void *iov_base; /* Pointer to data. */ + size_t iov_len; /* Length of data. */ +}; + +extern ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt); + +#endif + +#endif /* HEADER_CARES_WRITEV_H */ diff --git a/src/rt/libuv/src/ares/bitncmp.c b/src/rt/libuv/src/ares/bitncmp.c new file mode 100644 index 00000000000..5c89506b33f --- /dev/null +++ b/src/rt/libuv/src/ares/bitncmp.c @@ -0,0 +1,59 @@ + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996,1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef HAVE_BITNCMP + +#include "ares_setup.h" +#include "bitncmp.h" + +/* + * int + * bitncmp(l, r, n) + * compare bit masks l and r, for n bits. + * return: + * -1, 1, or 0 in the libc tradition. + * note: + * network byte order assumed. this means 192.5.5.240/28 has + * 0x11110000 in its fourth octet. + * author: + * Paul Vixie (ISC), June 1996 + */ +int +ares_bitncmp(const void *l, const void *r, int n) { + unsigned int lb, rb; + int x, b; + + b = n / 8; + x = memcmp(l, r, b); + if (x || (n % 8) == 0) + return (x); + + lb = ((const unsigned char *)l)[b]; + rb = ((const unsigned char *)r)[b]; + for (b = n % 8; b > 0; b--) { + if ((lb & 0x80) != (rb & 0x80)) { + if (lb & 0x80) + return (1); + return (-1); + } + lb <<= 1; + rb <<= 1; + } + return (0); +} +#endif diff --git a/src/rt/libuv/src/ares/bitncmp.h b/src/rt/libuv/src/ares/bitncmp.h new file mode 100644 index 00000000000..b0a5c812b42 --- /dev/null +++ b/src/rt/libuv/src/ares/bitncmp.h @@ -0,0 +1,26 @@ +#ifndef __ARES_BITNCMP_H +#define __ARES_BITNCMP_H + + +/* Copyright (C) 2005 by Dominick Meglio + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#ifndef HAVE_BITNCMP +int ares_bitncmp(const void *l, const void *r, int n); +#else +#define ares_bitncmp(x,y,z) bitncmp(x,y,z) +#endif + +#endif /* __ARES_BITNCMP_H */ diff --git a/src/rt/libuv/src/ares/config_cygwin/ares_config.h b/src/rt/libuv/src/ares/config_cygwin/ares_config.h new file mode 100644 index 00000000000..70595d36175 --- /dev/null +++ b/src/rt/libuv/src/ares/config_cygwin/ares_config.h @@ -0,0 +1,510 @@ +/* ares_config.h. Generated from ares_config.h.in by configure. */ +/* ares_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* define this if ares is built for a big endian system */ +/* #undef ARES_BIG_ENDIAN */ + +/* when building as static part of libcurl */ +/* #undef BUILDING_LIBCURL */ + +/* when building c-ares library */ +/* #undef CARES_BUILDING_LIBRARY */ + +/* when not building a shared library */ +/* #undef CARES_STATICLIB */ + +/* Define to 1 to enable hiding of library internal symbols. */ +#define CARES_SYMBOL_HIDING 1 + +/* Definition to make a library symbol externally visible. */ +#define CARES_SYMBOL_SCOPE_EXTERN __attribute__ ((visibility ("default"))) + +/* if a /etc/inet dir is being used */ +/* #undef ETC_INET */ + +/* Define to the type qualifier of arg 1 for getnameinfo. */ +#define GETNAMEINFO_QUAL_ARG1 const + +/* Define to the type of arg 1 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * + +/* Define to the type of arg 2 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG2 socklen_t + +/* Define to the type of args 4 and 6 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG46 int + +/* Define to the type of arg 7 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG7 int + +/* Specifies the number of arguments to getservbyport_r */ +/* #undef GETSERVBYPORT_R_ARGS */ + +/* Specifies the size of the buffer to pass to getservbyport_r */ +/* #undef GETSERVBYPORT_R_BUFSIZE */ + +/* Define to 1 if you have AF_INET6. */ +#define HAVE_AF_INET6 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_COMPAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bitncmp' function. */ +/* #undef HAVE_BITNCMP */ + +/* Define to 1 if bool is an available type. */ +#define HAVE_BOOL_T 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +/* #undef HAVE_CLOCK_GETTIME_MONOTONIC */ + +/* Define to 1 if you have the closesocket function. */ +/* #undef HAVE_CLOSESOCKET */ + +/* Define to 1 if you have the CloseSocket camel case function. */ +/* #undef HAVE_CLOSESOCKET_CAMEL */ + +/* Define to 1 if you have the connect function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the fcntl function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#define HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +/* #undef HAVE_GETADDRINFO_THREADSAFE */ + +/* Define to 1 if you have the gethostbyaddr function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the gethostbyname function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the getnameinfo function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the getservbyport_r function. */ +/* #undef HAVE_GETSERVBYPORT_R */ + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `inet_net_pton' function. */ +/* #undef HAVE_INET_NET_PTON */ + +/* Define to 1 if inet_net_pton supports IPv6. */ +/* #undef HAVE_INET_NET_PTON_IPV6 */ + +/* Define to 1 if you have a IPv6 capable working inet_ntop function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have a IPv6 capable working inet_pton function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the ioctl function. */ +#define HAVE_IOCTL 1 + +/* Define to 1 if you have the ioctlsocket function. */ +/* #undef HAVE_IOCTLSOCKET */ + +/* Define to 1 if you have the IoctlSocket camel case function. */ +/* #undef HAVE_IOCTLSOCKET_CAMEL */ + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */ + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +/* #undef HAVE_IOCTLSOCKET_FIONBIO */ + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +#define HAVE_IOCTL_FIONBIO 1 + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +#define HAVE_IOCTL_SIOCGIFADDR 1 + +/* Define to 1 if you have the `resolve' library (-lresolve). */ +/* #undef HAVE_LIBRESOLVE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* if your compiler supports LL */ +#define HAVE_LL 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#define HAVE_LONGLONG 1 + +/* Define to 1 if you have the malloc.h header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the memory.h header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +#define HAVE_MSG_NOSIGNAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have PF_INET6. */ +#define HAVE_PF_INET6 1 + +/* Define to 1 if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to 1 if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to 1 if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to 1 if you have the setsockopt function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if sig_atomic_t is already defined as volatile. */ +/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */ + +/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */ +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the socket function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +/* #undef HAVE_STRCMPI */ + +/* Define to 1 if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the stricmp function. */ +/* #undef HAVE_STRICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the strncasecmp function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the strncmpi function. */ +/* #undef HAVE_STRNCMPI */ + +/* Define to 1 if you have the strnicmp function. */ +/* #undef HAVE_STRNICMP */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STROPTS_H */ + +/* Define to 1 if you have struct addrinfo. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if you have struct in6_addr. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if you have struct sockaddr_in6. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* if struct sockaddr_storage is defined */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the windows.h header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the winsock2.h header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define to 1 if you have the winsock.h header file. */ +/* #undef HAVE_WINSOCK_H */ + +/* Define to 1 if you have the writev function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the ws2tcpip.h header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if you are building a native Windows target. */ +/* #undef NATIVE_WINDOWS */ + +/* Define to 1 if you need the malloc.h header file even with stdlib.h */ +/* #undef NEED_MALLOC_H */ + +/* Define to 1 if you need the memory.h header file even with stdlib.h */ +/* #undef NEED_MEMORY_H */ + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +/* #undef NEED_REENTRANT */ + +/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */ +/* #undef NEED_THREAD_SAFE */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* cpu-machine-OS */ +#define OS "i686-pc-cygwin" + +/* Name of package */ +#define PACKAGE "c-ares" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "c-ares" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "c-ares 1.7.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-ares" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.7.1" + +/* a suitable file/device to read random data from */ +#define RANDOM_FILE "/dev/urandom" + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 int + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 void + +/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG2_IS_VOID 1 + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG5_IS_VOID */ + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 socklen_t + +/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG6_IS_VOID */ + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV int + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 int + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 void * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV int + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 int + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 void * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV int + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 4 + +/* The size of `struct in6_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN6_ADDR 16 + +/* The size of `struct in_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN_ADDR 4 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to disable non-blocking sockets. */ +/* #undef USE_BLOCKING_SOCKETS */ + +/* Version number of package */ +#define VERSION "1.7.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to 1 if OS is AIX. */ +#ifndef _ALL_SOURCE +/* # undef _ALL_SOURCE */ +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Type to use in place of in_addr_t when system does not provide it. */ +/* #undef in_addr_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* the signed version of size_t */ +/* #undef ssize_t */ diff --git a/src/rt/libuv/src/ares/config_darwin/ares_config.h b/src/rt/libuv/src/ares/config_darwin/ares_config.h new file mode 100644 index 00000000000..3722bba10b5 --- /dev/null +++ b/src/rt/libuv/src/ares/config_darwin/ares_config.h @@ -0,0 +1,510 @@ +/* ares_config.h. Generated from ares_config.h.in by configure. */ +/* ares_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* define this if ares is built for a big endian system */ +/* #undef ARES_BIG_ENDIAN */ + +/* when building as static part of libcurl */ +/* #undef BUILDING_LIBCURL */ + +/* when building c-ares library */ +/* #undef CARES_BUILDING_LIBRARY */ + +/* when not building a shared library */ +/* #undef CARES_STATICLIB */ + +/* Define to 1 to enable hiding of library internal symbols. */ +#define CARES_SYMBOL_HIDING 1 + +/* Definition to make a library symbol externally visible. */ +#define CARES_SYMBOL_SCOPE_EXTERN __attribute__ ((visibility ("default"))) + +/* if a /etc/inet dir is being used */ +/* #undef ETC_INET */ + +/* Define to the type qualifier of arg 1 for getnameinfo. */ +#define GETNAMEINFO_QUAL_ARG1 const + +/* Define to the type of arg 1 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * + +/* Define to the type of arg 2 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG2 socklen_t + +/* Define to the type of args 4 and 6 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG46 socklen_t + +/* Define to the type of arg 7 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG7 int + +/* Specifies the number of arguments to getservbyport_r */ +/* #undef GETSERVBYPORT_R_ARGS */ + +/* Specifies the size of the buffer to pass to getservbyport_r */ +/* #undef GETSERVBYPORT_R_BUFSIZE */ + +/* Define to 1 if you have AF_INET6. */ +#define HAVE_AF_INET6 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_COMPAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bitncmp' function. */ +/* #undef HAVE_BITNCMP */ + +/* Define to 1 if bool is an available type. */ +#define HAVE_BOOL_T 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +/* #undef HAVE_CLOCK_GETTIME_MONOTONIC */ + +/* Define to 1 if you have the closesocket function. */ +/* #undef HAVE_CLOSESOCKET */ + +/* Define to 1 if you have the CloseSocket camel case function. */ +/* #undef HAVE_CLOSESOCKET_CAMEL */ + +/* Define to 1 if you have the connect function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the fcntl function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#define HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +#define HAVE_GETADDRINFO_THREADSAFE 1 + +/* Define to 1 if you have the gethostbyaddr function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the gethostbyname function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the getnameinfo function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the getservbyport_r function. */ +/* #undef HAVE_GETSERVBYPORT_R */ + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `inet_net_pton' function. */ +#define HAVE_INET_NET_PTON 1 + +/* Define to 1 if inet_net_pton supports IPv6. */ +#define HAVE_INET_NET_PTON_IPV6 1 + +/* Define to 1 if you have a IPv6 capable working inet_ntop function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have a IPv6 capable working inet_pton function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the ioctl function. */ +#define HAVE_IOCTL 1 + +/* Define to 1 if you have the ioctlsocket function. */ +/* #undef HAVE_IOCTLSOCKET */ + +/* Define to 1 if you have the IoctlSocket camel case function. */ +/* #undef HAVE_IOCTLSOCKET_CAMEL */ + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */ + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +/* #undef HAVE_IOCTLSOCKET_FIONBIO */ + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +#define HAVE_IOCTL_FIONBIO 1 + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +#define HAVE_IOCTL_SIOCGIFADDR 1 + +/* Define to 1 if you have the `resolve' library (-lresolve). */ +/* #undef HAVE_LIBRESOLVE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* if your compiler supports LL */ +#define HAVE_LL 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#define HAVE_LONGLONG 1 + +/* Define to 1 if you have the malloc.h header file. */ +/* #undef HAVE_MALLOC_H */ + +/* Define to 1 if you have the memory.h header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +/* #undef HAVE_MSG_NOSIGNAL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have PF_INET6. */ +#define HAVE_PF_INET6 1 + +/* Define to 1 if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to 1 if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to 1 if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to 1 if you have the setsockopt function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if sig_atomic_t is already defined as volatile. */ +/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */ + +/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */ +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the socket function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +/* #undef HAVE_STRCMPI */ + +/* Define to 1 if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the stricmp function. */ +/* #undef HAVE_STRICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the strncasecmp function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the strncmpi function. */ +/* #undef HAVE_STRNCMPI */ + +/* Define to 1 if you have the strnicmp function. */ +/* #undef HAVE_STRNICMP */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STROPTS_H */ + +/* Define to 1 if you have struct addrinfo. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if you have struct in6_addr. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if you have struct sockaddr_in6. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* if struct sockaddr_storage is defined */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the windows.h header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the winsock2.h header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define to 1 if you have the winsock.h header file. */ +/* #undef HAVE_WINSOCK_H */ + +/* Define to 1 if you have the writev function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the ws2tcpip.h header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if you are building a native Windows target. */ +/* #undef NATIVE_WINDOWS */ + +/* Define to 1 if you need the malloc.h header file even with stdlib.h */ +/* #undef NEED_MALLOC_H */ + +/* Define to 1 if you need the memory.h header file even with stdlib.h */ +/* #undef NEED_MEMORY_H */ + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +/* #undef NEED_REENTRANT */ + +/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */ +/* #undef NEED_THREAD_SAFE */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* cpu-machine-OS */ +#define OS "i386-apple-darwin9.8.0" + +/* Name of package */ +#define PACKAGE "c-ares" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "c-ares" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "c-ares 1.7.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-ares" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.7.1" + +/* a suitable file/device to read random data from */ +#define RANDOM_FILE "/dev/urandom" + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 int + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 void + +/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG2_IS_VOID 1 + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG5_IS_VOID */ + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 socklen_t + +/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG6_IS_VOID */ + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV ssize_t + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 int + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 void * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV ssize_t + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 int + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 void * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV ssize_t + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 4 + +/* The size of `struct in6_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN6_ADDR 16 + +/* The size of `struct in_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN_ADDR 4 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to disable non-blocking sockets. */ +/* #undef USE_BLOCKING_SOCKETS */ + +/* Version number of package */ +#define VERSION "1.7.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to 1 if OS is AIX. */ +#ifndef _ALL_SOURCE +/* # undef _ALL_SOURCE */ +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Type to use in place of in_addr_t when system does not provide it. */ +/* #undef in_addr_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* the signed version of size_t */ +/* #undef ssize_t */ diff --git a/src/rt/libuv/src/ares/config_freebsd/ares_config.h b/src/rt/libuv/src/ares/config_freebsd/ares_config.h new file mode 100644 index 00000000000..4164edb3e25 --- /dev/null +++ b/src/rt/libuv/src/ares/config_freebsd/ares_config.h @@ -0,0 +1,510 @@ +/* ares_config.h. Generated from ares_config.h.in by configure. */ +/* ares_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* define this if ares is built for a big endian system */ +/* #undef ARES_BIG_ENDIAN */ + +/* when building as static part of libcurl */ +/* #undef BUILDING_LIBCURL */ + +/* when building c-ares library */ +/* #undef CARES_BUILDING_LIBRARY */ + +/* when not building a shared library */ +/* #undef CARES_STATICLIB */ + +/* Define to 1 to enable hiding of library internal symbols. */ +#define CARES_SYMBOL_HIDING 1 + +/* Definition to make a library symbol externally visible. */ +#define CARES_SYMBOL_SCOPE_EXTERN __attribute__ ((visibility ("default"))) + +/* if a /etc/inet dir is being used */ +/* #undef ETC_INET */ + +/* Define to the type qualifier of arg 1 for getnameinfo. */ +#define GETNAMEINFO_QUAL_ARG1 const + +/* Define to the type of arg 1 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * + +/* Define to the type of arg 2 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG2 socklen_t + +/* Define to the type of args 4 and 6 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG46 size_t + +/* Define to the type of arg 7 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG7 int + +/* Specifies the number of arguments to getservbyport_r */ +#define GETSERVBYPORT_R_ARGS 6 + +/* Specifies the size of the buffer to pass to getservbyport_r */ +#define GETSERVBYPORT_R_BUFSIZE 4096 + +/* Define to 1 if you have AF_INET6. */ +#define HAVE_AF_INET6 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_COMPAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bitncmp' function. */ +/* #undef HAVE_BITNCMP */ + +/* Define to 1 if bool is an available type. */ +#define HAVE_BOOL_T 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +#define HAVE_CLOCK_GETTIME_MONOTONIC 1 + +/* Define to 1 if you have the closesocket function. */ +/* #undef HAVE_CLOSESOCKET */ + +/* Define to 1 if you have the CloseSocket camel case function. */ +/* #undef HAVE_CLOSESOCKET_CAMEL */ + +/* Define to 1 if you have the connect function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the fcntl function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#define HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +#define HAVE_GETADDRINFO_THREADSAFE 1 + +/* Define to 1 if you have the gethostbyaddr function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the gethostbyname function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the getnameinfo function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the getservbyport_r function. */ +#define HAVE_GETSERVBYPORT_R 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `inet_net_pton' function. */ +#define HAVE_INET_NET_PTON 1 + +/* Define to 1 if inet_net_pton supports IPv6. */ +/* #undef HAVE_INET_NET_PTON_IPV6 */ + +/* Define to 1 if you have a IPv6 capable working inet_ntop function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have a IPv6 capable working inet_pton function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the ioctl function. */ +#define HAVE_IOCTL 1 + +/* Define to 1 if you have the ioctlsocket function. */ +/* #undef HAVE_IOCTLSOCKET */ + +/* Define to 1 if you have the IoctlSocket camel case function. */ +/* #undef HAVE_IOCTLSOCKET_CAMEL */ + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */ + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +/* #undef HAVE_IOCTLSOCKET_FIONBIO */ + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +#define HAVE_IOCTL_FIONBIO 1 + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +#define HAVE_IOCTL_SIOCGIFADDR 1 + +/* Define to 1 if you have the `resolve' library (-lresolve). */ +/* #undef HAVE_LIBRESOLVE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* if your compiler supports LL */ +#define HAVE_LL 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#define HAVE_LONGLONG 1 + +/* Define to 1 if you have the malloc.h header file. */ +/* #undef HAVE_MALLOC_H */ + +/* Define to 1 if you have the memory.h header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +#define HAVE_MSG_NOSIGNAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have PF_INET6. */ +#define HAVE_PF_INET6 1 + +/* Define to 1 if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to 1 if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to 1 if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to 1 if you have the setsockopt function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if sig_atomic_t is already defined as volatile. */ +/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */ + +/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */ +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the socket function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +/* #undef HAVE_STRCMPI */ + +/* Define to 1 if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the stricmp function. */ +/* #undef HAVE_STRICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the strncasecmp function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the strncmpi function. */ +/* #undef HAVE_STRNCMPI */ + +/* Define to 1 if you have the strnicmp function. */ +/* #undef HAVE_STRNICMP */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STROPTS_H */ + +/* Define to 1 if you have struct addrinfo. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if you have struct in6_addr. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if you have struct sockaddr_in6. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* if struct sockaddr_storage is defined */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the windows.h header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the winsock2.h header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define to 1 if you have the winsock.h header file. */ +/* #undef HAVE_WINSOCK_H */ + +/* Define to 1 if you have the writev function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the ws2tcpip.h header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if you are building a native Windows target. */ +/* #undef NATIVE_WINDOWS */ + +/* Define to 1 if you need the malloc.h header file even with stdlib.h */ +/* #undef NEED_MALLOC_H */ + +/* Define to 1 if you need the memory.h header file even with stdlib.h */ +/* #undef NEED_MEMORY_H */ + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +/* #undef NEED_REENTRANT */ + +/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */ +/* #undef NEED_THREAD_SAFE */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* cpu-machine-OS */ +#define OS "i386-portbld-freebsd8.0" + +/* Name of package */ +#define PACKAGE "c-ares" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "c-ares" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "c-ares 1.7.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-ares" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.7.1" + +/* a suitable file/device to read random data from */ +#define RANDOM_FILE "/dev/urandom" + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 int + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 void + +/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG2_IS_VOID 1 + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG5_IS_VOID */ + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 socklen_t + +/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG6_IS_VOID */ + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV int + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 int + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 void * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV int + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 int + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 void * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV int + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 4 + +/* The size of `struct in6_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN6_ADDR 16 + +/* The size of `struct in_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN_ADDR 4 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to disable non-blocking sockets. */ +/* #undef USE_BLOCKING_SOCKETS */ + +/* Version number of package */ +#define VERSION "1.7.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to 1 if OS is AIX. */ +#ifndef _ALL_SOURCE +/* # undef _ALL_SOURCE */ +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Type to use in place of in_addr_t when system does not provide it. */ +/* #undef in_addr_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* the signed version of size_t */ +/* #undef ssize_t */ diff --git a/src/rt/libuv/src/ares/config_linux/ares_config.h b/src/rt/libuv/src/ares/config_linux/ares_config.h new file mode 100644 index 00000000000..dca6476eb53 --- /dev/null +++ b/src/rt/libuv/src/ares/config_linux/ares_config.h @@ -0,0 +1,510 @@ +/* ares_config.h. Generated from ares_config.h.in by configure. */ +/* ares_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* define this if ares is built for a big endian system */ +/* #undef ARES_BIG_ENDIAN */ + +/* when building as static part of libcurl */ +/* #undef BUILDING_LIBCURL */ + +/* when building c-ares library */ +/* #undef CARES_BUILDING_LIBRARY */ + +/* when not building a shared library */ +/* #undef CARES_STATICLIB */ + +/* Define to 1 to enable hiding of library internal symbols. */ +#define CARES_SYMBOL_HIDING 1 + +/* Definition to make a library symbol externally visible. */ +#define CARES_SYMBOL_SCOPE_EXTERN __attribute__ ((visibility ("default"))) + +/* if a /etc/inet dir is being used */ +/* #undef ETC_INET */ + +/* Define to the type qualifier of arg 1 for getnameinfo. */ +#define GETNAMEINFO_QUAL_ARG1 const + +/* Define to the type of arg 1 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * + +/* Define to the type of arg 2 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG2 socklen_t + +/* Define to the type of args 4 and 6 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG46 size_t + +/* Define to the type of arg 7 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG7 unsigned int + +/* Specifies the number of arguments to getservbyport_r */ +#define GETSERVBYPORT_R_ARGS 6 + +/* Specifies the size of the buffer to pass to getservbyport_r */ +#define GETSERVBYPORT_R_BUFSIZE 4096 + +/* Define to 1 if you have AF_INET6. */ +#define HAVE_AF_INET6 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_COMPAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bitncmp' function. */ +/* #undef HAVE_BITNCMP */ + +/* Define to 1 if bool is an available type. */ +#define HAVE_BOOL_T 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +#define HAVE_CLOCK_GETTIME_MONOTONIC 1 + +/* Define to 1 if you have the closesocket function. */ +/* #undef HAVE_CLOSESOCKET */ + +/* Define to 1 if you have the CloseSocket camel case function. */ +/* #undef HAVE_CLOSESOCKET_CAMEL */ + +/* Define to 1 if you have the connect function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the fcntl function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#define HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +#define HAVE_GETADDRINFO_THREADSAFE 1 + +/* Define to 1 if you have the gethostbyaddr function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the gethostbyname function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the getnameinfo function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the getservbyport_r function. */ +#define HAVE_GETSERVBYPORT_R 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `inet_net_pton' function. */ +/* #undef HAVE_INET_NET_PTON */ + +/* Define to 1 if inet_net_pton supports IPv6. */ +/* #undef HAVE_INET_NET_PTON_IPV6 */ + +/* Define to 1 if you have a IPv6 capable working inet_ntop function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have a IPv6 capable working inet_pton function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the ioctl function. */ +#define HAVE_IOCTL 1 + +/* Define to 1 if you have the ioctlsocket function. */ +/* #undef HAVE_IOCTLSOCKET */ + +/* Define to 1 if you have the IoctlSocket camel case function. */ +/* #undef HAVE_IOCTLSOCKET_CAMEL */ + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */ + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +/* #undef HAVE_IOCTLSOCKET_FIONBIO */ + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +#define HAVE_IOCTL_FIONBIO 1 + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +#define HAVE_IOCTL_SIOCGIFADDR 1 + +/* Define to 1 if you have the `resolve' library (-lresolve). */ +/* #undef HAVE_LIBRESOLVE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* if your compiler supports LL */ +#define HAVE_LL 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#define HAVE_LONGLONG 1 + +/* Define to 1 if you have the malloc.h header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the memory.h header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +#define HAVE_MSG_NOSIGNAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have PF_INET6. */ +#define HAVE_PF_INET6 1 + +/* Define to 1 if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to 1 if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to 1 if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to 1 if you have the setsockopt function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if sig_atomic_t is already defined as volatile. */ +/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */ + +/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */ +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the socket function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +/* #undef HAVE_STRCMPI */ + +/* Define to 1 if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the stricmp function. */ +/* #undef HAVE_STRICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the strncasecmp function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the strncmpi function. */ +/* #undef HAVE_STRNCMPI */ + +/* Define to 1 if you have the strnicmp function. */ +/* #undef HAVE_STRNICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STROPTS_H 1 + +/* Define to 1 if you have struct addrinfo. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if you have struct in6_addr. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if you have struct sockaddr_in6. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* if struct sockaddr_storage is defined */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the windows.h header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the winsock2.h header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define to 1 if you have the winsock.h header file. */ +/* #undef HAVE_WINSOCK_H */ + +/* Define to 1 if you have the writev function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the ws2tcpip.h header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if you are building a native Windows target. */ +/* #undef NATIVE_WINDOWS */ + +/* Define to 1 if you need the malloc.h header file even with stdlib.h */ +/* #undef NEED_MALLOC_H */ + +/* Define to 1 if you need the memory.h header file even with stdlib.h */ +/* #undef NEED_MEMORY_H */ + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +/* #undef NEED_REENTRANT */ + +/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */ +/* #undef NEED_THREAD_SAFE */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* cpu-machine-OS */ +#define OS "i686-pc-linux-gnu" + +/* Name of package */ +#define PACKAGE "c-ares" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "c-ares" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "c-ares 1.7.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-ares" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.7.1" + +/* a suitable file/device to read random data from */ +#define RANDOM_FILE "/dev/urandom" + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 int + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 void + +/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG2_IS_VOID 1 + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG5_IS_VOID */ + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 socklen_t + +/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG6_IS_VOID */ + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV int + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 int + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 void * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV int + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 int + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 void * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV int + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 4 + +/* The size of `struct in6_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN6_ADDR 16 + +/* The size of `struct in_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN_ADDR 4 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to disable non-blocking sockets. */ +/* #undef USE_BLOCKING_SOCKETS */ + +/* Version number of package */ +#define VERSION "1.7.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to 1 if OS is AIX. */ +#ifndef _ALL_SOURCE +/* # undef _ALL_SOURCE */ +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#define _FILE_OFFSET_BITS 64 + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Type to use in place of in_addr_t when system does not provide it. */ +/* #undef in_addr_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* the signed version of size_t */ +/* #undef ssize_t */ diff --git a/src/rt/libuv/src/ares/config_openbsd/ares_config.h b/src/rt/libuv/src/ares/config_openbsd/ares_config.h new file mode 100644 index 00000000000..5e3ae688645 --- /dev/null +++ b/src/rt/libuv/src/ares/config_openbsd/ares_config.h @@ -0,0 +1,510 @@ +/* ares_config.h. Generated from ares_config.h.in by configure. */ +/* ares_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* define this if ares is built for a big endian system */ +/* #undef ARES_BIG_ENDIAN */ + +/* when building as static part of libcurl */ +/* #undef BUILDING_LIBCURL */ + +/* when building c-ares library */ +/* #undef CARES_BUILDING_LIBRARY */ + +/* when not building a shared library */ +/* #undef CARES_STATICLIB */ + +/* Define to 1 to enable hiding of library internal symbols. */ +/* #undef CARES_SYMBOL_HIDING */ + +/* Definition to make a library symbol externally visible. */ +/* #undef CARES_SYMBOL_SCOPE_EXTERN */ + +/* if a /etc/inet dir is being used */ +/* #undef ETC_INET */ + +/* Define to the type qualifier of arg 1 for getnameinfo. */ +#define GETNAMEINFO_QUAL_ARG1 const + +/* Define to the type of arg 1 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * + +/* Define to the type of arg 2 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG2 socklen_t + +/* Define to the type of args 4 and 6 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG46 size_t + +/* Define to the type of arg 7 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG7 int + +/* Specifies the number of arguments to getservbyport_r */ +#define GETSERVBYPORT_R_ARGS 4 + +/* Specifies the size of the buffer to pass to getservbyport_r */ +#define GETSERVBYPORT_R_BUFSIZE sizeof(struct servent_data) + +/* Define to 1 if you have AF_INET6. */ +#define HAVE_AF_INET6 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_ARPA_NAMESER_COMPAT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bitncmp' function. */ +/* #undef HAVE_BITNCMP */ + +/* Define to 1 if bool is an available type. */ +#define HAVE_BOOL_T 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +#define HAVE_CLOCK_GETTIME_MONOTONIC 1 + +/* Define to 1 if you have the closesocket function. */ +/* #undef HAVE_CLOSESOCKET */ + +/* Define to 1 if you have the CloseSocket camel case function. */ +/* #undef HAVE_CLOSESOCKET_CAMEL */ + +/* Define to 1 if you have the connect function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the fcntl function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#define HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +/* #undef HAVE_GETADDRINFO_THREADSAFE */ + +/* Define to 1 if you have the gethostbyaddr function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the gethostbyname function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the getnameinfo function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the getservbyport_r function. */ +#define HAVE_GETSERVBYPORT_R 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `inet_net_pton' function. */ +#define HAVE_INET_NET_PTON 1 + +/* Define to 1 if inet_net_pton supports IPv6. */ +/* #undef HAVE_INET_NET_PTON_IPV6 */ + +/* Define to 1 if you have a IPv6 capable working inet_ntop function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have a IPv6 capable working inet_pton function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the ioctl function. */ +#define HAVE_IOCTL 1 + +/* Define to 1 if you have the ioctlsocket function. */ +/* #undef HAVE_IOCTLSOCKET */ + +/* Define to 1 if you have the IoctlSocket camel case function. */ +/* #undef HAVE_IOCTLSOCKET_CAMEL */ + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */ + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +/* #undef HAVE_IOCTLSOCKET_FIONBIO */ + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +#define HAVE_IOCTL_FIONBIO 1 + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +#define HAVE_IOCTL_SIOCGIFADDR 1 + +/* Define to 1 if you have the `resolve' library (-lresolve). */ +/* #undef HAVE_LIBRESOLVE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* if your compiler supports LL */ +#define HAVE_LL 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#define HAVE_LONGLONG 1 + +/* Define to 1 if you have the malloc.h header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the memory.h header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +/* #undef HAVE_MSG_NOSIGNAL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have PF_INET6. */ +#define HAVE_PF_INET6 1 + +/* Define to 1 if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to 1 if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to 1 if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to 1 if you have the setsockopt function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if sig_atomic_t is already defined as volatile. */ +/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */ + +/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */ +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the socket function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +/* #undef HAVE_STRCMPI */ + +/* Define to 1 if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the stricmp function. */ +/* #undef HAVE_STRICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the strncasecmp function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the strncmpi function. */ +/* #undef HAVE_STRNCMPI */ + +/* Define to 1 if you have the strnicmp function. */ +/* #undef HAVE_STRNICMP */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STROPTS_H */ + +/* Define to 1 if you have struct addrinfo. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if you have struct in6_addr. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if you have struct sockaddr_in6. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* if struct sockaddr_storage is defined */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the windows.h header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the winsock2.h header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define to 1 if you have the winsock.h header file. */ +/* #undef HAVE_WINSOCK_H */ + +/* Define to 1 if you have the writev function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the ws2tcpip.h header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if you are building a native Windows target. */ +/* #undef NATIVE_WINDOWS */ + +/* Define to 1 if you need the malloc.h header file even with stdlib.h */ +/* #undef NEED_MALLOC_H */ + +/* Define to 1 if you need the memory.h header file even with stdlib.h */ +/* #undef NEED_MEMORY_H */ + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +/* #undef NEED_REENTRANT */ + +/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */ +/* #undef NEED_THREAD_SAFE */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* cpu-machine-OS */ +#define OS "i386-unknown-openbsd4.7" + +/* Name of package */ +#define PACKAGE "c-ares" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "c-ares" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "c-ares 1.7.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-ares" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.7.1" + +/* a suitable file/device to read random data from */ +#define RANDOM_FILE "/dev/urandom" + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 int + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 void + +/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG2_IS_VOID 1 + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG5_IS_VOID */ + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 socklen_t + +/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG6_IS_VOID */ + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV int + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 int + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 void * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV int + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 int + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 void * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV int + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 4 + +/* The size of `struct in6_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN6_ADDR 16 + +/* The size of `struct in_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN_ADDR 4 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to disable non-blocking sockets. */ +/* #undef USE_BLOCKING_SOCKETS */ + +/* Version number of package */ +#define VERSION "1.7.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to 1 if OS is AIX. */ +#ifndef _ALL_SOURCE +/* # undef _ALL_SOURCE */ +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Type to use in place of in_addr_t when system does not provide it. */ +/* #undef in_addr_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* the signed version of size_t */ +/* #undef ssize_t */ diff --git a/src/rt/libuv/src/ares/config_sunos/ares_config.h b/src/rt/libuv/src/ares/config_sunos/ares_config.h new file mode 100644 index 00000000000..836de9f5dde --- /dev/null +++ b/src/rt/libuv/src/ares/config_sunos/ares_config.h @@ -0,0 +1,510 @@ +/* ares_config.h. Generated from ares_config.h.in by configure. */ +/* ares_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* define this if ares is built for a big endian system */ +/* #undef ARES_BIG_ENDIAN */ + +/* when building as static part of libcurl */ +/* #undef BUILDING_LIBCURL */ + +/* when building c-ares library */ +/* #undef CARES_BUILDING_LIBRARY */ + +/* when not building a shared library */ +/* #undef CARES_STATICLIB */ + +/* Define to 1 to enable hiding of library internal symbols. */ +/* #undef CARES_SYMBOL_HIDING */ + +/* Definition to make a library symbol externally visible. */ +/* #undef CARES_SYMBOL_SCOPE_EXTERN */ + +/* if a /etc/inet dir is being used */ +#define ETC_INET 1 + +/* Define to the type qualifier of arg 1 for getnameinfo. */ +#define GETNAMEINFO_QUAL_ARG1 const + +/* Define to the type of arg 1 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * + +/* Define to the type of arg 2 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG2 socklen_t + +/* Define to the type of args 4 and 6 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG46 size_t + +/* Define to the type of arg 7 for getnameinfo. */ +#define GETNAMEINFO_TYPE_ARG7 int + +/* Specifies the number of arguments to getservbyport_r */ +#define GETSERVBYPORT_R_ARGS 5 + +/* Specifies the size of the buffer to pass to getservbyport_r */ +#define GETSERVBYPORT_R_BUFSIZE 4096 + +/* Define to 1 if you have AF_INET6. */ +#define HAVE_AF_INET6 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_COMPAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_NAMESER_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `bitncmp' function. */ +/* #undef HAVE_BITNCMP */ + +/* Define to 1 if bool is an available type. */ +#define HAVE_BOOL_T 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +#define HAVE_CLOCK_GETTIME_MONOTONIC 1 + +/* Define to 1 if you have the closesocket function. */ +/* #undef HAVE_CLOSESOCKET */ + +/* Define to 1 if you have the CloseSocket camel case function. */ +/* #undef HAVE_CLOSESOCKET_CAMEL */ + +/* Define to 1 if you have the connect function. */ +#define HAVE_CONNECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the fcntl function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#define HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +#define HAVE_GETADDRINFO_THREADSAFE 1 + +/* Define to 1 if you have the gethostbyaddr function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define to 1 if you have the gethostbyname function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the getnameinfo function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the getservbyport_r function. */ +#define HAVE_GETSERVBYPORT_R 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `inet_net_pton' function. */ +/* #undef HAVE_INET_NET_PTON */ + +/* Define to 1 if inet_net_pton supports IPv6. */ +/* #undef HAVE_INET_NET_PTON_IPV6 */ + +/* Define to 1 if you have a IPv6 capable working inet_ntop function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have a IPv6 capable working inet_pton function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the ioctl function. */ +#define HAVE_IOCTL 1 + +/* Define to 1 if you have the ioctlsocket function. */ +/* #undef HAVE_IOCTLSOCKET */ + +/* Define to 1 if you have the IoctlSocket camel case function. */ +/* #undef HAVE_IOCTLSOCKET_CAMEL */ + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */ + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +/* #undef HAVE_IOCTLSOCKET_FIONBIO */ + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +/* #undef HAVE_IOCTL_FIONBIO */ + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +/* #undef HAVE_IOCTL_SIOCGIFADDR */ + +/* Define to 1 if you have the `resolve' library (-lresolve). */ +/* #undef HAVE_LIBRESOLVE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* if your compiler supports LL */ +#define HAVE_LL 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#define HAVE_LONGLONG 1 + +/* Define to 1 if you have the malloc.h header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the memory.h header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +/* #undef HAVE_MSG_NOSIGNAL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have PF_INET6. */ +#define HAVE_PF_INET6 1 + +/* Define to 1 if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to 1 if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to 1 if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to 1 if you have the setsockopt function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if sig_atomic_t is already defined as volatile. */ +/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */ + +/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */ +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the socket function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SOCKET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +/* #undef HAVE_STRCMPI */ + +/* Define to 1 if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the stricmp function. */ +/* #undef HAVE_STRICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the strncasecmp function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the strncmpi function. */ +/* #undef HAVE_STRNCMPI */ + +/* Define to 1 if you have the strnicmp function. */ +/* #undef HAVE_STRNICMP */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STROPTS_H 1 + +/* Define to 1 if you have struct addrinfo. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if you have struct in6_addr. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if you have struct sockaddr_in6. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* if struct sockaddr_storage is defined */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the windows.h header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the winsock2.h header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Define to 1 if you have the winsock.h header file. */ +/* #undef HAVE_WINSOCK_H */ + +/* Define to 1 if you have the writev function. */ +#define HAVE_WRITEV 1 + +/* Define to 1 if you have the ws2tcpip.h header file. */ +/* #undef HAVE_WS2TCPIP_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if you are building a native Windows target. */ +/* #undef NATIVE_WINDOWS */ + +/* Define to 1 if you need the malloc.h header file even with stdlib.h */ +/* #undef NEED_MALLOC_H */ + +/* Define to 1 if you need the memory.h header file even with stdlib.h */ +/* #undef NEED_MEMORY_H */ + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +#define NEED_REENTRANT 1 + +/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */ +/* #undef NEED_THREAD_SAFE */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* cpu-machine-OS */ +#define OS "i386-pc-solaris2.11" + +/* Name of package */ +#define PACKAGE "c-ares" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "c-ares" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "c-ares 1.7.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-ares" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.7.1" + +/* a suitable file/device to read random data from */ +#define RANDOM_FILE "/dev/urandom" + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 int + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 void + +/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG2_IS_VOID 1 + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */ +/* #undef RECVFROM_TYPE_ARG5_IS_VOID */ + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 void + +/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */ +#define RECVFROM_TYPE_ARG6_IS_VOID 1 + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV int + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 int + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 void * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV int + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 int + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 void * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 size_t + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV int + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 4 + +/* The size of `struct in6_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN6_ADDR 16 + +/* The size of `struct in_addr', as computed by sizeof. */ +#define SIZEOF_STRUCT_IN_ADDR 4 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to disable non-blocking sockets. */ +/* #undef USE_BLOCKING_SOCKETS */ + +/* Version number of package */ +#define VERSION "1.7.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to 1 if OS is AIX. */ +#ifndef _ALL_SOURCE +/* # undef _ALL_SOURCE */ +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#define _FILE_OFFSET_BITS 64 + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Type to use in place of in_addr_t when system does not provide it. */ +/* #undef in_addr_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* the signed version of size_t */ +/* #undef ssize_t */ diff --git a/src/rt/libuv/src/ares/config_win32/ares_config.h b/src/rt/libuv/src/ares/config_win32/ares_config.h new file mode 100644 index 00000000000..a269da2b814 --- /dev/null +++ b/src/rt/libuv/src/ares/config_win32/ares_config.h @@ -0,0 +1,369 @@ +#ifndef __ARES_CONFIG_WIN32_H +#define __ARES_CONFIG_WIN32_H + +/* when building c-ares library */ +#define CARES_BUILDING_LIBRARY 1 + +/* when not building a shared library */ +#define CARES_STATICLIB 1 + +/* Copyright (C) 2004 - 2008 by Daniel Stenberg et al + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#define ARES_ + +/* ================================================================ */ +/* ares/config-win32.h - Hand crafted config file for Windows */ +/* ================================================================ */ + +/* ---------------------------------------------------------------- */ +/* HEADER FILES */ +/* ---------------------------------------------------------------- */ + +/* Define if you have the header file. */ +#if defined(__MINGW32__) || defined(__POCC__) +#define HAVE_GETOPT_H 1 +#endif + +/* Define if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define if you have the header file. */ +#ifndef __SALFORDC__ +#define HAVE_PROCESS_H 1 +#endif + +/* Define if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define if you have the header file */ +#if defined(__MINGW32__) +#define HAVE_SYS_TIME_H 1 +#endif + +/* Define if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define if you have the header file. */ +#if defined(__MINGW32__) || defined(__WATCOMC__) || defined(__LCC__) || \ + defined(__POCC__) +#define HAVE_UNISTD_H 1 +#endif + +/* Define if you have the windows.h header file. */ +#define HAVE_WINDOWS_H 1 + +/* Define if you have the header file. */ +#define HAVE_WINSOCK_H 1 + +/* Define if you have the header file. */ +#ifndef __SALFORDC__ +#define HAVE_WINSOCK2_H 1 +#endif + +/* Define if you have the header file. */ +#ifndef __SALFORDC__ +#define HAVE_WS2TCPIP_H 1 +#endif + +/* ---------------------------------------------------------------- */ +/* OTHER HEADER INFO */ +/* ---------------------------------------------------------------- */ + +/* Define if sig_atomic_t is an available typedef. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define if you can safely include both and . */ +/* #define TIME_WITH_SYS_TIME 1 */ + +/* ---------------------------------------------------------------- */ +/* FUNCTIONS */ +/* ---------------------------------------------------------------- */ + +/* Define if you have the closesocket function. */ +#define HAVE_CLOSESOCKET 1 + +/* Define if you have the gethostname function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define if you have the ioctlsocket function. */ +#define HAVE_IOCTLSOCKET 1 + +/* Define if you have a working ioctlsocket FIONBIO function. */ +#define HAVE_IOCTLSOCKET_FIONBIO 1 + +/* Define if you have the strcasecmp function. */ +/* #define HAVE_STRCASECMP 1 */ + +/* Define if you have the strdup function. */ +#define HAVE_STRDUP 1 + +/* Define if you have the stricmp function. */ +#define HAVE_STRICMP 1 + +/* Define if you have the strncasecmp function. */ +/* #define HAVE_STRNCASECMP 1 */ + +/* Define if you have the strnicmp function. */ +#define HAVE_STRNICMP 1 + +/* Define if you have the recv function. */ +#define HAVE_RECV 1 + +/* Define to the type of arg 1 for recv. */ +#define RECV_TYPE_ARG1 SOCKET + +/* Define to the type of arg 2 for recv. */ +#define RECV_TYPE_ARG2 char * + +/* Define to the type of arg 3 for recv. */ +#define RECV_TYPE_ARG3 int + +/* Define to the type of arg 4 for recv. */ +#define RECV_TYPE_ARG4 int + +/* Define to the function return type for recv. */ +#define RECV_TYPE_RETV int + +/* Define if you have the recvfrom function. */ +#define HAVE_RECVFROM 1 + +/* Define to the type of arg 1 for recvfrom. */ +#define RECVFROM_TYPE_ARG1 SOCKET + +/* Define to the type pointed by arg 2 for recvfrom. */ +#define RECVFROM_TYPE_ARG2 char + +/* Define to the type of arg 3 for recvfrom. */ +#define RECVFROM_TYPE_ARG3 int + +/* Define to the type of arg 4 for recvfrom. */ +#define RECVFROM_TYPE_ARG4 int + +/* Define to the type pointed by arg 5 for recvfrom. */ +#define RECVFROM_TYPE_ARG5 struct sockaddr + +/* Define to the type pointed by arg 6 for recvfrom. */ +#define RECVFROM_TYPE_ARG6 int + +/* Define to the function return type for recvfrom. */ +#define RECVFROM_TYPE_RETV int + +/* Define if you have the send function. */ +#define HAVE_SEND 1 + +/* Define to the type of arg 1 for send. */ +#define SEND_TYPE_ARG1 SOCKET + +/* Define to the type qualifier of arg 2 for send. */ +#define SEND_QUAL_ARG2 const + +/* Define to the type of arg 2 for send. */ +#define SEND_TYPE_ARG2 char * + +/* Define to the type of arg 3 for send. */ +#define SEND_TYPE_ARG3 int + +/* Define to the type of arg 4 for send. */ +#define SEND_TYPE_ARG4 int + +/* Define to the function return type for send. */ +#define SEND_TYPE_RETV int + +/* Specifics for the Watt-32 tcp/ip stack */ +#ifdef WATT32 + #define SOCKET int + #define NS_INADDRSZ 4 + #define HAVE_ARPA_NAMESER_H 1 + #define HAVE_ARPA_INET_H 1 + #define HAVE_NETDB_H 1 + #define HAVE_NETINET_IN_H 1 + #define HAVE_SYS_SOCKET_H 1 + #define HAVE_NETINET_TCP_H 1 + #define HAVE_AF_INET6 1 + #define HAVE_PF_INET6 1 + #define HAVE_STRUCT_IN6_ADDR 1 + #define HAVE_STRUCT_SOCKADDR_IN6 1 + #undef HAVE_WINSOCK_H + #undef HAVE_WINSOCK2_H + #undef HAVE_WS2TCPIP_H +#endif + +/* ---------------------------------------------------------------- */ +/* TYPEDEF REPLACEMENTS */ +/* ---------------------------------------------------------------- */ + +/* Define this if in_addr_t is not an available 'typedefed' type */ +#define in_addr_t unsigned long + +/* Define as the return type of signal handlers (int or void). */ +#define RETSIGTYPE void + +/* Define ssize_t if it is not an available 'typedefed' type */ +#ifndef _SSIZE_T_DEFINED +# if (defined(__WATCOMC__) && (__WATCOMC__ >= 1240)) || \ + defined(__POCC__) || \ + defined(__MINGW32__) +# elif defined(_WIN64) +# define _SSIZE_T_DEFINED +# define ssize_t __int64 +# else +# define _SSIZE_T_DEFINED +# define ssize_t int +# endif +#endif + +/* ---------------------------------------------------------------- */ +/* TYPE SIZES */ +/* ---------------------------------------------------------------- */ + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `short', as computed by sizeof. */ +#define SIZEOF_SHORT 2 + +/* The size of `size_t', as computed by sizeof. */ +#if defined(_WIN64) +# define SIZEOF_SIZE_T 8 +#else +# define SIZEOF_SIZE_T 4 +#endif + +/* ---------------------------------------------------------------- */ +/* STRUCT RELATED */ +/* ---------------------------------------------------------------- */ + +/* Define this if you have struct addrinfo */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define this if you have struct sockaddr_storage */ +#ifndef __SALFORDC__ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 +#endif + +/* Define this if you have struct timeval */ +#define HAVE_STRUCT_TIMEVAL 1 + +/* ---------------------------------------------------------------- */ +/* COMPILER SPECIFIC */ +/* ---------------------------------------------------------------- */ + +/* Define to avoid VS2005 complaining about portable C functions */ +#if defined(_MSC_VER) && (_MSC_VER >= 1400) +#define _CRT_SECURE_NO_DEPRECATE 1 +#define _CRT_NONSTDC_NO_DEPRECATE 1 +#endif + +/* Officially, Microsoft's Windows SDK versions 6.X do not support Windows + 2000 as a supported build target. VS2008 default installations provide an + embedded Windows SDK v6.0A along with the claim that Windows 2000 is a + valid build target for VS2008. Popular belief is that binaries built using + Windows SDK versions 6.X and Windows 2000 as a build target are functional */ +#if defined(_MSC_VER) && (_MSC_VER >= 1500) +# define VS2008_MINIMUM_TARGET 0x0500 +#endif + +/* When no build target is specified VS2008 default build target is Windows + Vista, which leaves out even Winsows XP. If no build target has been given + for VS2008 we will target the minimum Officially supported build target, + which happens to be Windows XP. */ +#if defined(_MSC_VER) && (_MSC_VER >= 1500) +# define VS2008_DEFAULT_TARGET 0x0501 +#endif + +/* VS2008 default target settings and minimum build target check */ +#if defined(_MSC_VER) && (_MSC_VER >= 1500) +# ifndef _WIN32_WINNT +# define _WIN32_WINNT VS2008_DEFAULT_TARGET +# endif +# ifndef WINVER +# define WINVER VS2008_DEFAULT_TARGET +# endif +# if (_WIN32_WINNT < VS2008_MINIMUM_TARGET) || (WINVER < VS2008_MINIMUM_TARGET) +# error VS2008 does not support Windows build targets prior to Windows 2000 +# endif +#endif + +/* When no build target is specified Pelles C 5.00 and later default build + target is Windows Vista. We override default target to be Windows 2000. */ +#if defined(__POCC__) && (__POCC__ >= 500) +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0500 +# endif +# ifndef WINVER +# define WINVER 0x0500 +# endif +#endif + +/* Availability of freeaddrinfo, getaddrinfo and getnameinfo functions is + quite convoluted, compiler dependent and even build target dependent. */ +#if defined(HAVE_WS2TCPIP_H) +# if defined(__POCC__) +# define HAVE_FREEADDRINFO 1 +# define HAVE_GETADDRINFO 1 +# define HAVE_GETNAMEINFO 1 +# elif defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0501) +# define HAVE_FREEADDRINFO 1 +# define HAVE_GETADDRINFO 1 +# define HAVE_GETNAMEINFO 1 +# elif defined(_MSC_VER) && (_MSC_VER >= 1200) +# define HAVE_FREEADDRINFO 1 +# define HAVE_GETADDRINFO 1 +# define HAVE_GETNAMEINFO 1 +# endif +#endif + +#if defined(__POCC__) +# ifndef _MSC_VER +# error Microsoft extensions /Ze compiler option is required +# endif +# ifndef __POCC__OLDNAMES +# error Compatibility names /Go compiler option is required +# endif +#endif + +/* ---------------------------------------------------------------- */ +/* IPV6 COMPATIBILITY */ +/* ---------------------------------------------------------------- */ + +/* Define this if you have address family AF_INET6 */ +#ifdef HAVE_WINSOCK2_H +#define HAVE_AF_INET6 1 +#endif + +/* Define this if you have protocol family PF_INET6 */ +#ifdef HAVE_WINSOCK2_H +#define HAVE_PF_INET6 1 +#endif + +/* Define this if you have struct in6_addr */ +#ifdef HAVE_WS2TCPIP_H +#define HAVE_STRUCT_IN6_ADDR 1 +#endif + +/* Define this if you have struct sockaddr_in6 */ +#ifdef HAVE_WS2TCPIP_H +#define HAVE_STRUCT_SOCKADDR_IN6 1 +#endif + +/* Define this if you have sockaddr_in6 with scopeid */ +#ifdef HAVE_WS2TCPIP_H +#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 +#endif + + +#endif /* __ARES_CONFIG_WIN32_H */ diff --git a/src/rt/libuv/src/ares/get_ver.awk b/src/rt/libuv/src/ares/get_ver.awk new file mode 100644 index 00000000000..a63c729a9dc --- /dev/null +++ b/src/rt/libuv/src/ares/get_ver.awk @@ -0,0 +1,35 @@ +# *************************************************************************** +# * Project: c-ares +# * +# *************************************************************************** +# awk script which fetches c-ares version number and string from input +# file and writes them to STDOUT. Here you can get an awk version for Win32: +# http://www.gknw.net/development/prgtools/awk-20070501.zip +# +BEGIN { + if (match (ARGV[1], /ares_version.h/)) { + while ((getline < ARGV[1]) > 0) { + if (match ($0, /^#define ARES_COPYRIGHT "[^"]+"$/)) { + libcares_copyright_str = substr($0, 25, length($0)-25); + } + else if (match ($0, /^#define ARES_VERSION_STR "[^"]+"$/)) { + libcares_ver_str = substr($3, 2, length($3)-2); + } + else if (match ($0, /^#define ARES_VERSION_MAJOR [0-9]+$/)) { + libcares_ver_major = substr($3, 1, length($3)); + } + else if (match ($0, /^#define ARES_VERSION_MINOR [0-9]+$/)) { + libcares_ver_minor = substr($3, 1, length($3)); + } + else if (match ($0, /^#define ARES_VERSION_PATCH [0-9]+$/)) { + libcares_ver_patch = substr($3, 1, length($3)); + } + } + libcares_ver = libcares_ver_major "," libcares_ver_minor "," libcares_ver_patch; + print "LIBCARES_VERSION = " libcares_ver ""; + print "LIBCARES_VERSION_STR = " libcares_ver_str ""; + print "LIBCARES_COPYRIGHT_STR = " libcares_copyright_str ""; + } +} + + diff --git a/src/rt/libuv/src/ares/inet_net_pton.c b/src/rt/libuv/src/ares/inet_net_pton.c new file mode 100644 index 00000000000..0b2accf1977 --- /dev/null +++ b/src/rt/libuv/src/ares/inet_net_pton.c @@ -0,0 +1,450 @@ + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996,1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include +#include +#include + +#include "ares.h" +#include "ares_ipv6.h" +#include "inet_net_pton.h" + + +const struct ares_in6_addr ares_in6addr_any = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }; + + +#if !defined(HAVE_INET_NET_PTON) || !defined(HAVE_INET_NET_PTON_IPV6) + +/* + * static int + * inet_net_pton_ipv4(src, dst, size) + * convert IPv4 network number from presentation to network format. + * accepts hex octets, hex strings, decimal octets, and /CIDR. + * "size" is in bytes and describes "dst". + * return: + * number of bits, either imputed classfully or specified with /CIDR, + * or -1 if some failure occurred (check errno). ENOENT means it was + * not an IPv4 network specification. + * note: + * network byte order assumed. this means 192.5.5.240/28 has + * 0b11110000 in its fourth octet. + * note: + * On Windows we store the error in the thread errno, not + * in the winsock error code. This is to avoid loosing the + * actual last winsock error. So use macro ERRNO to fetch the + * errno this funtion sets when returning (-1), not SOCKERRNO. + * author: + * Paul Vixie (ISC), June 1996 + */ +static int +inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size) +{ + static const char xdigits[] = "0123456789abcdef"; + static const char digits[] = "0123456789"; + int n, ch, tmp = 0, dirty, bits; + const unsigned char *odst = dst; + + ch = *src++; + if (ch == '0' && (src[0] == 'x' || src[0] == 'X') + && ISXDIGIT(src[1])) { + /* Hexadecimal: Eat nybble string. */ + if (!size) + goto emsgsize; + dirty = 0; + src++; /* skip x or X. */ + while ((ch = *src++) != '\0' && ISXDIGIT(ch)) { + if (ISUPPER(ch)) + ch = tolower(ch); + n = (int)(strchr(xdigits, ch) - xdigits); + if (dirty == 0) + tmp = n; + else + tmp = (tmp << 4) | n; + if (++dirty == 2) { + if (!size--) + goto emsgsize; + *dst++ = (unsigned char) tmp; + dirty = 0; + } + } + if (dirty) { /* Odd trailing nybble? */ + if (!size--) + goto emsgsize; + *dst++ = (unsigned char) (tmp << 4); + } + } else if (ISDIGIT(ch)) { + /* Decimal: eat dotted digit string. */ + for (;;) { + tmp = 0; + do { + n = (int)(strchr(digits, ch) - digits); + tmp *= 10; + tmp += n; + if (tmp > 255) + goto enoent; + } while ((ch = *src++) != '\0' && + ISDIGIT(ch)); + if (!size--) + goto emsgsize; + *dst++ = (unsigned char) tmp; + if (ch == '\0' || ch == '/') + break; + if (ch != '.') + goto enoent; + ch = *src++; + if (!ISDIGIT(ch)) + goto enoent; + } + } else + goto enoent; + + bits = -1; + if (ch == '/' && + ISDIGIT(src[0]) && dst > odst) { + /* CIDR width specifier. Nothing can follow it. */ + ch = *src++; /* Skip over the /. */ + bits = 0; + do { + n = (int)(strchr(digits, ch) - digits); + bits *= 10; + bits += n; + } while ((ch = *src++) != '\0' && ISDIGIT(ch)); + if (ch != '\0') + goto enoent; + if (bits > 32) + goto emsgsize; + } + + /* Firey death and destruction unless we prefetched EOS. */ + if (ch != '\0') + goto enoent; + + /* If nothing was written to the destination, we found no address. */ + if (dst == odst) + goto enoent; + /* If no CIDR spec was given, infer width from net class. */ + if (bits == -1) { + if (*odst >= 240) /* Class E */ + bits = 32; + else if (*odst >= 224) /* Class D */ + bits = 8; + else if (*odst >= 192) /* Class C */ + bits = 24; + else if (*odst >= 128) /* Class B */ + bits = 16; + else /* Class A */ + bits = 8; + /* If imputed mask is narrower than specified octets, widen. */ + if (bits < ((dst - odst) * 8)) + bits = (int)(dst - odst) * 8; + /* + * If there are no additional bits specified for a class D + * address adjust bits to 4. + */ + if (bits == 8 && *odst == 224) + bits = 4; + } + /* Extend network to cover the actual mask. */ + while (bits > ((dst - odst) * 8)) { + if (!size--) + goto emsgsize; + *dst++ = '\0'; + } + return (bits); + + enoent: + SET_ERRNO(ENOENT); + return (-1); + + emsgsize: + SET_ERRNO(EMSGSIZE); + return (-1); +} + +static int +getbits(const char *src, int *bitsp) +{ + static const char digits[] = "0123456789"; + int n; + int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /* no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 128) /* range */ + return (0); + continue; + } + return (0); + } + if (n == 0) + return (0); + *bitsp = val; + return (1); +} + +static int +getv4(const char *src, unsigned char *dst, int *bitsp) +{ + static const char digits[] = "0123456789"; + unsigned char *odst = dst; + int n; + unsigned int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /* no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 255) /* range */ + return (0); + continue; + } + if (ch == '.' || ch == '/') { + if (dst - odst > 3) /* too many octets? */ + return (0); + *dst++ = (unsigned char)val; + if (ch == '/') + return (getbits(src, bitsp)); + val = 0; + n = 0; + continue; + } + return (0); + } + if (n == 0) + return (0); + if (dst - odst > 3) /* too many octets? */ + return (0); + *dst++ = (unsigned char)val; + return (1); +} + +static int +inet_net_pton_ipv6(const char *src, unsigned char *dst, size_t size) +{ + static const char xdigits_l[] = "0123456789abcdef", + xdigits_u[] = "0123456789ABCDEF"; + unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, saw_xdigit; + unsigned int val; + int digits; + int bits; + size_t bytes; + int words; + int ipv4; + + memset((tp = tmp), '\0', NS_IN6ADDRSZ); + endp = tp + NS_IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + goto enoent; + curtok = src; + saw_xdigit = 0; + val = 0; + digits = 0; + bits = -1; + ipv4 = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) + pch = strchr((xdigits = xdigits_u), ch); + if (pch != NULL) { + val <<= 4; + val |= (pch - xdigits); + if (++digits > 4) + goto enoent; + saw_xdigit = 1; + continue; + } + if (ch == ':') { + curtok = src; + if (!saw_xdigit) { + if (colonp) + goto enoent; + colonp = tp; + continue; + } else if (*src == '\0') + goto enoent; + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); + saw_xdigit = 0; + digits = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && + getv4(curtok, tp, &bits) > 0) { + tp += NS_INADDRSZ; + saw_xdigit = 0; + ipv4 = 1; + break; /* '\0' was seen by inet_pton4(). */ + } + if (ch == '/' && getbits(src, &bits) > 0) + break; + goto enoent; + } + if (saw_xdigit) { + if (tp + NS_INT16SZ > endp) + goto enoent; + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); + } + if (bits == -1) + bits = 128; + + words = (bits + 15) / 16; + if (words < 2) + words = 2; + if (ipv4) + words = 8; + endp = tmp + 2 * words; + + if (colonp != NULL) { + /* + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ + const ssize_t n = tp - colonp; + ssize_t i; + + if (tp == endp) + goto enoent; + for (i = 1; i <= n; i++) { + *(endp - i) = *(colonp + n - i); + *(colonp + n - i) = 0; + } + tp = endp; + } + if (tp != endp) + goto enoent; + + bytes = (bits + 7) / 8; + if (bytes > size) + goto emsgsize; + memcpy(dst, tmp, bytes); + return (bits); + + enoent: + SET_ERRNO(ENOENT); + return (-1); + + emsgsize: + SET_ERRNO(EMSGSIZE); + return (-1); +} + +/* + * int + * inet_net_pton(af, src, dst, size) + * convert network number from presentation to network format. + * accepts hex octets, hex strings, decimal octets, and /CIDR. + * "size" is in bytes and describes "dst". + * return: + * number of bits, either imputed classfully or specified with /CIDR, + * or -1 if some failure occurred (check errno). ENOENT means it was + * not a valid network specification. + * note: + * On Windows we store the error in the thread errno, not + * in the winsock error code. This is to avoid loosing the + * actual last winsock error. So use macro ERRNO to fetch the + * errno this funtion sets when returning (-1), not SOCKERRNO. + * author: + * Paul Vixie (ISC), June 1996 + */ +int +ares_inet_net_pton(int af, const char *src, void *dst, size_t size) +{ + switch (af) { + case AF_INET: + return (inet_net_pton_ipv4(src, dst, size)); + case AF_INET6: + return (inet_net_pton_ipv6(src, dst, size)); + default: + SET_ERRNO(EAFNOSUPPORT); + return (-1); + } +} + +#endif + +#ifndef HAVE_INET_PTON +int ares_inet_pton(int af, const char *src, void *dst) +{ + int result; + size_t size; + + if (af == AF_INET) + size = sizeof(struct in_addr); + else if (af == AF_INET6) + size = sizeof(struct ares_in6_addr); + else + { + SET_ERRNO(EAFNOSUPPORT); + return -1; + } + result = ares_inet_net_pton(af, src, dst, size); + if (result == -1 && ERRNO == ENOENT) + return 0; + return (result > -1 ? 1 : -1); +} +#endif diff --git a/src/rt/libuv/src/ares/inet_net_pton.h b/src/rt/libuv/src/ares/inet_net_pton.h new file mode 100644 index 00000000000..e04bc11b165 --- /dev/null +++ b/src/rt/libuv/src/ares/inet_net_pton.h @@ -0,0 +1,31 @@ +#ifndef __ARES_INET_NET_PTON_H +#define __ARES_INET_NET_PTON_H + + +/* Copyright (C) 2005 by Daniel Stenberg + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#ifdef HAVE_INET_PTON +#define ares_inet_pton(x,y,z) inet_pton(x,y,z) +#else +int ares_inet_pton(int af, const char *src, void *dst); +#endif +#if defined(HAVE_INET_NET_PTON) && defined(HAVE_INET_NET_PTON_IPV6) +#define ares_inet_net_pton(w,x,y,z) inet_net_pton(w,x,y,z) +#else +int ares_inet_net_pton(int af, const char *src, void *dst, size_t size); +#endif + +#endif /* __ARES_INET_NET_PTON_H */ diff --git a/src/rt/libuv/src/ares/inet_ntop.c b/src/rt/libuv/src/ares/inet_ntop.c new file mode 100644 index 00000000000..71385cc8c9a --- /dev/null +++ b/src/rt/libuv/src/ares/inet_ntop.c @@ -0,0 +1,232 @@ + +/* Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include "ares_setup.h" + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif +#ifdef HAVE_NETINET_IN_H +# include +#endif +#ifdef HAVE_ARPA_INET_H +# include +#endif +#ifdef HAVE_ARPA_NAMESER_H +# include +#else +# include "nameser.h" +#endif +#ifdef HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#include +#include +#include +#include +#include + +#include "ares.h" +#include "ares_ipv6.h" +#include "inet_ntop.h" + + +#ifndef HAVE_INET_NTOP + +#ifdef SPRINTF_CHAR +# define SPRINTF(x) strlen(sprintf/**/x) +#else +# define SPRINTF(x) ((size_t)sprintf x) +#endif + +/* + * WARNING: Don't even consider trying to compile this on a system where + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. + */ + +static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size); +static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size); + +/* char * + * inet_ntop(af, src, dst, size) + * convert a network format address to presentation format. + * return: + * pointer to presentation format address (`dst'), or NULL (see errno). + * note: + * On Windows we store the error in the thread errno, not + * in the winsock error code. This is to avoid loosing the + * actual last winsock error. So use macro ERRNO to fetch the + * errno this funtion sets when returning NULL, not SOCKERRNO. + * author: + * Paul Vixie, 1996. + */ +const char * +ares_inet_ntop(int af, const void *src, char *dst, size_t size) +{ + switch (af) + { + case AF_INET: + return (inet_ntop4(src, dst, size)); + case AF_INET6: + return (inet_ntop6(src, dst, size)); + default: + SET_ERRNO(EAFNOSUPPORT); + return (NULL); + } + /* NOTREACHED */ +} + +/* const char * + * inet_ntop4(src, dst, size) + * format an IPv4 address, more or less like inet_ntoa() + * return: + * `dst' (as a const) + * notes: + * (1) uses no statics + * (2) takes a unsigned char* not an in_addr as input + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop4(const unsigned char *src, char *dst, size_t size) +{ + static const char fmt[] = "%u.%u.%u.%u"; + char tmp[sizeof "255.255.255.255"]; + + if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) + { + SET_ERRNO(ENOSPC); + return (NULL); + } + strcpy(dst, tmp); + return (dst); +} + +/* const char * + * inet_ntop6(src, dst, size) + * convert IPv6 binary address into presentation (printable) format + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop6(const unsigned char *src, char *dst, size_t size) +{ + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")]; + char *tp; + struct { + long base; + long len; + } best, cur; + unsigned long words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset(words, '\0', sizeof(words)); + for (i = 0; i < NS_IN6ADDRSZ; i++) + words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); + + best.base = -1; + cur.base = -1; + best.len = 0; + cur.len = 0; + + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + if (words[i] == 0) + { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } + else + { + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && + i < (best.base + best.len)) + { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + { + if (!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp))) + return (NULL); + tp += strlen(tp); + break; + } + tp += SPRINTF((tp, "%lx", words[i])); + } + + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == (NS_IN6ADDRSZ / NS_INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((size_t)(tp - tmp) > size) + { + SET_ERRNO(ENOSPC); + return (NULL); + } + strcpy(dst, tmp); + return (dst); +} +#endif + diff --git a/src/rt/libuv/src/ares/inet_ntop.h b/src/rt/libuv/src/ares/inet_ntop.h new file mode 100644 index 00000000000..c583488f75e --- /dev/null +++ b/src/rt/libuv/src/ares/inet_ntop.h @@ -0,0 +1,26 @@ +#ifndef __ARES_INET_NTOP_H +#define __ARES_INET_NTOP_H + + +/* Copyright (C) 2005 by Dominick Meglio + * + * Permission to use, copy, modify, and distribute this + * software and its documentation for any purpose and without + * fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in + * advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + +#ifdef HAVE_INET_NTOP +#define ares_inet_ntop(w,x,y,z) inet_ntop(w,x,y,z) +#else +const char *ares_inet_ntop(int af, const void *src, char *dst, size_t size); +#endif + +#endif /* __ARES_INET_NTOP_H */ diff --git a/src/rt/libuv/src/ares/nameser.h b/src/rt/libuv/src/ares/nameser.h new file mode 100644 index 00000000000..b5be424cf74 --- /dev/null +++ b/src/rt/libuv/src/ares/nameser.h @@ -0,0 +1,193 @@ + +#ifndef ARES_NAMESER_H +#define ARES_NAMESER_H + +/* header file provided by liren@vivisimo.com */ + +#ifndef HAVE_ARPA_NAMESER_H + +#define NS_PACKETSZ 512 /* maximum packet size */ +#define NS_MAXDNAME 256 /* maximum domain name */ +#define NS_MAXCDNAME 255 /* maximum compressed domain name */ +#define NS_MAXLABEL 63 +#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ +#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ +#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ +#define NS_INT16SZ 2 +#define NS_INADDRSZ 4 +#define NS_IN6ADDRSZ 16 +#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ +#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ + +typedef enum __ns_class { + ns_c_invalid = 0, /* Cookie. */ + ns_c_in = 1, /* Internet. */ + ns_c_2 = 2, /* unallocated/unsupported. */ + ns_c_chaos = 3, /* MIT Chaos-net. */ + ns_c_hs = 4, /* MIT Hesiod. */ + /* Query class values which do not appear in resource records */ + ns_c_none = 254, /* for prereq. sections in update requests */ + ns_c_any = 255, /* Wildcard match. */ + ns_c_max = 65536 +} ns_class; + +typedef enum __ns_type { + ns_t_invalid = 0, /* Cookie. */ + ns_t_a = 1, /* Host address. */ + ns_t_ns = 2, /* Authoritative server. */ + ns_t_md = 3, /* Mail destination. */ + ns_t_mf = 4, /* Mail forwarder. */ + ns_t_cname = 5, /* Canonical name. */ + ns_t_soa = 6, /* Start of authority zone. */ + ns_t_mb = 7, /* Mailbox domain name. */ + ns_t_mg = 8, /* Mail group member. */ + ns_t_mr = 9, /* Mail rename name. */ + ns_t_null = 10, /* Null resource record. */ + ns_t_wks = 11, /* Well known service. */ + ns_t_ptr = 12, /* Domain name pointer. */ + ns_t_hinfo = 13, /* Host information. */ + ns_t_minfo = 14, /* Mailbox information. */ + ns_t_mx = 15, /* Mail routing information. */ + ns_t_txt = 16, /* Text strings. */ + ns_t_rp = 17, /* Responsible person. */ + ns_t_afsdb = 18, /* AFS cell database. */ + ns_t_x25 = 19, /* X_25 calling address. */ + ns_t_isdn = 20, /* ISDN calling address. */ + ns_t_rt = 21, /* Router. */ + ns_t_nsap = 22, /* NSAP address. */ + ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ + ns_t_sig = 24, /* Security signature. */ + ns_t_key = 25, /* Security key. */ + ns_t_px = 26, /* X.400 mail mapping. */ + ns_t_gpos = 27, /* Geographical position (withdrawn). */ + ns_t_aaaa = 28, /* Ip6 Address. */ + ns_t_loc = 29, /* Location Information. */ + ns_t_nxt = 30, /* Next domain (security). */ + ns_t_eid = 31, /* Endpoint identifier. */ + ns_t_nimloc = 32, /* Nimrod Locator. */ + ns_t_srv = 33, /* Server Selection. */ + ns_t_atma = 34, /* ATM Address */ + ns_t_naptr = 35, /* Naming Authority PoinTeR */ + ns_t_kx = 36, /* Key Exchange */ + ns_t_cert = 37, /* Certification record */ + ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ + ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ + ns_t_sink = 40, /* Kitchen sink (experimentatl) */ + ns_t_opt = 41, /* EDNS0 option (meta-RR) */ + ns_t_apl = 42, /* Address prefix list (RFC3123) */ + ns_t_tkey = 249, /* Transaction key */ + ns_t_tsig = 250, /* Transaction signature. */ + ns_t_ixfr = 251, /* Incremental zone transfer. */ + ns_t_axfr = 252, /* Transfer zone of authority. */ + ns_t_mailb = 253, /* Transfer mailbox records. */ + ns_t_maila = 254, /* Transfer mail agent records. */ + ns_t_any = 255, /* Wildcard match. */ + ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ + ns_t_max = 65536 +} ns_type; + +typedef enum __ns_opcode { + ns_o_query = 0, /* Standard query. */ + ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ + ns_o_status = 2, /* Name server status query (unsupported). */ + /* Opcode 3 is undefined/reserved. */ + ns_o_notify = 4, /* Zone change notification. */ + ns_o_update = 5, /* Zone update message. */ + ns_o_max = 6 +} ns_opcode; + +typedef enum __ns_rcode { + ns_r_noerror = 0, /* No error occurred. */ + ns_r_formerr = 1, /* Format error. */ + ns_r_servfail = 2, /* Server failure. */ + ns_r_nxdomain = 3, /* Name error. */ + ns_r_notimpl = 4, /* Unimplemented. */ + ns_r_refused = 5, /* Operation refused. */ + /* these are for BIND_UPDATE */ + ns_r_yxdomain = 6, /* Name exists */ + ns_r_yxrrset = 7, /* RRset exists */ + ns_r_nxrrset = 8, /* RRset does not exist */ + ns_r_notauth = 9, /* Not authoritative for zone */ + ns_r_notzone = 10, /* Zone of record different from zone section */ + ns_r_max = 11, + /* The following are TSIG extended errors */ + ns_r_badsig = 16, + ns_r_badkey = 17, + ns_r_badtime = 18 +} ns_rcode; + +#endif /* HAVE_ARPA_NAMESER_H */ + +#ifndef HAVE_ARPA_NAMESER_COMPAT_H + +#define PACKETSZ NS_PACKETSZ +#define MAXDNAME NS_MAXDNAME +#define MAXCDNAME NS_MAXCDNAME +#define MAXLABEL NS_MAXLABEL +#define HFIXEDSZ NS_HFIXEDSZ +#define QFIXEDSZ NS_QFIXEDSZ +#define RRFIXEDSZ NS_RRFIXEDSZ +#define INDIR_MASK NS_CMPRSFLGS +#define NAMESERVER_PORT NS_DEFAULTPORT + +#define QUERY ns_o_query + +#define SERVFAIL ns_r_servfail +#define NOTIMP ns_r_notimpl +#define REFUSED ns_r_refused +#undef NOERROR /* it seems this is already defined in winerror.h */ +#define NOERROR ns_r_noerror +#define FORMERR ns_r_formerr +#define NXDOMAIN ns_r_nxdomain + +#define C_IN ns_c_in +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs +#define C_NONE ns_c_none +#define C_ANY ns_c_any + +#define T_A ns_t_a +#define T_NS ns_t_ns +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_CNAME ns_t_cname +#define T_SOA ns_t_soa +#define T_MB ns_t_mb +#define T_MG ns_t_mg +#define T_MR ns_t_mr +#define T_NULL ns_t_null +#define T_WKS ns_t_wks +#define T_PTR ns_t_ptr +#define T_HINFO ns_t_hinfo +#define T_MINFO ns_t_minfo +#define T_MX ns_t_mx +#define T_TXT ns_t_txt +#define T_RP ns_t_rp +#define T_AFSDB ns_t_afsdb +#define T_X25 ns_t_x25 +#define T_ISDN ns_t_isdn +#define T_RT ns_t_rt +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_SIG ns_t_sig +#define T_KEY ns_t_key +#define T_PX ns_t_px +#define T_GPOS ns_t_gpos +#define T_AAAA ns_t_aaaa +#define T_LOC ns_t_loc +#define T_NXT ns_t_nxt +#define T_EID ns_t_eid +#define T_NIMLOC ns_t_nimloc +#define T_SRV ns_t_srv +#define T_ATMA ns_t_atma +#define T_NAPTR ns_t_naptr +#define T_TSIG ns_t_tsig +#define T_IXFR ns_t_ixfr +#define T_AXFR ns_t_axfr +#define T_MAILB ns_t_mailb +#define T_MAILA ns_t_maila +#define T_ANY ns_t_any + +#endif /* HAVE_ARPA_NAMESER_COMPAT_H */ + +#endif /* ARES_NAMESER_H */ diff --git a/src/rt/libuv/src/ares/setup_once.h b/src/rt/libuv/src/ares/setup_once.h new file mode 100644 index 00000000000..0c7c811194c --- /dev/null +++ b/src/rt/libuv/src/ares/setup_once.h @@ -0,0 +1,488 @@ +#ifndef __SETUP_ONCE_H +#define __SETUP_ONCE_H + + +/* Copyright (C) 2004 - 2010 by Daniel Stenberg et al + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ + + +/******************************************************************** + * NOTICE * + * ======== * + * * + * Content of header files lib/setup_once.h and ares/setup_once.h * + * must be kept in sync. Modify the other one if you change this. * + * * + ********************************************************************/ + + +/* + * Inclusion of common header files. + */ + +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef NEED_MALLOC_H +#include +#endif + +#ifdef NEED_MEMORY_H +#include +#endif + +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef HAVE_SYS_TIME_H +#include +#ifdef TIME_WITH_SYS_TIME +#include +#endif +#else +#ifdef HAVE_TIME_H +#include +#endif +#endif + +#ifdef WIN32 +#include +#include +#endif + +#ifdef HAVE_STDBOOL_H +#include +#endif + + +/* + * Definition of timeval struct for platforms that don't have it. + */ + +#ifndef HAVE_STRUCT_TIMEVAL +struct timeval { + long tv_sec; + long tv_usec; +}; +#endif + + +/* + * If we have the MSG_NOSIGNAL define, make sure we use + * it as the fourth argument of function send() + */ + +#ifdef HAVE_MSG_NOSIGNAL +#define SEND_4TH_ARG MSG_NOSIGNAL +#else +#define SEND_4TH_ARG 0 +#endif + + +#if defined(__minix) +/* Minix doesn't support recv on TCP sockets */ +#define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \ + (RECV_TYPE_ARG2)(y), \ + (RECV_TYPE_ARG3)(z)) + +#elif defined(HAVE_RECV) +/* + * The definitions for the return type and arguments types + * of functions recv() and send() belong and come from the + * configuration file. Do not define them in any other place. + * + * HAVE_RECV is defined if you have a function named recv() + * which is used to read incoming data from sockets. If your + * function has another name then don't define HAVE_RECV. + * + * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2, + * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also + * be defined. + * + * HAVE_SEND is defined if you have a function named send() + * which is used to write outgoing data on a connected socket. + * If yours has another name then don't define HAVE_SEND. + * + * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2, + * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and + * SEND_TYPE_RETV must also be defined. + */ + +#if !defined(RECV_TYPE_ARG1) || \ + !defined(RECV_TYPE_ARG2) || \ + !defined(RECV_TYPE_ARG3) || \ + !defined(RECV_TYPE_ARG4) || \ + !defined(RECV_TYPE_RETV) + /* */ + Error Missing_definition_of_return_and_arguments_types_of_recv + /* */ +#else +#define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \ + (RECV_TYPE_ARG2)(y), \ + (RECV_TYPE_ARG3)(z), \ + (RECV_TYPE_ARG4)(0)) +#endif +#else /* HAVE_RECV */ +#ifndef sread + /* */ + Error Missing_definition_of_macro_sread + /* */ +#endif +#endif /* HAVE_RECV */ + + +#if defined(__minix) +/* Minix doesn't support send on TCP sockets */ +#define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \ + (SEND_TYPE_ARG2)(y), \ + (SEND_TYPE_ARG3)(z)) + +#elif defined(HAVE_SEND) +#if !defined(SEND_TYPE_ARG1) || \ + !defined(SEND_QUAL_ARG2) || \ + !defined(SEND_TYPE_ARG2) || \ + !defined(SEND_TYPE_ARG3) || \ + !defined(SEND_TYPE_ARG4) || \ + !defined(SEND_TYPE_RETV) + /* */ + Error Missing_definition_of_return_and_arguments_types_of_send + /* */ +#else +#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \ + (SEND_TYPE_ARG2)(y), \ + (SEND_TYPE_ARG3)(z), \ + (SEND_TYPE_ARG4)(SEND_4TH_ARG)) +#endif +#else /* HAVE_SEND */ +#ifndef swrite + /* */ + Error Missing_definition_of_macro_swrite + /* */ +#endif +#endif /* HAVE_SEND */ + + +#if 0 +#if defined(HAVE_RECVFROM) +/* + * Currently recvfrom is only used on udp sockets. + */ +#if !defined(RECVFROM_TYPE_ARG1) || \ + !defined(RECVFROM_TYPE_ARG2) || \ + !defined(RECVFROM_TYPE_ARG3) || \ + !defined(RECVFROM_TYPE_ARG4) || \ + !defined(RECVFROM_TYPE_ARG5) || \ + !defined(RECVFROM_TYPE_ARG6) || \ + !defined(RECVFROM_TYPE_RETV) + /* */ + Error Missing_definition_of_return_and_arguments_types_of_recvfrom + /* */ +#else +#define sreadfrom(s,b,bl,f,fl) (ssize_t)recvfrom((RECVFROM_TYPE_ARG1) (s), \ + (RECVFROM_TYPE_ARG2 *)(b), \ + (RECVFROM_TYPE_ARG3) (bl), \ + (RECVFROM_TYPE_ARG4) (0), \ + (RECVFROM_TYPE_ARG5 *)(f), \ + (RECVFROM_TYPE_ARG6 *)(fl)) +#endif +#else /* HAVE_RECVFROM */ +#ifndef sreadfrom + /* */ + Error Missing_definition_of_macro_sreadfrom + /* */ +#endif +#endif /* HAVE_RECVFROM */ + + +#ifdef RECVFROM_TYPE_ARG6_IS_VOID +# define RECVFROM_ARG6_T int +#else +# define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6 +#endif +#endif /* if 0 */ + + +/* + * Function-like macro definition used to close a socket. + */ + +#if defined(HAVE_CLOSESOCKET) +# define sclose(x) closesocket((x)) +#elif defined(HAVE_CLOSESOCKET_CAMEL) +# define sclose(x) CloseSocket((x)) +#else +# define sclose(x) close((x)) +#endif + + +/* + * Uppercase macro versions of ANSI/ISO is*() functions/macros which + * avoid negative number inputs with argument byte codes > 127. + */ + +#define ISSPACE(x) (isspace((int) ((unsigned char)x))) +#define ISDIGIT(x) (isdigit((int) ((unsigned char)x))) +#define ISALNUM(x) (isalnum((int) ((unsigned char)x))) +#define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x))) +#define ISGRAPH(x) (isgraph((int) ((unsigned char)x))) +#define ISALPHA(x) (isalpha((int) ((unsigned char)x))) +#define ISPRINT(x) (isprint((int) ((unsigned char)x))) +#define ISUPPER(x) (isupper((int) ((unsigned char)x))) +#define ISLOWER(x) (islower((int) ((unsigned char)x))) + +#define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \ + (((unsigned char)x) == '\t')) + +#define TOLOWER(x) (tolower((int) ((unsigned char)x))) + + +/* + * 'bool' exists on platforms with , i.e. C99 platforms. + * On non-C99 platforms there's no bool, so define an enum for that. + * On C99 platforms 'false' and 'true' also exist. Enum uses a + * global namespace though, so use bool_false and bool_true. + */ + +#ifndef HAVE_BOOL_T + typedef enum { + bool_false = 0, + bool_true = 1 + } bool; + +/* + * Use a define to let 'true' and 'false' use those enums. There + * are currently no use of true and false in libcurl proper, but + * there are some in the examples. This will cater for any later + * code happening to use true and false. + */ +# define false bool_false +# define true bool_true +# define HAVE_BOOL_T +#endif + + +/* + * Redefine TRUE and FALSE too, to catch current use. With this + * change, 'bool found = 1' will give a warning on MIPSPro, but + * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro, + * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too. + */ + +#ifndef TRUE +#define TRUE true +#endif +#ifndef FALSE +#define FALSE false +#endif + + +/* + * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type. + */ + +#ifndef HAVE_SIG_ATOMIC_T +typedef int sig_atomic_t; +#define HAVE_SIG_ATOMIC_T +#endif + + +/* + * Convenience SIG_ATOMIC_T definition + */ + +#ifdef HAVE_SIG_ATOMIC_T_VOLATILE +#define SIG_ATOMIC_T static sig_atomic_t +#else +#define SIG_ATOMIC_T static volatile sig_atomic_t +#endif + + +/* + * Default return type for signal handlers. + */ + +#ifndef RETSIGTYPE +#define RETSIGTYPE void +#endif + + +/* + * Macro used to include code only in debug builds. + */ + +#ifdef DEBUGBUILD +#define DEBUGF(x) x +#else +#define DEBUGF(x) do { } while (0) +#endif + + +/* + * Macro used to include assertion code only in debug builds. + */ + +#if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H) +#define DEBUGASSERT(x) assert(x) +#else +#define DEBUGASSERT(x) do { } while (0) +#endif + + +/* + * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno + * (or equivalent) on this platform to hide platform details to code using it. + */ + +#ifdef USE_WINSOCK +#define SOCKERRNO ((int)WSAGetLastError()) +#define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) +#else +#define SOCKERRNO (errno) +#define SET_SOCKERRNO(x) (errno = (x)) +#endif + + +/* + * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno + * (or equivalent) on this platform to hide platform details to code using it. + */ + +#ifdef WIN32 +#define ERRNO ((int)GetLastError()) +#define SET_ERRNO(x) (SetLastError((DWORD)(x))) +#else +#define ERRNO (errno) +#define SET_ERRNO(x) (errno = (x)) +#endif + + +/* + * Portable error number symbolic names defined to Winsock error codes. + */ + +#ifdef USE_WINSOCK +#undef EBADF /* override definition in errno.h */ +#define EBADF WSAEBADF +#undef EINTR /* override definition in errno.h */ +#define EINTR WSAEINTR +#undef EINVAL /* override definition in errno.h */ +#define EINVAL WSAEINVAL +#undef EWOULDBLOCK /* override definition in errno.h */ +#define EWOULDBLOCK WSAEWOULDBLOCK +#undef EINPROGRESS /* override definition in errno.h */ +#define EINPROGRESS WSAEINPROGRESS +#undef EALREADY /* override definition in errno.h */ +#define EALREADY WSAEALREADY +#undef ENOTSOCK /* override definition in errno.h */ +#define ENOTSOCK WSAENOTSOCK +#undef EDESTADDRREQ /* override definition in errno.h */ +#define EDESTADDRREQ WSAEDESTADDRREQ +#undef EMSGSIZE /* override definition in errno.h */ +#define EMSGSIZE WSAEMSGSIZE +#undef EPROTOTYPE /* override definition in errno.h */ +#define EPROTOTYPE WSAEPROTOTYPE +#undef ENOPROTOOPT /* override definition in errno.h */ +#define ENOPROTOOPT WSAENOPROTOOPT +#undef EPROTONOSUPPORT /* override definition in errno.h */ +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +#undef EOPNOTSUPP /* override definition in errno.h */ +#define EOPNOTSUPP WSAEOPNOTSUPP +#define EPFNOSUPPORT WSAEPFNOSUPPORT +#undef EAFNOSUPPORT /* override definition in errno.h */ +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#undef EADDRINUSE /* override definition in errno.h */ +#define EADDRINUSE WSAEADDRINUSE +#undef EADDRNOTAVAIL /* override definition in errno.h */ +#define EADDRNOTAVAIL WSAEADDRNOTAVAIL +#undef ENETDOWN /* override definition in errno.h */ +#define ENETDOWN WSAENETDOWN +#undef ENETUNREACH /* override definition in errno.h */ +#define ENETUNREACH WSAENETUNREACH +#undef ENETRESET /* override definition in errno.h */ +#define ENETRESET WSAENETRESET +#undef ECONNABORTED /* override definition in errno.h */ +#define ECONNABORTED WSAECONNABORTED +#undef ECONNRESET /* override definition in errno.h */ +#define ECONNRESET WSAECONNRESET +#undef ENOBUFS /* override definition in errno.h */ +#define ENOBUFS WSAENOBUFS +#undef EISCONN /* override definition in errno.h */ +#define EISCONN WSAEISCONN +#undef ENOTCONN /* override definition in errno.h */ +#define ENOTCONN WSAENOTCONN +#define ESHUTDOWN WSAESHUTDOWN +#define ETOOMANYREFS WSAETOOMANYREFS +#undef ETIMEDOUT /* override definition in errno.h */ +#define ETIMEDOUT WSAETIMEDOUT +#undef ECONNREFUSED /* override definition in errno.h */ +#define ECONNREFUSED WSAECONNREFUSED +#undef ELOOP /* override definition in errno.h */ +#define ELOOP WSAELOOP +#ifndef ENAMETOOLONG /* possible previous definition in errno.h */ +#define ENAMETOOLONG WSAENAMETOOLONG +#endif +#define EHOSTDOWN WSAEHOSTDOWN +#undef EHOSTUNREACH /* override definition in errno.h */ +#define EHOSTUNREACH WSAEHOSTUNREACH +#ifndef ENOTEMPTY /* possible previous definition in errno.h */ +#define ENOTEMPTY WSAENOTEMPTY +#endif +#define EPROCLIM WSAEPROCLIM +#define EUSERS WSAEUSERS +#define EDQUOT WSAEDQUOT +#define ESTALE WSAESTALE +#define EREMOTE WSAEREMOTE +#endif + + +/* + * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid() + */ + +#if defined(__VMS) && \ + defined(__INITIAL_POINTER_SIZE) && (__INITIAL_POINTER_SIZE == 64) +#define getpwuid __32_getpwuid +#endif + + +/* + * Macro argv_item_t hides platform details to code using it. + */ + +#ifdef __VMS +#define argv_item_t __char_ptr32 +#else +#define argv_item_t char * +#endif + + +/* + * We use this ZERO_NULL to avoid picky compiler warnings, + * when assigning a NULL pointer to a function pointer var. + */ + +#define ZERO_NULL 0 + + +#endif /* __SETUP_ONCE_H */ + diff --git a/src/rt/libuv/src/ares/windows_port.c b/src/rt/libuv/src/ares/windows_port.c new file mode 100644 index 00000000000..03acd1c1e2b --- /dev/null +++ b/src/rt/libuv/src/ares/windows_port.c @@ -0,0 +1,22 @@ +#include "ares_setup.h" + + +/* only do the following on windows + */ +#if (defined(WIN32) || defined(WATT32)) && !defined(MSDOS) + +#ifdef __WATCOMC__ +/* + * Watcom needs a DllMain() in order to initialise the clib startup code. + */ +BOOL +WINAPI DllMain (HINSTANCE hnd, DWORD reason, LPVOID reserved) +{ + (void) hnd; + (void) reason; + (void) reserved; + return (TRUE); +} +#endif + +#endif /* WIN32 builds only */ diff --git a/src/rt/libuv/src/eio/Changes b/src/rt/libuv/src/eio/Changes new file mode 100644 index 00000000000..baa94eca9ca --- /dev/null +++ b/src/rt/libuv/src/eio/Changes @@ -0,0 +1,35 @@ +Revision history for libeio + +TODO: maybe add mincore support? available on at least darwin, solaris, linux, freebsd +TODO: openbsd requites stdint.h for intptr_t - why posix? + +1.0 + - readdir: correctly handle malloc failures. + - readdir: new flags argument, can return inode + and possibly filetype, can sort in various ways. + - readdir: stop immediately when cancelled, do + not continue reading the directory. + - fix return value of eio_sendfile_sync. + - include sys/mman.h for msync. + - added EIO_STACKSIZE. + - added msync, mtouch support (untested). + - added sync_file_range (untested). + - fixed custom support. + - use a more robust feed-add detection method. + - "outbundled" from IO::AIO. + - eio_set_max_polltime did not properly convert time to ticks. + - tentatively support darwin in sendfile. + - fix freebsd/darwin sendfile. + - also use sendfile emulation for ENOTSUP and EOPNOTSUPP + error codes. + - add OS-independent EIO_MT_* and EIO_MS_* flag enums. + - add eio_statvfs/eio_fstatvfs. + - add eio_mlock/eio_mlockall and OS-independent MCL_* flag enums. + - no longer set errno to 0 before making syscalls, this only lures + people into the trap of believing errno shows success or failure. + - "fix" demo.c so that it works as non-root. + - suppoert utimes seperately from futimes, as some systems have + utimes but not futimes. + - use _POSIX_MEMLOCK_RANGE for mlock. + - do not (errornously) overwrite CFLAGS in configure.ac. + diff --git a/src/rt/libuv/src/eio/LICENSE b/src/rt/libuv/src/eio/LICENSE new file mode 100644 index 00000000000..1ed1324d304 --- /dev/null +++ b/src/rt/libuv/src/eio/LICENSE @@ -0,0 +1,36 @@ +All files in libeio are Copyright (C)2007,2008 Marc Alexander Lehmann. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Alternatively, the contents of this package may be used under the terms +of the GNU General Public License ("GPL") version 2 or any later version, +in which case the provisions of the GPL are applicable instead of the +above. If you wish to allow the use of your version of this package only +under the terms of the GPL and not to allow others to use your version of +this file under the BSD license, indicate your decision by deleting the +provisions above and replace them with the notice and other provisions +required by the GPL in this and the other files of this package. If you do +not delete the provisions above, a recipient may use your version of this +file under either the BSD or the GPL. diff --git a/src/rt/libuv/src/eio/Makefile.am b/src/rt/libuv/src/eio/Makefile.am new file mode 100644 index 00000000000..857d26b6190 --- /dev/null +++ b/src/rt/libuv/src/eio/Makefile.am @@ -0,0 +1,15 @@ +AUTOMAKE_OPTIONS = foreign no-dependencies + +VERSION_INFO = 1:0 + +EXTRA_DIST = LICENSE Changes autogen.sh + +#man_MANS = ev.3 + +include_HEADERS = eio.h + +lib_LTLIBRARIES = libeio.la + +libeio_la_SOURCES = eio.c xthread.h config.h +libeio_la_LDFLAGS = -version-info $(VERSION_INFO) + diff --git a/src/rt/libuv/ev/aclocal.m4 b/src/rt/libuv/src/eio/aclocal.m4 similarity index 100% rename from src/rt/libuv/ev/aclocal.m4 rename to src/rt/libuv/src/eio/aclocal.m4 diff --git a/src/rt/libuv/src/eio/autogen.sh b/src/rt/libuv/src/eio/autogen.sh new file mode 100755 index 00000000000..bd3387c46c7 --- /dev/null +++ b/src/rt/libuv/src/eio/autogen.sh @@ -0,0 +1,5 @@ +libtoolize +aclocal +automake --add-missing +autoconf +autoheader diff --git a/src/rt/libuv/src/eio/config.h.in b/src/rt/libuv/src/eio/config.h.in new file mode 100644 index 00000000000..73e9dd07d28 --- /dev/null +++ b/src/rt/libuv/src/eio/config.h.in @@ -0,0 +1,86 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* fdatasync(2) is available */ +#undef HAVE_FDATASYNC + +/* futimes(2) is available */ +#undef HAVE_FUTIMES + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* posix_fadvise(2) is available */ +#undef HAVE_POSIX_FADVISE + +/* posix_madvise(2) is available */ +#undef HAVE_POSIX_MADVISE + +/* pread(2) and pwrite(2) are available */ +#undef HAVE_PREADWRITE + +/* readahead(2) is available (linux) */ +#undef HAVE_READAHEAD + +/* sendfile(2) is available and supported */ +#undef HAVE_SENDFILE + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* sync_file_range(2) is available */ +#undef HAVE_SYNC_FILE_RANGE + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* utimes(2) is available */ +#undef HAVE_UTIMES + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS diff --git a/src/rt/libuv/src/eio/config_cygwin.h b/src/rt/libuv/src/eio/config_cygwin.h new file mode 100644 index 00000000000..f149a6b352a --- /dev/null +++ b/src/rt/libuv/src/eio/config_cygwin.h @@ -0,0 +1,77 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* fdatasync(2) is available */ +#define HAVE_FDATASYNC 1 + +/* futimes(2) is available */ +#define HAVE_FUTIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* pread(2) and pwrite(2) are available */ +#define HAVE_PREADWRITE 1 + +/* readahead(2) is available (linux) */ +/* #undef HAVE_READAHEAD */ + +/* sendfile(2) is available and supported */ +/* #undef HAVE_SENDFILE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* sync_file_range(2) is available */ +/* #undef HAVE_SYNC_FILE_RANGE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Name of package */ +#define PACKAGE "libeio" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.0" diff --git a/src/rt/libuv/src/eio/config_darwin.h b/src/rt/libuv/src/eio/config_darwin.h new file mode 100644 index 00000000000..84a3440df0d --- /dev/null +++ b/src/rt/libuv/src/eio/config_darwin.h @@ -0,0 +1,82 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* fdatasync(2) is not available on 10.5 but is on 10.6 + * How should we deal with this? */ +/* #define HAVE_FDATASYNC 0 */ + +/* futimes(2) is available */ +#define HAVE_FUTIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* pread(2) and pwrite(2) are available */ +#define HAVE_PREADWRITE 1 + +/* readahead(2) is available (linux) */ +/* #undef HAVE_READAHEAD */ + +/* sendfile(2) is available and supported */ +#define HAVE_SENDFILE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* sync_file_range(2) is available */ +/* #undef HAVE_SYNC_FILE_RANGE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libeio" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.0" diff --git a/src/rt/libuv/src/eio/config_freebsd.h b/src/rt/libuv/src/eio/config_freebsd.h new file mode 100644 index 00000000000..b740cdd8787 --- /dev/null +++ b/src/rt/libuv/src/eio/config_freebsd.h @@ -0,0 +1,78 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* fdatasync(2) is available */ +/* #undef HAVE_FDATASYNC */ + +/* futimes(2) is available */ +#define HAVE_FUTIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* pread(2) and pwrite(2) are available */ +#define HAVE_PREADWRITE 1 + +/* readahead(2) is available (linux) */ +/* #undef HAVE_READAHEAD */ + +/* sendfile(2) is available and supported */ +#define HAVE_SENDFILE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* sync_file_range(2) is available */ +/* #undef HAVE_SYNC_FILE_RANGE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libeio" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.0" diff --git a/src/rt/libuv/src/eio/config_linux.h b/src/rt/libuv/src/eio/config_linux.h new file mode 100644 index 00000000000..9823f624085 --- /dev/null +++ b/src/rt/libuv/src/eio/config_linux.h @@ -0,0 +1,89 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +#include + +#define LINUX_VERSION_CODE_FOR(major, minor, patch) \ + (((major & 255) << 16) | ((minor & 255) << 8) | (patch & 255)) + +#define LINUX_VERSION_AT_LEAST(major, minor, patch) \ + (LINUX_VERSION_CODE >= LINUX_VERSION_CODE_FOR(major, minor, patch)) + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* fdatasync(2) is available */ +#define HAVE_FDATASYNC 1 + +/* futimes(2) is available */ +#define HAVE_FUTIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* pread(2) and pwrite(2) are available */ +#define HAVE_PREADWRITE 1 + +/* readahead(2) is available (linux) */ +#define HAVE_READAHEAD 1 + +/* sendfile(2) is available and supported */ +#define HAVE_SENDFILE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* sync_file_range(2) is available */ +#define HAVE_SYNC_FILE_RANGE LINUX_VERSION_AT_LEAST(2, 6, 17) + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libeio" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.0" diff --git a/src/rt/libuv/src/eio/config_sunos.h b/src/rt/libuv/src/eio/config_sunos.h new file mode 100644 index 00000000000..8f878efd956 --- /dev/null +++ b/src/rt/libuv/src/eio/config_sunos.h @@ -0,0 +1,81 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* fdatasync(2) is available */ +#define HAVE_FDATASYNC 1 + +/* futimes(2) is available */ +/* #undef HAVE_FUTIMES */ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* pread(2) and pwrite(2) are available */ +#define HAVE_PREADWRITE 1 + +/* readahead(2) is available (linux) */ +/* #undef HAVE_READAHEAD */ + +/* sendfile(2) is available and supported */ +/* #undef HAVE_SENDFILE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* sync_file_range(2) is available */ +/* #undef HAVE_SYNC_FILE_RANGE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libeio" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.0" diff --git a/src/rt/libuv/src/eio/configure.ac b/src/rt/libuv/src/eio/configure.ac new file mode 100644 index 00000000000..9f4cea9d12d --- /dev/null +++ b/src/rt/libuv/src/eio/configure.ac @@ -0,0 +1,22 @@ +AC_PREREQ(2.59) +AC_INIT +AC_CONFIG_SRCDIR([eio.h]) +AC_CONFIG_HEADERS([config.h]) + +AM_INIT_AUTOMAKE(libeio,1.0) +AM_MAINTAINER_MODE +AC_PROG_LIBTOOL + +AC_PROG_CC + +if test "x$GCC" = xyes ; then + CFLAGS="$CFLAGS -O3" +fi + +dnl somebody will forgive me +CFLAGS="-D_GNU_SOURCE $CFLAGS" + +m4_include([libeio.m4]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/src/rt/libuv/src/eio/demo.c b/src/rt/libuv/src/eio/demo.c new file mode 100644 index 00000000000..cbef59557fe --- /dev/null +++ b/src/rt/libuv/src/eio/demo.c @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "eio.h" + +int respipe [2]; + +void +want_poll (void) +{ + char dummy; + printf ("want_poll ()\n"); + write (respipe [1], &dummy, 1); +} + +void +done_poll (void) +{ + char dummy; + printf ("done_poll ()\n"); + read (respipe [0], &dummy, 1); +} + +void +event_loop (void) +{ + // an event loop. yeah. + struct pollfd pfd; + pfd.fd = respipe [0]; + pfd.events = POLLIN; + + printf ("\nentering event loop\n"); + while (eio_nreqs ()) + { + poll (&pfd, 1, -1); + printf ("eio_poll () = %d\n", eio_poll ()); + } + printf ("leaving event loop\n"); +} + +int +res_cb (eio_req *req) +{ + printf ("res_cb(%d|%s) = %d\n", req->type, req->data ? req->data : "?", EIO_RESULT (req)); + + if (req->result < 0) + abort (); + + return 0; +} + +int +readdir_cb (eio_req *req) +{ + char *buf = (char *)EIO_BUF (req); + + printf ("readdir_cb = %d\n", EIO_RESULT (req)); + + if (EIO_RESULT (req) < 0) + return 0; + + while (EIO_RESULT (req)--) + { + printf ("readdir = <%s>\n", buf); + buf += strlen (buf) + 1; + } + + return 0; +} + +int +stat_cb (eio_req *req) +{ + struct stat *buf = EIO_STAT_BUF (req); + + if (req->type == EIO_FSTAT) + printf ("fstat_cb = %d\n", EIO_RESULT (req)); + else + printf ("stat_cb(%s) = %d\n", EIO_PATH (req), EIO_RESULT (req)); + + if (!EIO_RESULT (req)) + printf ("stat size %d perm 0%o\n", buf->st_size, buf->st_mode & 0777); + + return 0; +} + +int +read_cb (eio_req *req) +{ + unsigned char *buf = (unsigned char *)EIO_BUF (req); + + printf ("read_cb = %d (%02x%02x%02x%02x %02x%02x%02x%02x)\n", + EIO_RESULT (req), + buf [0], buf [1], buf [2], buf [3], + buf [4], buf [5], buf [6], buf [7]); + + return 0; +} + +int last_fd; + +int +open_cb (eio_req *req) +{ + printf ("open_cb = %d\n", EIO_RESULT (req)); + + last_fd = EIO_RESULT (req); + + return 0; +} + +int +main (void) +{ + printf ("pipe ()\n"); + if (pipe (respipe)) abort (); + + printf ("eio_init ()\n"); + if (eio_init (want_poll, done_poll)) abort (); + + do + { + /* avoid relative paths yourself(!) */ + eio_mkdir ("eio-test-dir", 0777, 0, res_cb, "mkdir"); + eio_nop (0, res_cb, "nop"); + event_loop (); + + eio_stat ("eio-test-dir", 0, stat_cb, "stat"); + eio_lstat ("eio-test-dir", 0, stat_cb, "stat"); + eio_open ("eio-test-dir/eio-test-file", O_RDWR | O_CREAT, 0777, 0, open_cb, "open"); + eio_symlink ("test", "eio-test-dir/eio-symlink", 0, res_cb, "symlink"); + eio_mknod ("eio-test-dir/eio-fifo", S_IFIFO, 0, 0, res_cb, "mknod"); + event_loop (); + + eio_utime ("eio-test-dir", 12345.678, 23456.789, 0, res_cb, "utime"); + eio_futime (last_fd, 92345.678, 93456.789, 0, res_cb, "futime"); + eio_chown ("eio-test-dir", getuid (), getgid (), 0, res_cb, "chown"); + eio_fchown (last_fd, getuid (), getgid (), 0, res_cb, "fchown"); + eio_fchmod (last_fd, 0723, 0, res_cb, "fchmod"); + eio_readdir ("eio-test-dir", 0, 0, readdir_cb, "readdir"); + eio_readdir ("/nonexistant", 0, 0, readdir_cb, "readdir"); + eio_fstat (last_fd, 0, stat_cb, "stat"); + eio_write (last_fd, "test\nfail\n", 10, 4, 0, res_cb, "write"); + event_loop (); + + eio_read (last_fd, 0, 8, 0, EIO_PRI_DEFAULT, read_cb, "read"); + eio_readlink ("eio-test-dir/eio-symlink", 0, res_cb, "readlink"); + event_loop (); + + eio_dup2 (1, 2, EIO_PRI_DEFAULT, res_cb, "dup"); // dup stdout to stderr + eio_chmod ("eio-test-dir", 0765, 0, res_cb, "chmod"); + eio_ftruncate (last_fd, 9, 0, res_cb, "ftruncate"); + eio_fdatasync (last_fd, 0, res_cb, "fdatasync"); + eio_fsync (last_fd, 0, res_cb, "fsync"); + eio_sync (0, res_cb, "sync"); + eio_busy (0.5, 0, res_cb, "busy"); + event_loop (); + + eio_sendfile (1, last_fd, 4, 5, 0, res_cb, "sendfile"); // write "test\n" to stdout + eio_fstat (last_fd, 0, stat_cb, "stat"); + event_loop (); + + eio_truncate ("eio-test-dir/eio-test-file", 6, 0, res_cb, "truncate"); + eio_readahead (last_fd, 0, 64, 0, res_cb, "readahead"); + event_loop (); + + eio_close (last_fd, 0, res_cb, "close"); + eio_link ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-2", 0, res_cb, "link"); + event_loop (); + + eio_rename ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-renamed", 0, res_cb, "rename"); + event_loop (); + + eio_unlink ("eio-test-dir/eio-fifo", 0, res_cb, "unlink"); + eio_unlink ("eio-test-dir/eio-symlink", 0, res_cb, "unlink"); + eio_unlink ("eio-test-dir/eio-test-file-2", 0, res_cb, "unlink"); + eio_unlink ("eio-test-dir/eio-test-file-renamed", 0, res_cb, "unlink"); + event_loop (); + + eio_rmdir ("eio-test-dir", 0, res_cb, "rmdir"); + event_loop (); + } + while (0); + + return 0; +} + diff --git a/src/rt/libuv/src/eio/eio.3 b/src/rt/libuv/src/eio/eio.3 new file mode 100644 index 00000000000..ec5bde33e1a --- /dev/null +++ b/src/rt/libuv/src/eio/eio.3 @@ -0,0 +1,3428 @@ +.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05) +.\" +.\" Standard preamble: +.\" ======================================================================== +.de Sh \" Subsection heading +.br +.if t .Sp +.ne 5 +.PP +\fB\\$1\fR +.PP +.. +.de Sp \" Vertical space (when we can't use .PP) +.if t .sp .5v +.if n .sp +.. +.de Vb \" Begin verbatim text +.ft CW +.nf +.ne \\$1 +.. +.de Ve \" End verbatim text +.ft R +.fi +.. +.\" Set up some character translations and predefined strings. \*(-- will +.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left +.\" double quote, and \*(R" will give a right double quote. \*(C+ will +.\" give a nicer C++. Capital omega is used to do unbreakable dashes and +.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, +.\" nothing in troff, for use with C<>. +.tr \(*W- +.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' +.ie n \{\ +. ds -- \(*W- +. ds PI pi +. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch +. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch +. ds L" "" +. ds R" "" +. ds C` "" +. ds C' "" +'br\} +.el\{\ +. ds -- \|\(em\| +. ds PI \(*p +. ds L" `` +. ds R" '' +'br\} +.\" +.\" Escape single quotes in literal strings from groff's Unicode transform. +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" +.\" If the F register is turned on, we'll generate index entries on stderr for +.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index +.\" entries marked with X<> in POD. Of course, you'll have to process the +.\" output yourself in some meaningful fashion. +.ie \nF \{\ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" +.. +. nr % 0 +. rr F +.\} +.el \{\ +. de IX +.. +.\} +.\" +.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). +.\" Fear. Run. Save yourself. No user-serviceable parts. +. \" fudge factors for nroff and troff +.if n \{\ +. ds #H 0 +. ds #V .8m +. ds #F .3m +. ds #[ \f1 +. ds #] \fP +.\} +.if t \{\ +. ds #H ((1u-(\\\\n(.fu%2u))*.13m) +. ds #V .6m +. ds #F 0 +. ds #[ \& +. ds #] \& +.\} +. \" simple accents for nroff and troff +.if n \{\ +. ds ' \& +. ds ` \& +. ds ^ \& +. ds , \& +. ds ~ ~ +. ds / +.\} +.if t \{\ +. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" +. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' +. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' +. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' +. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' +. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' +.\} +. \" troff and (daisy-wheel) nroff accents +.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' +.ds 8 \h'\*(#H'\(*b\h'-\*(#H' +.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] +.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' +.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' +.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] +.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] +.ds ae a\h'-(\w'a'u*4/10)'e +.ds Ae A\h'-(\w'A'u*4/10)'E +. \" corrections for vroff +.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' +.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' +. \" for low resolution devices (crt and lpr) +.if \n(.H>23 .if \n(.V>19 \ +\{\ +. ds : e +. ds 8 ss +. ds o a +. ds d- d\h'-1'\(ga +. ds D- D\h'-1'\(hy +. ds th \o'bp' +. ds Th \o'LP' +. ds ae ae +. ds Ae AE +.\} +.rm #[ #] #H #V #F C +.\" ======================================================================== +.\" +.IX Title "LIBEIO 3" +.TH LIBEIO 3 "2008-05-11" "libeio-1.0" "libeio - truly asynchronous POSIX I/O" +.\" For nroff, turn off justification. Always turn off hyphenation; it makes +.\" way too many mistakes in technical documents. +.if n .ad l +.nh +.SH "NAME" +libev \- a high performance full\-featured event loop written in C +.SH "SYNOPSIS" +.IX Header "SYNOPSIS" +.Vb 1 +\& #include +.Ve +.Sh "\s-1EXAMPLE\s0 \s-1PROGRAM\s0" +.IX Subsection "EXAMPLE PROGRAM" +.Vb 2 +\& // a single header file is required +\& #include +\& +\& // every watcher type has its own typedef\*(Aqd struct +\& // with the name ev_ +\& ev_io stdin_watcher; +\& ev_timer timeout_watcher; +\& +\& // all watcher callbacks have a similar signature +\& // this callback is called when data is readable on stdin +\& static void +\& stdin_cb (EV_P_ struct ev_io *w, int revents) +\& { +\& puts ("stdin ready"); +\& // for one\-shot events, one must manually stop the watcher +\& // with its corresponding stop function. +\& ev_io_stop (EV_A_ w); +\& +\& // this causes all nested ev_loop\*(Aqs to stop iterating +\& ev_unloop (EV_A_ EVUNLOOP_ALL); +\& } +\& +\& // another callback, this time for a time\-out +\& static void +\& timeout_cb (EV_P_ struct ev_timer *w, int revents) +\& { +\& puts ("timeout"); +\& // this causes the innermost ev_loop to stop iterating +\& ev_unloop (EV_A_ EVUNLOOP_ONE); +\& } +\& +\& int +\& main (void) +\& { +\& // use the default event loop unless you have special needs +\& struct ev_loop *loop = ev_default_loop (0); +\& +\& // initialise an io watcher, then start it +\& // this one will watch for stdin to become readable +\& ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ); +\& ev_io_start (loop, &stdin_watcher); +\& +\& // initialise a timer watcher, then start it +\& // simple non\-repeating 5.5 second timeout +\& ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); +\& ev_timer_start (loop, &timeout_watcher); +\& +\& // now wait for events to arrive +\& ev_loop (loop, 0); +\& +\& // unloop was called, so exit +\& return 0; +\& } +.Ve +.SH "DESCRIPTION" +.IX Header "DESCRIPTION" +The newest version of this document is also available as an html-formatted +web page you might find easier to navigate when reading it for the first +time: . +.PP +Libev is an event loop: you register interest in certain events (such as a +file descriptor being readable or a timeout occurring), and it will manage +these event sources and provide your program with events. +.PP +To do this, it must take more or less complete control over your process +(or thread) by executing the \fIevent loop\fR handler, and will then +communicate events via a callback mechanism. +.PP +You register interest in certain events by registering so-called \fIevent +watchers\fR, which are relatively small C structures you initialise with the +details of the event, and then hand it over to libev by \fIstarting\fR the +watcher. +.Sh "\s-1FEATURES\s0" +.IX Subsection "FEATURES" +Libev supports \f(CW\*(C`select\*(C'\fR, \f(CW\*(C`poll\*(C'\fR, the Linux-specific \f(CW\*(C`epoll\*(C'\fR, the +BSD-specific \f(CW\*(C`kqueue\*(C'\fR and the Solaris-specific event port mechanisms +for file descriptor events (\f(CW\*(C`ev_io\*(C'\fR), the Linux \f(CW\*(C`inotify\*(C'\fR interface +(for \f(CW\*(C`ev_stat\*(C'\fR), relative timers (\f(CW\*(C`ev_timer\*(C'\fR), absolute timers +with customised rescheduling (\f(CW\*(C`ev_periodic\*(C'\fR), synchronous signals +(\f(CW\*(C`ev_signal\*(C'\fR), process status change events (\f(CW\*(C`ev_child\*(C'\fR), and event +watchers dealing with the event loop mechanism itself (\f(CW\*(C`ev_idle\*(C'\fR, +\&\f(CW\*(C`ev_embed\*(C'\fR, \f(CW\*(C`ev_prepare\*(C'\fR and \f(CW\*(C`ev_check\*(C'\fR watchers) as well as +file watchers (\f(CW\*(C`ev_stat\*(C'\fR) and even limited support for fork events +(\f(CW\*(C`ev_fork\*(C'\fR). +.PP +It also is quite fast (see this +benchmark comparing it to libevent +for example). +.Sh "\s-1CONVENTIONS\s0" +.IX Subsection "CONVENTIONS" +Libev is very configurable. In this manual the default (and most common) +configuration will be described, which supports multiple event loops. For +more info about various configuration options please have a look at +\&\fB\s-1EMBED\s0\fR section in this manual. If libev was configured without support +for multiple event loops, then all functions taking an initial argument of +name \f(CW\*(C`loop\*(C'\fR (which is always of type \f(CW\*(C`struct ev_loop *\*(C'\fR) will not have +this argument. +.Sh "\s-1TIME\s0 \s-1REPRESENTATION\s0" +.IX Subsection "TIME REPRESENTATION" +Libev represents time as a single floating point number, representing the +(fractional) number of seconds since the (\s-1POSIX\s0) epoch (somewhere near +the beginning of 1970, details are complicated, don't ask). This type is +called \f(CW\*(C`ev_tstamp\*(C'\fR, which is what you should use too. It usually aliases +to the \f(CW\*(C`double\*(C'\fR type in C, and when you need to do any calculations on +it, you should treat it as some floatingpoint value. Unlike the name +component \f(CW\*(C`stamp\*(C'\fR might indicate, it is also used for time differences +throughout libev. +.SH "GLOBAL FUNCTIONS" +.IX Header "GLOBAL FUNCTIONS" +These functions can be called anytime, even before initialising the +library in any way. +.IP "ev_tstamp ev_time ()" 4 +.IX Item "ev_tstamp ev_time ()" +Returns the current time as libev would use it. Please note that the +\&\f(CW\*(C`ev_now\*(C'\fR function is usually faster and also often returns the timestamp +you actually want to know. +.IP "ev_sleep (ev_tstamp interval)" 4 +.IX Item "ev_sleep (ev_tstamp interval)" +Sleep for the given interval: The current thread will be blocked until +either it is interrupted or the given time interval has passed. Basically +this is a subsecond-resolution \f(CW\*(C`sleep ()\*(C'\fR. +.IP "int ev_version_major ()" 4 +.IX Item "int ev_version_major ()" +.PD 0 +.IP "int ev_version_minor ()" 4 +.IX Item "int ev_version_minor ()" +.PD +You can find out the major and minor \s-1ABI\s0 version numbers of the library +you linked against by calling the functions \f(CW\*(C`ev_version_major\*(C'\fR and +\&\f(CW\*(C`ev_version_minor\*(C'\fR. If you want, you can compare against the global +symbols \f(CW\*(C`EV_VERSION_MAJOR\*(C'\fR and \f(CW\*(C`EV_VERSION_MINOR\*(C'\fR, which specify the +version of the library your program was compiled against. +.Sp +These version numbers refer to the \s-1ABI\s0 version of the library, not the +release version. +.Sp +Usually, it's a good idea to terminate if the major versions mismatch, +as this indicates an incompatible change. Minor versions are usually +compatible to older versions, so a larger minor version alone is usually +not a problem. +.Sp +Example: Make sure we haven't accidentally been linked against the wrong +version. +.Sp +.Vb 3 +\& assert (("libev version mismatch", +\& ev_version_major () == EV_VERSION_MAJOR +\& && ev_version_minor () >= EV_VERSION_MINOR)); +.Ve +.IP "unsigned int ev_supported_backends ()" 4 +.IX Item "unsigned int ev_supported_backends ()" +Return the set of all backends (i.e. their corresponding \f(CW\*(C`EV_BACKEND_*\*(C'\fR +value) compiled into this binary of libev (independent of their +availability on the system you are running on). See \f(CW\*(C`ev_default_loop\*(C'\fR for +a description of the set values. +.Sp +Example: make sure we have the epoll method, because yeah this is cool and +a must have and can we have a torrent of it please!!!11 +.Sp +.Vb 2 +\& assert (("sorry, no epoll, no sex", +\& ev_supported_backends () & EVBACKEND_EPOLL)); +.Ve +.IP "unsigned int ev_recommended_backends ()" 4 +.IX Item "unsigned int ev_recommended_backends ()" +Return the set of all backends compiled into this binary of libev and also +recommended for this platform. This set is often smaller than the one +returned by \f(CW\*(C`ev_supported_backends\*(C'\fR, as for example kqueue is broken on +most BSDs and will not be autodetected unless you explicitly request it +(assuming you know what you are doing). This is the set of backends that +libev will probe for if you specify no backends explicitly. +.IP "unsigned int ev_embeddable_backends ()" 4 +.IX Item "unsigned int ev_embeddable_backends ()" +Returns the set of backends that are embeddable in other event loops. This +is the theoretical, all-platform, value. To find which backends +might be supported on the current system, you would need to look at +\&\f(CW\*(C`ev_embeddable_backends () & ev_supported_backends ()\*(C'\fR, likewise for +recommended ones. +.Sp +See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. +.IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4 +.IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))" +Sets the allocation function to use (the prototype is similar \- the +semantics are identical to the \f(CW\*(C`realloc\*(C'\fR C89/SuS/POSIX function). It is +used to allocate and free memory (no surprises here). If it returns zero +when memory needs to be allocated (\f(CW\*(C`size != 0\*(C'\fR), the library might abort +or take some potentially destructive action. +.Sp +Since some systems (at least OpenBSD and Darwin) fail to implement +correct \f(CW\*(C`realloc\*(C'\fR semantics, libev will use a wrapper around the system +\&\f(CW\*(C`realloc\*(C'\fR and \f(CW\*(C`free\*(C'\fR functions by default. +.Sp +You could override this function in high-availability programs to, say, +free some memory if it cannot allocate memory, to use a special allocator, +or even to sleep a while and retry until some memory is available. +.Sp +Example: Replace the libev allocator with one that waits a bit and then +retries (example requires a standards-compliant \f(CW\*(C`realloc\*(C'\fR). +.Sp +.Vb 6 +\& static void * +\& persistent_realloc (void *ptr, size_t size) +\& { +\& for (;;) +\& { +\& void *newptr = realloc (ptr, size); +\& +\& if (newptr) +\& return newptr; +\& +\& sleep (60); +\& } +\& } +\& +\& ... +\& ev_set_allocator (persistent_realloc); +.Ve +.IP "ev_set_syserr_cb (void (*cb)(const char *msg));" 4 +.IX Item "ev_set_syserr_cb (void (*cb)(const char *msg));" +Set the callback function to call on a retryable syscall error (such +as failed select, poll, epoll_wait). The message is a printable string +indicating the system call or subsystem causing the problem. If this +callback is set, then libev will expect it to remedy the sitution, no +matter what, when it returns. That is, libev will generally retry the +requested operation, or, if the condition doesn't go away, do bad stuff +(such as abort). +.Sp +Example: This is basically the same thing that libev does internally, too. +.Sp +.Vb 6 +\& static void +\& fatal_error (const char *msg) +\& { +\& perror (msg); +\& abort (); +\& } +\& +\& ... +\& ev_set_syserr_cb (fatal_error); +.Ve +.SH "FUNCTIONS CONTROLLING THE EVENT LOOP" +.IX Header "FUNCTIONS CONTROLLING THE EVENT LOOP" +An event loop is described by a \f(CW\*(C`struct ev_loop *\*(C'\fR. The library knows two +types of such loops, the \fIdefault\fR loop, which supports signals and child +events, and dynamically created loops which do not. +.IP "struct ev_loop *ev_default_loop (unsigned int flags)" 4 +.IX Item "struct ev_loop *ev_default_loop (unsigned int flags)" +This will initialise the default event loop if it hasn't been initialised +yet and return it. If the default loop could not be initialised, returns +false. If it already was initialised it simply returns it (and ignores the +flags. If that is troubling you, check \f(CW\*(C`ev_backend ()\*(C'\fR afterwards). +.Sp +If you don't know what event loop to use, use the one returned from this +function. +.Sp +Note that this function is \fInot\fR thread-safe, so if you want to use it +from multiple threads, you have to lock (note also that this is unlikely, +as loops cannot bes hared easily between threads anyway). +.Sp +The default loop is the only loop that can handle \f(CW\*(C`ev_signal\*(C'\fR and +\&\f(CW\*(C`ev_child\*(C'\fR watchers, and to do this, it always registers a handler +for \f(CW\*(C`SIGCHLD\*(C'\fR. If this is a problem for your app you can either +create a dynamic loop with \f(CW\*(C`ev_loop_new\*(C'\fR that doesn't do that, or you +can simply overwrite the \f(CW\*(C`SIGCHLD\*(C'\fR signal handler \fIafter\fR calling +\&\f(CW\*(C`ev_default_init\*(C'\fR. +.Sp +The flags argument can be used to specify special behaviour or specific +backends to use, and is usually specified as \f(CW0\fR (or \f(CW\*(C`EVFLAG_AUTO\*(C'\fR). +.Sp +The following flags are supported: +.RS 4 +.ie n .IP """EVFLAG_AUTO""" 4 +.el .IP "\f(CWEVFLAG_AUTO\fR" 4 +.IX Item "EVFLAG_AUTO" +The default flags value. Use this if you have no clue (it's the right +thing, believe me). +.ie n .IP """EVFLAG_NOENV""" 4 +.el .IP "\f(CWEVFLAG_NOENV\fR" 4 +.IX Item "EVFLAG_NOENV" +If this flag bit is ored into the flag value (or the program runs setuid +or setgid) then libev will \fInot\fR look at the environment variable +\&\f(CW\*(C`LIBEV_FLAGS\*(C'\fR. Otherwise (the default), this environment variable will +override the flags completely if it is found in the environment. This is +useful to try out specific backends to test their performance, or to work +around bugs. +.ie n .IP """EVFLAG_FORKCHECK""" 4 +.el .IP "\f(CWEVFLAG_FORKCHECK\fR" 4 +.IX Item "EVFLAG_FORKCHECK" +Instead of calling \f(CW\*(C`ev_default_fork\*(C'\fR or \f(CW\*(C`ev_loop_fork\*(C'\fR manually after +a fork, you can also make libev check for a fork in each iteration by +enabling this flag. +.Sp +This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop, +and thus this might slow down your event loop if you do a lot of loop +iterations and little real work, but is usually not noticeable (on my +GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn sequence +without a syscall and thus \fIvery\fR fast, but my GNU/Linux system also has +\&\f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). +.Sp +The big advantage of this flag is that you can forget about fork (and +forget about forgetting to tell libev about forking) when you use this +flag. +.Sp +This flag setting cannot be overriden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR +environment variable. +.ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4 +.el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4 +.IX Item "EVBACKEND_SELECT (value 1, portable select backend)" +This is your standard \fIselect\fR\|(2) backend. Not \fIcompletely\fR standard, as +libev tries to roll its own fd_set with no limits on the number of fds, +but if that fails, expect a fairly low limit on the number of fds when +using this backend. It doesn't scale too well (O(highest_fd)), but its +usually the fastest backend for a low number of (low-numbered :) fds. +.Sp +To get good performance out of this backend you need a high amount of +parallelity (most of the file descriptors should be busy). If you are +writing a server, you should \f(CW\*(C`accept ()\*(C'\fR in a loop to accept as many +connections as possible during one iteration. You might also want to have +a look at \f(CW\*(C`ev_set_io_collect_interval ()\*(C'\fR to increase the amount of +readyness notifications you get per iteration. +.ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4 +.el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4 +.IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)" +And this is your standard \fIpoll\fR\|(2) backend. It's more complicated +than select, but handles sparse fds better and has no artificial +limit on the number of fds you can use (except it will slow down +considerably with a lot of inactive fds). It scales similarly to select, +i.e. O(total_fds). See the entry for \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR, above, for +performance tips. +.ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 +.el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 +.IX Item "EVBACKEND_EPOLL (value 4, Linux)" +For few fds, this backend is a bit little slower than poll and select, +but it scales phenomenally better. While poll and select usually scale +like O(total_fds) where n is the total number of fds (or the highest fd), +epoll scales either O(1) or O(active_fds). The epoll design has a number +of shortcomings, such as silently dropping events in some hard-to-detect +cases and requiring a syscall per fd change, no fork support and bad +support for dup. +.Sp +While stopping, setting and starting an I/O watcher in the same iteration +will result in some caching, there is still a syscall per such incident +(because the fd could point to a different file description now), so its +best to avoid that. Also, \f(CW\*(C`dup ()\*(C'\fR'ed file descriptors might not work +very well if you register events for both fds. +.Sp +Please note that epoll sometimes generates spurious notifications, so you +need to use non-blocking I/O or other means to avoid blocking when no data +(or space) is available. +.Sp +Best performance from this backend is achieved by not unregistering all +watchers for a file descriptor until it has been closed, if possible, i.e. +keep at least one watcher active per fd at all times. +.Sp +While nominally embeddeble in other event loops, this feature is broken in +all kernel versions tested so far. +.ie n .IP """EVBACKEND_KQUEUE"" (value 8, most \s-1BSD\s0 clones)" 4 +.el .IP "\f(CWEVBACKEND_KQUEUE\fR (value 8, most \s-1BSD\s0 clones)" 4 +.IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)" +Kqueue deserves special mention, as at the time of this writing, it +was broken on all BSDs except NetBSD (usually it doesn't work reliably +with anything but sockets and pipes, except on Darwin, where of course +it's completely useless). For this reason it's not being \*(L"autodetected\*(R" +unless you explicitly specify it explicitly in the flags (i.e. using +\&\f(CW\*(C`EVBACKEND_KQUEUE\*(C'\fR) or libev was compiled on a known-to-be-good (\-enough) +system like NetBSD. +.Sp +You still can embed kqueue into a normal poll or select backend and use it +only for sockets (after having made sure that sockets work with kqueue on +the target platform). See \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. +.Sp +It scales in the same way as the epoll backend, but the interface to the +kernel is more efficient (which says nothing about its actual speed, of +course). While stopping, setting and starting an I/O watcher does never +cause an extra syscall as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to +two event changes per incident, support for \f(CW\*(C`fork ()\*(C'\fR is very bad and it +drops fds silently in similarly hard-to-detect cases. +.Sp +This backend usually performs well under most conditions. +.Sp +While nominally embeddable in other event loops, this doesn't work +everywhere, so you might need to test for this. And since it is broken +almost everywhere, you should only use it when you have a lot of sockets +(for which it usually works), by embedding it into another event loop +(e.g. \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR) and using it only for +sockets. +.ie n .IP """EVBACKEND_DEVPOLL"" (value 16, Solaris 8)" 4 +.el .IP "\f(CWEVBACKEND_DEVPOLL\fR (value 16, Solaris 8)" 4 +.IX Item "EVBACKEND_DEVPOLL (value 16, Solaris 8)" +This is not implemented yet (and might never be, unless you send me an +implementation). According to reports, \f(CW\*(C`/dev/poll\*(C'\fR only supports sockets +and is not embeddable, which would limit the usefulness of this backend +immensely. +.ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4 +.el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4 +.IX Item "EVBACKEND_PORT (value 32, Solaris 10)" +This uses the Solaris 10 event port mechanism. As with everything on Solaris, +it's really slow, but it still scales very well (O(active_fds)). +.Sp +Please note that solaris event ports can deliver a lot of spurious +notifications, so you need to use non-blocking I/O or other means to avoid +blocking when no data (or space) is available. +.Sp +While this backend scales well, it requires one system call per active +file descriptor per loop iteration. For small and medium numbers of file +descriptors a \*(L"slow\*(R" \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR backend +might perform better. +.Sp +On the positive side, ignoring the spurious readyness notifications, this +backend actually performed to specification in all tests and is fully +embeddable, which is a rare feat among the OS-specific backends. +.ie n .IP """EVBACKEND_ALL""" 4 +.el .IP "\f(CWEVBACKEND_ALL\fR" 4 +.IX Item "EVBACKEND_ALL" +Try all backends (even potentially broken ones that wouldn't be tried +with \f(CW\*(C`EVFLAG_AUTO\*(C'\fR). Since this is a mask, you can do stuff such as +\&\f(CW\*(C`EVBACKEND_ALL & ~EVBACKEND_KQUEUE\*(C'\fR. +.Sp +It is definitely not recommended to use this flag. +.RE +.RS 4 +.Sp +If one or more of these are ored into the flags value, then only these +backends will be tried (in the reverse order as listed here). If none are +specified, all backends in \f(CW\*(C`ev_recommended_backends ()\*(C'\fR will be tried. +.Sp +The most typical usage is like this: +.Sp +.Vb 2 +\& if (!ev_default_loop (0)) +\& fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?"); +.Ve +.Sp +Restrict libev to the select and poll backends, and do not allow +environment settings to be taken into account: +.Sp +.Vb 1 +\& ev_default_loop (EVBACKEND_POLL | EVBACKEND_SELECT | EVFLAG_NOENV); +.Ve +.Sp +Use whatever libev has to offer, but make sure that kqueue is used if +available (warning, breaks stuff, best use only with your own private +event loop and only if you know the \s-1OS\s0 supports your types of fds): +.Sp +.Vb 1 +\& ev_default_loop (ev_recommended_backends () | EVBACKEND_KQUEUE); +.Ve +.RE +.IP "struct ev_loop *ev_loop_new (unsigned int flags)" 4 +.IX Item "struct ev_loop *ev_loop_new (unsigned int flags)" +Similar to \f(CW\*(C`ev_default_loop\*(C'\fR, but always creates a new event loop that is +always distinct from the default loop. Unlike the default loop, it cannot +handle signal and child watchers, and attempts to do so will be greeted by +undefined behaviour (or a failed assertion if assertions are enabled). +.Sp +Note that this function \fIis\fR thread-safe, and the recommended way to use +libev with threads is indeed to create one loop per thread, and using the +default loop in the \*(L"main\*(R" or \*(L"initial\*(R" thread. +.Sp +Example: Try to create a event loop that uses epoll and nothing else. +.Sp +.Vb 3 +\& struct ev_loop *epoller = ev_loop_new (EVBACKEND_EPOLL | EVFLAG_NOENV); +\& if (!epoller) +\& fatal ("no epoll found here, maybe it hides under your chair"); +.Ve +.IP "ev_default_destroy ()" 4 +.IX Item "ev_default_destroy ()" +Destroys the default loop again (frees all memory and kernel state +etc.). None of the active event watchers will be stopped in the normal +sense, so e.g. \f(CW\*(C`ev_is_active\*(C'\fR might still return true. It is your +responsibility to either stop all watchers cleanly yoursef \fIbefore\fR +calling this function, or cope with the fact afterwards (which is usually +the easiest thing, you can just ignore the watchers and/or \f(CW\*(C`free ()\*(C'\fR them +for example). +.Sp +Note that certain global state, such as signal state, will not be freed by +this function, and related watchers (such as signal and child watchers) +would need to be stopped manually. +.Sp +In general it is not advisable to call this function except in the +rare occasion where you really need to free e.g. the signal handling +pipe fds. If you need dynamically allocated loops it is better to use +\&\f(CW\*(C`ev_loop_new\*(C'\fR and \f(CW\*(C`ev_loop_destroy\*(C'\fR). +.IP "ev_loop_destroy (loop)" 4 +.IX Item "ev_loop_destroy (loop)" +Like \f(CW\*(C`ev_default_destroy\*(C'\fR, but destroys an event loop created by an +earlier call to \f(CW\*(C`ev_loop_new\*(C'\fR. +.IP "ev_default_fork ()" 4 +.IX Item "ev_default_fork ()" +This function sets a flag that causes subsequent \f(CW\*(C`ev_loop\*(C'\fR iterations +to reinitialise the kernel state for backends that have one. Despite the +name, you can call it anytime, but it makes most sense after forking, in +the child process (or both child and parent, but that again makes little +sense). You \fImust\fR call it in the child before using any of the libev +functions, and it will only take effect at the next \f(CW\*(C`ev_loop\*(C'\fR iteration. +.Sp +On the other hand, you only need to call this function in the child +process if and only if you want to use the event library in the child. If +you just fork+exec, you don't have to call it at all. +.Sp +The function itself is quite fast and it's usually not a problem to call +it just in case after a fork. To make this easy, the function will fit in +quite nicely into a call to \f(CW\*(C`pthread_atfork\*(C'\fR: +.Sp +.Vb 1 +\& pthread_atfork (0, 0, ev_default_fork); +.Ve +.IP "ev_loop_fork (loop)" 4 +.IX Item "ev_loop_fork (loop)" +Like \f(CW\*(C`ev_default_fork\*(C'\fR, but acts on an event loop created by +\&\f(CW\*(C`ev_loop_new\*(C'\fR. Yes, you have to call this on every allocated event loop +after fork, and how you do this is entirely your own problem. +.IP "int ev_is_default_loop (loop)" 4 +.IX Item "int ev_is_default_loop (loop)" +Returns true when the given loop actually is the default loop, false otherwise. +.IP "unsigned int ev_loop_count (loop)" 4 +.IX Item "unsigned int ev_loop_count (loop)" +Returns the count of loop iterations for the loop, which is identical to +the number of times libev did poll for new events. It starts at \f(CW0\fR and +happily wraps around with enough iterations. +.Sp +This value can sometimes be useful as a generation counter of sorts (it +\&\*(L"ticks\*(R" the number of loop iterations), as it roughly corresponds with +\&\f(CW\*(C`ev_prepare\*(C'\fR and \f(CW\*(C`ev_check\*(C'\fR calls. +.IP "unsigned int ev_backend (loop)" 4 +.IX Item "unsigned int ev_backend (loop)" +Returns one of the \f(CW\*(C`EVBACKEND_*\*(C'\fR flags indicating the event backend in +use. +.IP "ev_tstamp ev_now (loop)" 4 +.IX Item "ev_tstamp ev_now (loop)" +Returns the current \*(L"event loop time\*(R", which is the time the event loop +received events and started processing them. This timestamp does not +change as long as callbacks are being processed, and this is also the base +time used for relative timers. You can treat it as the timestamp of the +event occurring (or more correctly, libev finding out about it). +.IP "ev_loop (loop, int flags)" 4 +.IX Item "ev_loop (loop, int flags)" +Finally, this is it, the event handler. This function usually is called +after you initialised all your watchers and you want to start handling +events. +.Sp +If the flags argument is specified as \f(CW0\fR, it will not return until +either no event watchers are active anymore or \f(CW\*(C`ev_unloop\*(C'\fR was called. +.Sp +Please note that an explicit \f(CW\*(C`ev_unloop\*(C'\fR is usually better than +relying on all watchers to be stopped when deciding when a program has +finished (especially in interactive programs), but having a program that +automatically loops as long as it has to and no longer by virtue of +relying on its watchers stopping correctly is a thing of beauty. +.Sp +A flags value of \f(CW\*(C`EVLOOP_NONBLOCK\*(C'\fR will look for new events, will handle +those events and any outstanding ones, but will not block your process in +case there are no events and will return after one iteration of the loop. +.Sp +A flags value of \f(CW\*(C`EVLOOP_ONESHOT\*(C'\fR will look for new events (waiting if +neccessary) and will handle those and any outstanding ones. It will block +your process until at least one new event arrives, and will return after +one iteration of the loop. This is useful if you are waiting for some +external event in conjunction with something not expressible using other +libev watchers. However, a pair of \f(CW\*(C`ev_prepare\*(C'\fR/\f(CW\*(C`ev_check\*(C'\fR watchers is +usually a better approach for this kind of thing. +.Sp +Here are the gory details of what \f(CW\*(C`ev_loop\*(C'\fR does: +.Sp +.Vb 10 +\& \- Before the first iteration, call any pending watchers. +\& * If EVFLAG_FORKCHECK was used, check for a fork. +\& \- If a fork was detected, queue and call all fork watchers. +\& \- Queue and call all prepare watchers. +\& \- If we have been forked, recreate the kernel state. +\& \- Update the kernel state with all outstanding changes. +\& \- Update the "event loop time". +\& \- Calculate for how long to sleep or block, if at all +\& (active idle watchers, EVLOOP_NONBLOCK or not having +\& any active watchers at all will result in not sleeping). +\& \- Sleep if the I/O and timer collect interval say so. +\& \- Block the process, waiting for any events. +\& \- Queue all outstanding I/O (fd) events. +\& \- Update the "event loop time" and do time jump handling. +\& \- Queue all outstanding timers. +\& \- Queue all outstanding periodics. +\& \- If no events are pending now, queue all idle watchers. +\& \- Queue all check watchers. +\& \- Call all queued watchers in reverse order (i.e. check watchers first). +\& Signals and child watchers are implemented as I/O watchers, and will +\& be handled here by queueing them when their watcher gets executed. +\& \- If ev_unloop has been called, or EVLOOP_ONESHOT or EVLOOP_NONBLOCK +\& were used, or there are no active watchers, return, otherwise +\& continue with step *. +.Ve +.Sp +Example: Queue some jobs and then loop until no events are outstanding +anymore. +.Sp +.Vb 4 +\& ... queue jobs here, make sure they register event watchers as long +\& ... as they still have work to do (even an idle watcher will do..) +\& ev_loop (my_loop, 0); +\& ... jobs done. yeah! +.Ve +.IP "ev_unloop (loop, how)" 4 +.IX Item "ev_unloop (loop, how)" +Can be used to make a call to \f(CW\*(C`ev_loop\*(C'\fR return early (but only after it +has processed all outstanding events). The \f(CW\*(C`how\*(C'\fR argument must be either +\&\f(CW\*(C`EVUNLOOP_ONE\*(C'\fR, which will make the innermost \f(CW\*(C`ev_loop\*(C'\fR call return, or +\&\f(CW\*(C`EVUNLOOP_ALL\*(C'\fR, which will make all nested \f(CW\*(C`ev_loop\*(C'\fR calls return. +.Sp +This \*(L"unloop state\*(R" will be cleared when entering \f(CW\*(C`ev_loop\*(C'\fR again. +.IP "ev_ref (loop)" 4 +.IX Item "ev_ref (loop)" +.PD 0 +.IP "ev_unref (loop)" 4 +.IX Item "ev_unref (loop)" +.PD +Ref/unref can be used to add or remove a reference count on the event +loop: Every watcher keeps one reference, and as long as the reference +count is nonzero, \f(CW\*(C`ev_loop\*(C'\fR will not return on its own. If you have +a watcher you never unregister that should not keep \f(CW\*(C`ev_loop\*(C'\fR from +returning, \fIev_unref()\fR after starting, and \fIev_ref()\fR before stopping it. For +example, libev itself uses this for its internal signal pipe: It is not +visible to the libev user and should not keep \f(CW\*(C`ev_loop\*(C'\fR from exiting if +no event watchers registered by it are active. It is also an excellent +way to do this for generic recurring timers or from within third-party +libraries. Just remember to \fIunref after start\fR and \fIref before stop\fR +(but only if the watcher wasn't active before, or was active before, +respectively). +.Sp +Example: Create a signal watcher, but keep it from keeping \f(CW\*(C`ev_loop\*(C'\fR +running when nothing else is active. +.Sp +.Vb 4 +\& struct ev_signal exitsig; +\& ev_signal_init (&exitsig, sig_cb, SIGINT); +\& ev_signal_start (loop, &exitsig); +\& evf_unref (loop); +.Ve +.Sp +Example: For some weird reason, unregister the above signal handler again. +.Sp +.Vb 2 +\& ev_ref (loop); +\& ev_signal_stop (loop, &exitsig); +.Ve +.IP "ev_set_io_collect_interval (loop, ev_tstamp interval)" 4 +.IX Item "ev_set_io_collect_interval (loop, ev_tstamp interval)" +.PD 0 +.IP "ev_set_timeout_collect_interval (loop, ev_tstamp interval)" 4 +.IX Item "ev_set_timeout_collect_interval (loop, ev_tstamp interval)" +.PD +These advanced functions influence the time that libev will spend waiting +for events. Both are by default \f(CW0\fR, meaning that libev will try to +invoke timer/periodic callbacks and I/O callbacks with minimum latency. +.Sp +Setting these to a higher value (the \f(CW\*(C`interval\*(C'\fR \fImust\fR be >= \f(CW0\fR) +allows libev to delay invocation of I/O and timer/periodic callbacks to +increase efficiency of loop iterations. +.Sp +The background is that sometimes your program runs just fast enough to +handle one (or very few) event(s) per loop iteration. While this makes +the program responsive, it also wastes a lot of \s-1CPU\s0 time to poll for new +events, especially with backends like \f(CW\*(C`select ()\*(C'\fR which have a high +overhead for the actual polling but can deliver many events at once. +.Sp +By setting a higher \fIio collect interval\fR you allow libev to spend more +time collecting I/O events, so you can handle more events per iteration, +at the cost of increasing latency. Timeouts (both \f(CW\*(C`ev_periodic\*(C'\fR and +\&\f(CW\*(C`ev_timer\*(C'\fR) will be not affected. Setting this to a non-null value will +introduce an additional \f(CW\*(C`ev_sleep ()\*(C'\fR call into most loop iterations. +.Sp +Likewise, by setting a higher \fItimeout collect interval\fR you allow libev +to spend more time collecting timeouts, at the expense of increased +latency (the watcher callback will be called later). \f(CW\*(C`ev_io\*(C'\fR watchers +will not be affected. Setting this to a non-null value will not introduce +any overhead in libev. +.Sp +Many (busy) programs can usually benefit by setting the io collect +interval to a value near \f(CW0.1\fR or so, which is often enough for +interactive servers (of course not for games), likewise for timeouts. It +usually doesn't make much sense to set it to a lower value than \f(CW0.01\fR, +as this approsaches the timing granularity of most systems. +.SH "ANATOMY OF A WATCHER" +.IX Header "ANATOMY OF A WATCHER" +A watcher is a structure that you create and register to record your +interest in some event. For instance, if you want to wait for \s-1STDIN\s0 to +become readable, you would create an \f(CW\*(C`ev_io\*(C'\fR watcher for that: +.PP +.Vb 5 +\& static void my_cb (struct ev_loop *loop, struct ev_io *w, int revents) +\& { +\& ev_io_stop (w); +\& ev_unloop (loop, EVUNLOOP_ALL); +\& } +\& +\& struct ev_loop *loop = ev_default_loop (0); +\& struct ev_io stdin_watcher; +\& ev_init (&stdin_watcher, my_cb); +\& ev_io_set (&stdin_watcher, STDIN_FILENO, EV_READ); +\& ev_io_start (loop, &stdin_watcher); +\& ev_loop (loop, 0); +.Ve +.PP +As you can see, you are responsible for allocating the memory for your +watcher structures (and it is usually a bad idea to do this on the stack, +although this can sometimes be quite valid). +.PP +Each watcher structure must be initialised by a call to \f(CW\*(C`ev_init +(watcher *, callback)\*(C'\fR, which expects a callback to be provided. This +callback gets invoked each time the event occurs (or, in the case of io +watchers, each time the event loop detects that the file descriptor given +is readable and/or writable). +.PP +Each watcher type has its own \f(CW\*(C`ev__set (watcher *, ...)\*(C'\fR macro +with arguments specific to this watcher type. There is also a macro +to combine initialisation and setting in one call: \f(CW\*(C`ev__init +(watcher *, callback, ...)\*(C'\fR. +.PP +To make the watcher actually watch out for events, you have to start it +with a watcher-specific start function (\f(CW\*(C`ev__start (loop, watcher +*)\*(C'\fR), and you can stop watching for events at any time by calling the +corresponding stop function (\f(CW\*(C`ev__stop (loop, watcher *)\*(C'\fR. +.PP +As long as your watcher is active (has been started but not stopped) you +must not touch the values stored in it. Most specifically you must never +reinitialise it or call its \f(CW\*(C`set\*(C'\fR macro. +.PP +Each and every callback receives the event loop pointer as first, the +registered watcher structure as second, and a bitset of received events as +third argument. +.PP +The received events usually include a single bit per event type received +(you can receive multiple events at the same time). The possible bit masks +are: +.ie n .IP """EV_READ""" 4 +.el .IP "\f(CWEV_READ\fR" 4 +.IX Item "EV_READ" +.PD 0 +.ie n .IP """EV_WRITE""" 4 +.el .IP "\f(CWEV_WRITE\fR" 4 +.IX Item "EV_WRITE" +.PD +The file descriptor in the \f(CW\*(C`ev_io\*(C'\fR watcher has become readable and/or +writable. +.ie n .IP """EV_TIMEOUT""" 4 +.el .IP "\f(CWEV_TIMEOUT\fR" 4 +.IX Item "EV_TIMEOUT" +The \f(CW\*(C`ev_timer\*(C'\fR watcher has timed out. +.ie n .IP """EV_PERIODIC""" 4 +.el .IP "\f(CWEV_PERIODIC\fR" 4 +.IX Item "EV_PERIODIC" +The \f(CW\*(C`ev_periodic\*(C'\fR watcher has timed out. +.ie n .IP """EV_SIGNAL""" 4 +.el .IP "\f(CWEV_SIGNAL\fR" 4 +.IX Item "EV_SIGNAL" +The signal specified in the \f(CW\*(C`ev_signal\*(C'\fR watcher has been received by a thread. +.ie n .IP """EV_CHILD""" 4 +.el .IP "\f(CWEV_CHILD\fR" 4 +.IX Item "EV_CHILD" +The pid specified in the \f(CW\*(C`ev_child\*(C'\fR watcher has received a status change. +.ie n .IP """EV_STAT""" 4 +.el .IP "\f(CWEV_STAT\fR" 4 +.IX Item "EV_STAT" +The path specified in the \f(CW\*(C`ev_stat\*(C'\fR watcher changed its attributes somehow. +.ie n .IP """EV_IDLE""" 4 +.el .IP "\f(CWEV_IDLE\fR" 4 +.IX Item "EV_IDLE" +The \f(CW\*(C`ev_idle\*(C'\fR watcher has determined that you have nothing better to do. +.ie n .IP """EV_PREPARE""" 4 +.el .IP "\f(CWEV_PREPARE\fR" 4 +.IX Item "EV_PREPARE" +.PD 0 +.ie n .IP """EV_CHECK""" 4 +.el .IP "\f(CWEV_CHECK\fR" 4 +.IX Item "EV_CHECK" +.PD +All \f(CW\*(C`ev_prepare\*(C'\fR watchers are invoked just \fIbefore\fR \f(CW\*(C`ev_loop\*(C'\fR starts +to gather new events, and all \f(CW\*(C`ev_check\*(C'\fR watchers are invoked just after +\&\f(CW\*(C`ev_loop\*(C'\fR has gathered them, but before it invokes any callbacks for any +received events. Callbacks of both watcher types can start and stop as +many watchers as they want, and all of them will be taken into account +(for example, a \f(CW\*(C`ev_prepare\*(C'\fR watcher might start an idle watcher to keep +\&\f(CW\*(C`ev_loop\*(C'\fR from blocking). +.ie n .IP """EV_EMBED""" 4 +.el .IP "\f(CWEV_EMBED\fR" 4 +.IX Item "EV_EMBED" +The embedded event loop specified in the \f(CW\*(C`ev_embed\*(C'\fR watcher needs attention. +.ie n .IP """EV_FORK""" 4 +.el .IP "\f(CWEV_FORK\fR" 4 +.IX Item "EV_FORK" +The event loop has been resumed in the child process after fork (see +\&\f(CW\*(C`ev_fork\*(C'\fR). +.ie n .IP """EV_ASYNC""" 4 +.el .IP "\f(CWEV_ASYNC\fR" 4 +.IX Item "EV_ASYNC" +The given async watcher has been asynchronously notified (see \f(CW\*(C`ev_async\*(C'\fR). +.ie n .IP """EV_ERROR""" 4 +.el .IP "\f(CWEV_ERROR\fR" 4 +.IX Item "EV_ERROR" +An unspecified error has occured, the watcher has been stopped. This might +happen because the watcher could not be properly started because libev +ran out of memory, a file descriptor was found to be closed or any other +problem. You best act on it by reporting the problem and somehow coping +with the watcher being stopped. +.Sp +Libev will usually signal a few \*(L"dummy\*(R" events together with an error, +for example it might indicate that a fd is readable or writable, and if +your callbacks is well-written it can just attempt the operation and cope +with the error from \fIread()\fR or \fIwrite()\fR. This will not work in multithreaded +programs, though, so beware. +.Sh "\s-1GENERIC\s0 \s-1WATCHER\s0 \s-1FUNCTIONS\s0" +.IX Subsection "GENERIC WATCHER FUNCTIONS" +In the following description, \f(CW\*(C`TYPE\*(C'\fR stands for the watcher type, +e.g. \f(CW\*(C`timer\*(C'\fR for \f(CW\*(C`ev_timer\*(C'\fR watchers and \f(CW\*(C`io\*(C'\fR for \f(CW\*(C`ev_io\*(C'\fR watchers. +.ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4 +.el .IP "\f(CWev_init\fR (ev_TYPE *watcher, callback)" 4 +.IX Item "ev_init (ev_TYPE *watcher, callback)" +This macro initialises the generic portion of a watcher. The contents +of the watcher object can be arbitrary (so \f(CW\*(C`malloc\*(C'\fR will do). Only +the generic parts of the watcher are initialised, you \fIneed\fR to call +the type-specific \f(CW\*(C`ev_TYPE_set\*(C'\fR macro afterwards to initialise the +type-specific parts. For each type there is also a \f(CW\*(C`ev_TYPE_init\*(C'\fR macro +which rolls both calls into one. +.Sp +You can reinitialise a watcher at any time as long as it has been stopped +(or never started) and there are no pending events outstanding. +.Sp +The callback is always of type \f(CW\*(C`void (*)(ev_loop *loop, ev_TYPE *watcher, +int revents)\*(C'\fR. +.ie n .IP """ev_TYPE_set"" (ev_TYPE *, [args])" 4 +.el .IP "\f(CWev_TYPE_set\fR (ev_TYPE *, [args])" 4 +.IX Item "ev_TYPE_set (ev_TYPE *, [args])" +This macro initialises the type-specific parts of a watcher. You need to +call \f(CW\*(C`ev_init\*(C'\fR at least once before you call this macro, but you can +call \f(CW\*(C`ev_TYPE_set\*(C'\fR any number of times. You must not, however, call this +macro on a watcher that is active (it can be pending, however, which is a +difference to the \f(CW\*(C`ev_init\*(C'\fR macro). +.Sp +Although some watcher types do not have type-specific arguments +(e.g. \f(CW\*(C`ev_prepare\*(C'\fR) you still need to call its \f(CW\*(C`set\*(C'\fR macro. +.ie n .IP """ev_TYPE_init"" (ev_TYPE *watcher, callback, [args])" 4 +.el .IP "\f(CWev_TYPE_init\fR (ev_TYPE *watcher, callback, [args])" 4 +.IX Item "ev_TYPE_init (ev_TYPE *watcher, callback, [args])" +This convinience macro rolls both \f(CW\*(C`ev_init\*(C'\fR and \f(CW\*(C`ev_TYPE_set\*(C'\fR macro +calls into a single call. This is the most convinient method to initialise +a watcher. The same limitations apply, of course. +.ie n .IP """ev_TYPE_start"" (loop *, ev_TYPE *watcher)" 4 +.el .IP "\f(CWev_TYPE_start\fR (loop *, ev_TYPE *watcher)" 4 +.IX Item "ev_TYPE_start (loop *, ev_TYPE *watcher)" +Starts (activates) the given watcher. Only active watchers will receive +events. If the watcher is already active nothing will happen. +.ie n .IP """ev_TYPE_stop"" (loop *, ev_TYPE *watcher)" 4 +.el .IP "\f(CWev_TYPE_stop\fR (loop *, ev_TYPE *watcher)" 4 +.IX Item "ev_TYPE_stop (loop *, ev_TYPE *watcher)" +Stops the given watcher again (if active) and clears the pending +status. It is possible that stopped watchers are pending (for example, +non-repeating timers are being stopped when they become pending), but +\&\f(CW\*(C`ev_TYPE_stop\*(C'\fR ensures that the watcher is neither active nor pending. If +you want to free or reuse the memory used by the watcher it is therefore a +good idea to always call its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function. +.IP "bool ev_is_active (ev_TYPE *watcher)" 4 +.IX Item "bool ev_is_active (ev_TYPE *watcher)" +Returns a true value iff the watcher is active (i.e. it has been started +and not yet been stopped). As long as a watcher is active you must not modify +it. +.IP "bool ev_is_pending (ev_TYPE *watcher)" 4 +.IX Item "bool ev_is_pending (ev_TYPE *watcher)" +Returns a true value iff the watcher is pending, (i.e. it has outstanding +events but its callback has not yet been invoked). As long as a watcher +is pending (but not active) you must not call an init function on it (but +\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must +make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR +it). +.IP "callback ev_cb (ev_TYPE *watcher)" 4 +.IX Item "callback ev_cb (ev_TYPE *watcher)" +Returns the callback currently set on the watcher. +.IP "ev_cb_set (ev_TYPE *watcher, callback)" 4 +.IX Item "ev_cb_set (ev_TYPE *watcher, callback)" +Change the callback. You can change the callback at virtually any time +(modulo threads). +.IP "ev_set_priority (ev_TYPE *watcher, priority)" 4 +.IX Item "ev_set_priority (ev_TYPE *watcher, priority)" +.PD 0 +.IP "int ev_priority (ev_TYPE *watcher)" 4 +.IX Item "int ev_priority (ev_TYPE *watcher)" +.PD +Set and query the priority of the watcher. The priority is a small +integer between \f(CW\*(C`EV_MAXPRI\*(C'\fR (default: \f(CW2\fR) and \f(CW\*(C`EV_MINPRI\*(C'\fR +(default: \f(CW\*(C`\-2\*(C'\fR). Pending watchers with higher priority will be invoked +before watchers with lower priority, but priority will not keep watchers +from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers). +.Sp +This means that priorities are \fIonly\fR used for ordering callback +invocation after new events have been received. This is useful, for +example, to reduce latency after idling, or more often, to bind two +watchers on the same event and make sure one is called first. +.Sp +If you need to suppress invocation when higher priority events are pending +you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality. +.Sp +You \fImust not\fR change the priority of a watcher as long as it is active or +pending. +.Sp +The default priority used by watchers when no priority has been set is +always \f(CW0\fR, which is supposed to not be too high and not be too low :). +.Sp +Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is +fine, as long as you do not mind that the priority value you query might +or might not have been adjusted to be within valid range. +.IP "ev_invoke (loop, ev_TYPE *watcher, int revents)" 4 +.IX Item "ev_invoke (loop, ev_TYPE *watcher, int revents)" +Invoke the \f(CW\*(C`watcher\*(C'\fR with the given \f(CW\*(C`loop\*(C'\fR and \f(CW\*(C`revents\*(C'\fR. Neither +\&\f(CW\*(C`loop\*(C'\fR nor \f(CW\*(C`revents\*(C'\fR need to be valid as long as the watcher callback +can deal with that fact. +.IP "int ev_clear_pending (loop, ev_TYPE *watcher)" 4 +.IX Item "int ev_clear_pending (loop, ev_TYPE *watcher)" +If the watcher is pending, this function returns clears its pending status +and returns its \f(CW\*(C`revents\*(C'\fR bitset (as if its callback was invoked). If the +watcher isn't pending it does nothing and returns \f(CW0\fR. +.Sh "\s-1ASSOCIATING\s0 \s-1CUSTOM\s0 \s-1DATA\s0 \s-1WITH\s0 A \s-1WATCHER\s0" +.IX Subsection "ASSOCIATING CUSTOM DATA WITH A WATCHER" +Each watcher has, by default, a member \f(CW\*(C`void *data\*(C'\fR that you can change +and read at any time, libev will completely ignore it. This can be used +to associate arbitrary data with your watcher. If you need more data and +don't want to allocate memory and store a pointer to it in that data +member, you can also \*(L"subclass\*(R" the watcher type and provide your own +data: +.PP +.Vb 7 +\& struct my_io +\& { +\& struct ev_io io; +\& int otherfd; +\& void *somedata; +\& struct whatever *mostinteresting; +\& } +.Ve +.PP +And since your callback will be called with a pointer to the watcher, you +can cast it back to your own type: +.PP +.Vb 5 +\& static void my_cb (struct ev_loop *loop, struct ev_io *w_, int revents) +\& { +\& struct my_io *w = (struct my_io *)w_; +\& ... +\& } +.Ve +.PP +More interesting and less C\-conformant ways of casting your callback type +instead have been omitted. +.PP +Another common scenario is having some data structure with multiple +watchers: +.PP +.Vb 6 +\& struct my_biggy +\& { +\& int some_data; +\& ev_timer t1; +\& ev_timer t2; +\& } +.Ve +.PP +In this case getting the pointer to \f(CW\*(C`my_biggy\*(C'\fR is a bit more complicated, +you need to use \f(CW\*(C`offsetof\*(C'\fR: +.PP +.Vb 1 +\& #include +\& +\& static void +\& t1_cb (EV_P_ struct ev_timer *w, int revents) +\& { +\& struct my_biggy big = (struct my_biggy * +\& (((char *)w) \- offsetof (struct my_biggy, t1)); +\& } +\& +\& static void +\& t2_cb (EV_P_ struct ev_timer *w, int revents) +\& { +\& struct my_biggy big = (struct my_biggy * +\& (((char *)w) \- offsetof (struct my_biggy, t2)); +\& } +.Ve +.SH "WATCHER TYPES" +.IX Header "WATCHER TYPES" +This section describes each watcher in detail, but will not repeat +information given in the last section. Any initialisation/set macros, +functions and members specific to the watcher type are explained. +.PP +Members are additionally marked with either \fI[read\-only]\fR, meaning that, +while the watcher is active, you can look at the member and expect some +sensible content, but you must not modify it (you can modify it while the +watcher is stopped to your hearts content), or \fI[read\-write]\fR, which +means you can expect it to have some sensible content while the watcher +is active, but you can also modify it. Modifying it may not do something +sensible or take immediate effect (or do anything at all), but libev will +not crash or malfunction in any way. +.ie n .Sh """ev_io"" \- is this file descriptor readable or writable?" +.el .Sh "\f(CWev_io\fP \- is this file descriptor readable or writable?" +.IX Subsection "ev_io - is this file descriptor readable or writable?" +I/O watchers check whether a file descriptor is readable or writable +in each iteration of the event loop, or, more precisely, when reading +would not block the process and writing would at least be able to write +some data. This behaviour is called level-triggering because you keep +receiving events as long as the condition persists. Remember you can stop +the watcher if you don't want to act on the event and neither want to +receive future events. +.PP +In general you can register as many read and/or write event watchers per +fd as you want (as long as you don't confuse yourself). Setting all file +descriptors to non-blocking mode is also usually a good idea (but not +required if you know what you are doing). +.PP +If you must do this, then force the use of a known-to-be-good backend +(at the time of this writing, this includes only \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR and +\&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR). +.PP +Another thing you have to watch out for is that it is quite easy to +receive \*(L"spurious\*(R" readyness notifications, that is your callback might +be called with \f(CW\*(C`EV_READ\*(C'\fR but a subsequent \f(CW\*(C`read\*(C'\fR(2) will actually block +because there is no data. Not only are some backends known to create a +lot of those (for example solaris ports), it is very easy to get into +this situation even with a relatively standard program structure. Thus +it is best to always use non-blocking I/O: An extra \f(CW\*(C`read\*(C'\fR(2) returning +\&\f(CW\*(C`EAGAIN\*(C'\fR is far preferable to a program hanging until some data arrives. +.PP +If you cannot run the fd in non-blocking mode (for example you should not +play around with an Xlib connection), then you have to seperately re-test +whether a file descriptor is really ready with a known-to-be good interface +such as poll (fortunately in our Xlib example, Xlib already does this on +its own, so its quite safe to use). +.PP +\fIThe special problem of disappearing file descriptors\fR +.IX Subsection "The special problem of disappearing file descriptors" +.PP +Some backends (e.g. kqueue, epoll) need to be told about closing a file +descriptor (either by calling \f(CW\*(C`close\*(C'\fR explicitly or by any other means, +such as \f(CW\*(C`dup\*(C'\fR). The reason is that you register interest in some file +descriptor, but when it goes away, the operating system will silently drop +this interest. If another file descriptor with the same number then is +registered with libev, there is no efficient way to see that this is, in +fact, a different file descriptor. +.PP +To avoid having to explicitly tell libev about such cases, libev follows +the following policy: Each time \f(CW\*(C`ev_io_set\*(C'\fR is being called, libev +will assume that this is potentially a new file descriptor, otherwise +it is assumed that the file descriptor stays the same. That means that +you \fIhave\fR to call \f(CW\*(C`ev_io_set\*(C'\fR (or \f(CW\*(C`ev_io_init\*(C'\fR) when you change the +descriptor even if the file descriptor number itself did not change. +.PP +This is how one would do it normally anyway, the important point is that +the libev application should not optimise around libev but should leave +optimisations to libev. +.PP +\fIThe special problem of dup'ed file descriptors\fR +.IX Subsection "The special problem of dup'ed file descriptors" +.PP +Some backends (e.g. epoll), cannot register events for file descriptors, +but only events for the underlying file descriptions. That means when you +have \f(CW\*(C`dup ()\*(C'\fR'ed file descriptors or weirder constellations, and register +events for them, only one file descriptor might actually receive events. +.PP +There is no workaround possible except not registering events +for potentially \f(CW\*(C`dup ()\*(C'\fR'ed file descriptors, or to resort to +\&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR. +.PP +\fIThe special problem of fork\fR +.IX Subsection "The special problem of fork" +.PP +Some backends (epoll, kqueue) do not support \f(CW\*(C`fork ()\*(C'\fR at all or exhibit +useless behaviour. Libev fully supports fork, but needs to be told about +it in the child. +.PP +To support fork in your programs, you either have to call +\&\f(CW\*(C`ev_default_fork ()\*(C'\fR or \f(CW\*(C`ev_loop_fork ()\*(C'\fR after a fork in the child, +enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or +\&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. +.PP +\fIThe special problem of \s-1SIGPIPE\s0\fR +.IX Subsection "The special problem of SIGPIPE" +.PP +While not really specific to libev, it is easy to forget about \s-1SIGPIPE:\s0 +when reading from a pipe whose other end has been closed, your program +gets send a \s-1SIGPIPE\s0, which, by default, aborts your program. For most +programs this is sensible behaviour, for daemons, this is usually +undesirable. +.PP +So when you encounter spurious, unexplained daemon exits, make sure you +ignore \s-1SIGPIPE\s0 (and maybe make sure you log the exit status of your daemon +somewhere, as that would have given you a big clue). +.PP +\fIWatcher-Specific Functions\fR +.IX Subsection "Watcher-Specific Functions" +.IP "ev_io_init (ev_io *, callback, int fd, int events)" 4 +.IX Item "ev_io_init (ev_io *, callback, int fd, int events)" +.PD 0 +.IP "ev_io_set (ev_io *, int fd, int events)" 4 +.IX Item "ev_io_set (ev_io *, int fd, int events)" +.PD +Configures an \f(CW\*(C`ev_io\*(C'\fR watcher. The \f(CW\*(C`fd\*(C'\fR is the file descriptor to +rceeive events for and events is either \f(CW\*(C`EV_READ\*(C'\fR, \f(CW\*(C`EV_WRITE\*(C'\fR or +\&\f(CW\*(C`EV_READ | EV_WRITE\*(C'\fR to receive the given events. +.IP "int fd [read\-only]" 4 +.IX Item "int fd [read-only]" +The file descriptor being watched. +.IP "int events [read\-only]" 4 +.IX Item "int events [read-only]" +The events being watched. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: Call \f(CW\*(C`stdin_readable_cb\*(C'\fR when \s-1STDIN_FILENO\s0 has become, well +readable, but only once. Since it is likely line-buffered, you could +attempt to read a whole line in the callback. +.PP +.Vb 6 +\& static void +\& stdin_readable_cb (struct ev_loop *loop, struct ev_io *w, int revents) +\& { +\& ev_io_stop (loop, w); +\& .. read from stdin here (or from w\->fd) and haqndle any I/O errors +\& } +\& +\& ... +\& struct ev_loop *loop = ev_default_init (0); +\& struct ev_io stdin_readable; +\& ev_io_init (&stdin_readable, stdin_readable_cb, STDIN_FILENO, EV_READ); +\& ev_io_start (loop, &stdin_readable); +\& ev_loop (loop, 0); +.Ve +.ie n .Sh """ev_timer"" \- relative and optionally repeating timeouts" +.el .Sh "\f(CWev_timer\fP \- relative and optionally repeating timeouts" +.IX Subsection "ev_timer - relative and optionally repeating timeouts" +Timer watchers are simple relative timers that generate an event after a +given time, and optionally repeating in regular intervals after that. +.PP +The timers are based on real time, that is, if you register an event that +times out after an hour and you reset your system clock to last years +time, it will still time out after (roughly) and hour. \*(L"Roughly\*(R" because +detecting time jumps is hard, and some inaccuracies are unavoidable (the +monotonic clock option helps a lot here). +.PP +The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR +time. This is usually the right thing as this timestamp refers to the time +of the event triggering whatever timeout you are modifying/starting. If +you suspect event processing to be delayed and you \fIneed\fR to base the timeout +on the current time, use something like this to adjust for this: +.PP +.Vb 1 +\& ev_timer_set (&timer, after + ev_now () \- ev_time (), 0.); +.Ve +.PP +The callback is guarenteed to be invoked only when its timeout has passed, +but if multiple timers become ready during the same loop iteration then +order of execution is undefined. +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" 4 +.IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" +.PD 0 +.IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 +.IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" +.PD +Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds. If \f(CW\*(C`repeat\*(C'\fR is +\&\f(CW0.\fR, then it will automatically be stopped. If it is positive, then the +timer will automatically be configured to trigger again \f(CW\*(C`repeat\*(C'\fR seconds +later, again, and again, until stopped manually. +.Sp +The timer itself will do a best-effort at avoiding drift, that is, if you +configure a timer to trigger every 10 seconds, then it will trigger at +exactly 10 second intervals. If, however, your program cannot keep up with +the timer (because it takes longer than those 10 seconds to do stuff) the +timer will not fire more than once per event loop iteration. +.IP "ev_timer_again (loop, ev_timer *)" 4 +.IX Item "ev_timer_again (loop, ev_timer *)" +This will act as if the timer timed out and restart it again if it is +repeating. The exact semantics are: +.Sp +If the timer is pending, its pending status is cleared. +.Sp +If the timer is started but nonrepeating, stop it (as if it timed out). +.Sp +If the timer is repeating, either start it if necessary (with the +\&\f(CW\*(C`repeat\*(C'\fR value), or reset the running timer to the \f(CW\*(C`repeat\*(C'\fR value. +.Sp +This sounds a bit complicated, but here is a useful and typical +example: Imagine you have a tcp connection and you want a so-called idle +timeout, that is, you want to be called when there have been, say, 60 +seconds of inactivity on the socket. The easiest way to do this is to +configure an \f(CW\*(C`ev_timer\*(C'\fR with a \f(CW\*(C`repeat\*(C'\fR value of \f(CW60\fR and then call +\&\f(CW\*(C`ev_timer_again\*(C'\fR each time you successfully read or write some data. If +you go into an idle state where you do not expect data to travel on the +socket, you can \f(CW\*(C`ev_timer_stop\*(C'\fR the timer, and \f(CW\*(C`ev_timer_again\*(C'\fR will +automatically restart it if need be. +.Sp +That means you can ignore the \f(CW\*(C`after\*(C'\fR value and \f(CW\*(C`ev_timer_start\*(C'\fR +altogether and only ever use the \f(CW\*(C`repeat\*(C'\fR value and \f(CW\*(C`ev_timer_again\*(C'\fR: +.Sp +.Vb 8 +\& ev_timer_init (timer, callback, 0., 5.); +\& ev_timer_again (loop, timer); +\& ... +\& timer\->again = 17.; +\& ev_timer_again (loop, timer); +\& ... +\& timer\->again = 10.; +\& ev_timer_again (loop, timer); +.Ve +.Sp +This is more slightly efficient then stopping/starting the timer each time +you want to modify its timeout value. +.IP "ev_tstamp repeat [read\-write]" 4 +.IX Item "ev_tstamp repeat [read-write]" +The current \f(CW\*(C`repeat\*(C'\fR value. Will be used each time the watcher times out +or \f(CW\*(C`ev_timer_again\*(C'\fR is called and determines the next timeout (if any), +which is also when any modifications are taken into account. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: Create a timer that fires after 60 seconds. +.PP +.Vb 5 +\& static void +\& one_minute_cb (struct ev_loop *loop, struct ev_timer *w, int revents) +\& { +\& .. one minute over, w is actually stopped right here +\& } +\& +\& struct ev_timer mytimer; +\& ev_timer_init (&mytimer, one_minute_cb, 60., 0.); +\& ev_timer_start (loop, &mytimer); +.Ve +.PP +Example: Create a timeout timer that times out after 10 seconds of +inactivity. +.PP +.Vb 5 +\& static void +\& timeout_cb (struct ev_loop *loop, struct ev_timer *w, int revents) +\& { +\& .. ten seconds without any activity +\& } +\& +\& struct ev_timer mytimer; +\& ev_timer_init (&mytimer, timeout_cb, 0., 10.); /* note, only repeat used */ +\& ev_timer_again (&mytimer); /* start timer */ +\& ev_loop (loop, 0); +\& +\& // and in some piece of code that gets executed on any "activity": +\& // reset the timeout to start ticking again at 10 seconds +\& ev_timer_again (&mytimer); +.Ve +.ie n .Sh """ev_periodic"" \- to cron or not to cron?" +.el .Sh "\f(CWev_periodic\fP \- to cron or not to cron?" +.IX Subsection "ev_periodic - to cron or not to cron?" +Periodic watchers are also timers of a kind, but they are very versatile +(and unfortunately a bit complex). +.PP +Unlike \f(CW\*(C`ev_timer\*(C'\fR's, they are not based on real time (or relative time) +but on wallclock time (absolute time). You can tell a periodic watcher +to trigger \*(L"at\*(R" some specific point in time. For example, if you tell a +periodic watcher to trigger in 10 seconds (by specifiying e.g. \f(CW\*(C`ev_now () ++ 10.\*(C'\fR) and then reset your system clock to the last year, then it will +take a year to trigger the event (unlike an \f(CW\*(C`ev_timer\*(C'\fR, which would trigger +roughly 10 seconds later). +.PP +They can also be used to implement vastly more complex timers, such as +triggering an event on each midnight, local time or other, complicated, +rules. +.PP +As with timers, the callback is guarenteed to be invoked only when the +time (\f(CW\*(C`at\*(C'\fR) has been passed, but if multiple periodic timers become ready +during the same loop iteration then order of execution is undefined. +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)" 4 +.IX Item "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)" +.PD 0 +.IP "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)" 4 +.IX Item "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)" +.PD +Lots of arguments, lets sort it out... There are basically three modes of +operation, and we will explain them from simplest to complex: +.RS 4 +.IP "\(bu" 4 +absolute timer (at = time, interval = reschedule_cb = 0) +.Sp +In this configuration the watcher triggers an event at the wallclock time +\&\f(CW\*(C`at\*(C'\fR and doesn't repeat. It will not adjust when a time jump occurs, +that is, if it is to be run at January 1st 2011 then it will run when the +system time reaches or surpasses this time. +.IP "\(bu" 4 +repeating interval timer (at = offset, interval > 0, reschedule_cb = 0) +.Sp +In this mode the watcher will always be scheduled to time out at the next +\&\f(CW\*(C`at + N * interval\*(C'\fR time (for some integer N, which can also be negative) +and then repeat, regardless of any time jumps. +.Sp +This can be used to create timers that do not drift with respect to system +time: +.Sp +.Vb 1 +\& ev_periodic_set (&periodic, 0., 3600., 0); +.Ve +.Sp +This doesn't mean there will always be 3600 seconds in between triggers, +but only that the the callback will be called when the system time shows a +full hour (\s-1UTC\s0), or more correctly, when the system time is evenly divisible +by 3600. +.Sp +Another way to think about it (for the mathematically inclined) is that +\&\f(CW\*(C`ev_periodic\*(C'\fR will try to run the callback in this mode at the next possible +time where \f(CW\*(C`time = at (mod interval)\*(C'\fR, regardless of any time jumps. +.Sp +For numerical stability it is preferable that the \f(CW\*(C`at\*(C'\fR value is near +\&\f(CW\*(C`ev_now ()\*(C'\fR (the current time), but there is no range requirement for +this value. +.IP "\(bu" 4 +manual reschedule mode (at and interval ignored, reschedule_cb = callback) +.Sp +In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`at\*(C'\fR are both being +ignored. Instead, each time the periodic watcher gets scheduled, the +reschedule callback will be called with the watcher as first, and the +current time as second argument. +.Sp +\&\s-1NOTE:\s0 \fIThis callback \s-1MUST\s0 \s-1NOT\s0 stop or destroy any periodic watcher, +ever, or make any event loop modifications\fR. If you need to stop it, +return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop it afterwards (e.g. by +starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is legal). +.Sp +Its prototype is \f(CW\*(C`ev_tstamp (*reschedule_cb)(struct ev_periodic *w, +ev_tstamp now)\*(C'\fR, e.g.: +.Sp +.Vb 4 +\& static ev_tstamp my_rescheduler (struct ev_periodic *w, ev_tstamp now) +\& { +\& return now + 60.; +\& } +.Ve +.Sp +It must return the next time to trigger, based on the passed time value +(that is, the lowest time value larger than to the second argument). It +will usually be called just before the callback will be triggered, but +might be called at other times, too. +.Sp +\&\s-1NOTE:\s0 \fIThis callback must always return a time that is later than the +passed \f(CI\*(C`now\*(C'\fI value\fR. Not even \f(CW\*(C`now\*(C'\fR itself will do, it \fImust\fR be larger. +.Sp +This can be used to create very complex timers, such as a timer that +triggers on each midnight, local time. To do this, you would calculate the +next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for this. How +you do this is, again, up to you (but it is not trivial, which is the main +reason I omitted it as an example). +.RE +.RS 4 +.RE +.IP "ev_periodic_again (loop, ev_periodic *)" 4 +.IX Item "ev_periodic_again (loop, ev_periodic *)" +Simply stops and restarts the periodic watcher again. This is only useful +when you changed some parameters or the reschedule callback would return +a different time than the last time it was called (e.g. in a crond like +program when the crontabs have changed). +.IP "ev_tstamp ev_periodic_at (ev_periodic *)" 4 +.IX Item "ev_tstamp ev_periodic_at (ev_periodic *)" +When active, returns the absolute time that the watcher is supposed to +trigger next. +.IP "ev_tstamp offset [read\-write]" 4 +.IX Item "ev_tstamp offset [read-write]" +When repeating, this contains the offset value, otherwise this is the +absolute point in time (the \f(CW\*(C`at\*(C'\fR value passed to \f(CW\*(C`ev_periodic_set\*(C'\fR). +.Sp +Can be modified any time, but changes only take effect when the periodic +timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called. +.IP "ev_tstamp interval [read\-write]" 4 +.IX Item "ev_tstamp interval [read-write]" +The current interval value. Can be modified any time, but changes only +take effect when the periodic timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being +called. +.IP "ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) [read\-write]" 4 +.IX Item "ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) [read-write]" +The current reschedule callback, or \f(CW0\fR, if this functionality is +switched off. Can be changed any time, but changes only take effect when +the periodic timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: Call a callback every hour, or, more precisely, whenever the +system clock is divisible by 3600. The callback invocation times have +potentially a lot of jittering, but good long-term stability. +.PP +.Vb 5 +\& static void +\& clock_cb (struct ev_loop *loop, struct ev_io *w, int revents) +\& { +\& ... its now a full hour (UTC, or TAI or whatever your clock follows) +\& } +\& +\& struct ev_periodic hourly_tick; +\& ev_periodic_init (&hourly_tick, clock_cb, 0., 3600., 0); +\& ev_periodic_start (loop, &hourly_tick); +.Ve +.PP +Example: The same as above, but use a reschedule callback to do it: +.PP +.Vb 1 +\& #include +\& +\& static ev_tstamp +\& my_scheduler_cb (struct ev_periodic *w, ev_tstamp now) +\& { +\& return fmod (now, 3600.) + 3600.; +\& } +\& +\& ev_periodic_init (&hourly_tick, clock_cb, 0., 0., my_scheduler_cb); +.Ve +.PP +Example: Call a callback every hour, starting now: +.PP +.Vb 4 +\& struct ev_periodic hourly_tick; +\& ev_periodic_init (&hourly_tick, clock_cb, +\& fmod (ev_now (loop), 3600.), 3600., 0); +\& ev_periodic_start (loop, &hourly_tick); +.Ve +.ie n .Sh """ev_signal"" \- signal me when a signal gets signalled!" +.el .Sh "\f(CWev_signal\fP \- signal me when a signal gets signalled!" +.IX Subsection "ev_signal - signal me when a signal gets signalled!" +Signal watchers will trigger an event when the process receives a specific +signal one or more times. Even though signals are very asynchronous, libev +will try it's best to deliver signals synchronously, i.e. as part of the +normal event processing, like any other event. +.PP +You can configure as many watchers as you like per signal. Only when the +first watcher gets started will libev actually register a signal watcher +with the kernel (thus it coexists with your own signal handlers as long +as you don't register any with libev). Similarly, when the last signal +watcher for a signal is stopped libev will reset the signal handler to +\&\s-1SIG_DFL\s0 (regardless of what it was set to before). +.PP +If possible and supported, libev will install its handlers with +\&\f(CW\*(C`SA_RESTART\*(C'\fR behaviour enabled, so syscalls should not be unduly +interrupted. If you have a problem with syscalls getting interrupted by +signals you can block all signals in an \f(CW\*(C`ev_check\*(C'\fR watcher and unblock +them in an \f(CW\*(C`ev_prepare\*(C'\fR watcher. +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_signal_init (ev_signal *, callback, int signum)" 4 +.IX Item "ev_signal_init (ev_signal *, callback, int signum)" +.PD 0 +.IP "ev_signal_set (ev_signal *, int signum)" 4 +.IX Item "ev_signal_set (ev_signal *, int signum)" +.PD +Configures the watcher to trigger on the given signal number (usually one +of the \f(CW\*(C`SIGxxx\*(C'\fR constants). +.IP "int signum [read\-only]" 4 +.IX Item "int signum [read-only]" +The signal the watcher watches out for. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: Try to exit cleanly on \s-1SIGINT\s0 and \s-1SIGTERM\s0. +.PP +.Vb 5 +\& static void +\& sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents) +\& { +\& ev_unloop (loop, EVUNLOOP_ALL); +\& } +\& +\& struct ev_signal signal_watcher; +\& ev_signal_init (&signal_watcher, sigint_cb, SIGINT); +\& ev_signal_start (loop, &sigint_cb); +.Ve +.ie n .Sh """ev_child"" \- watch out for process status changes" +.el .Sh "\f(CWev_child\fP \- watch out for process status changes" +.IX Subsection "ev_child - watch out for process status changes" +Child watchers trigger when your process receives a \s-1SIGCHLD\s0 in response to +some child status changes (most typically when a child of yours dies). It +is permissible to install a child watcher \fIafter\fR the child has been +forked (which implies it might have already exited), as long as the event +loop isn't entered (or is continued from a watcher). +.PP +Only the default event loop is capable of handling signals, and therefore +you can only rgeister child watchers in the default event loop. +.PP +\fIProcess Interaction\fR +.IX Subsection "Process Interaction" +.PP +Libev grabs \f(CW\*(C`SIGCHLD\*(C'\fR as soon as the default event loop is +initialised. This is necessary to guarantee proper behaviour even if +the first child watcher is started after the child exits. The occurance +of \f(CW\*(C`SIGCHLD\*(C'\fR is recorded asynchronously, but child reaping is done +synchronously as part of the event loop processing. Libev always reaps all +children, even ones not watched. +.PP +\fIOverriding the Built-In Processing\fR +.IX Subsection "Overriding the Built-In Processing" +.PP +Libev offers no special support for overriding the built-in child +processing, but if your application collides with libev's default child +handler, you can override it easily by installing your own handler for +\&\f(CW\*(C`SIGCHLD\*(C'\fR after initialising the default loop, and making sure the +default loop never gets destroyed. You are encouraged, however, to use an +event-based approach to child reaping and thus use libev's support for +that, so other libev users can use \f(CW\*(C`ev_child\*(C'\fR watchers freely. +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_child_init (ev_child *, callback, int pid, int trace)" 4 +.IX Item "ev_child_init (ev_child *, callback, int pid, int trace)" +.PD 0 +.IP "ev_child_set (ev_child *, int pid, int trace)" 4 +.IX Item "ev_child_set (ev_child *, int pid, int trace)" +.PD +Configures the watcher to wait for status changes of process \f(CW\*(C`pid\*(C'\fR (or +\&\fIany\fR process if \f(CW\*(C`pid\*(C'\fR is specified as \f(CW0\fR). The callback can look +at the \f(CW\*(C`rstatus\*(C'\fR member of the \f(CW\*(C`ev_child\*(C'\fR watcher structure to see +the status word (use the macros from \f(CW\*(C`sys/wait.h\*(C'\fR and see your systems +\&\f(CW\*(C`waitpid\*(C'\fR documentation). The \f(CW\*(C`rpid\*(C'\fR member contains the pid of the +process causing the status change. \f(CW\*(C`trace\*(C'\fR must be either \f(CW0\fR (only +activate the watcher when the process terminates) or \f(CW1\fR (additionally +activate the watcher when the process is stopped or continued). +.IP "int pid [read\-only]" 4 +.IX Item "int pid [read-only]" +The process id this watcher watches out for, or \f(CW0\fR, meaning any process id. +.IP "int rpid [read\-write]" 4 +.IX Item "int rpid [read-write]" +The process id that detected a status change. +.IP "int rstatus [read\-write]" 4 +.IX Item "int rstatus [read-write]" +The process exit/trace status caused by \f(CW\*(C`rpid\*(C'\fR (see your systems +\&\f(CW\*(C`waitpid\*(C'\fR and \f(CW\*(C`sys/wait.h\*(C'\fR documentation for details). +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: \f(CW\*(C`fork()\*(C'\fR a new process and install a child handler to wait for +its completion. +.PP +.Vb 1 +\& ev_child cw; +\& +\& static void +\& child_cb (EV_P_ struct ev_child *w, int revents) +\& { +\& ev_child_stop (EV_A_ w); +\& printf ("process %d exited with status %x\en", w\->rpid, w\->rstatus); +\& } +\& +\& pid_t pid = fork (); +\& +\& if (pid < 0) +\& // error +\& else if (pid == 0) +\& { +\& // the forked child executes here +\& exit (1); +\& } +\& else +\& { +\& ev_child_init (&cw, child_cb, pid, 0); +\& ev_child_start (EV_DEFAULT_ &cw); +\& } +.Ve +.ie n .Sh """ev_stat"" \- did the file attributes just change?" +.el .Sh "\f(CWev_stat\fP \- did the file attributes just change?" +.IX Subsection "ev_stat - did the file attributes just change?" +This watches a filesystem path for attribute changes. That is, it calls +\&\f(CW\*(C`stat\*(C'\fR regularly (or when the \s-1OS\s0 says it changed) and sees if it changed +compared to the last time, invoking the callback if it did. +.PP +The path does not need to exist: changing from \*(L"path exists\*(R" to \*(L"path does +not exist\*(R" is a status change like any other. The condition \*(L"path does +not exist\*(R" is signified by the \f(CW\*(C`st_nlink\*(C'\fR field being zero (which is +otherwise always forced to be at least one) and all the other fields of +the stat buffer having unspecified contents. +.PP +The path \fIshould\fR be absolute and \fImust not\fR end in a slash. If it is +relative and your working directory changes, the behaviour is undefined. +.PP +Since there is no standard to do this, the portable implementation simply +calls \f(CW\*(C`stat (2)\*(C'\fR regularly on the path to see if it changed somehow. You +can specify a recommended polling interval for this case. If you specify +a polling interval of \f(CW0\fR (highly recommended!) then a \fIsuitable, +unspecified default\fR value will be used (which you can expect to be around +five seconds, although this might change dynamically). Libev will also +impose a minimum interval which is currently around \f(CW0.1\fR, but thats +usually overkill. +.PP +This watcher type is not meant for massive numbers of stat watchers, +as even with OS-supported change notifications, this can be +resource-intensive. +.PP +At the time of this writing, only the Linux inotify interface is +implemented (implementing kqueue support is left as an exercise for the +reader, note, however, that the author sees no way of implementing ev_stat +semantics with kqueue). Inotify will be used to give hints only and should +not change the semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers, which means that libev +sometimes needs to fall back to regular polling again even with inotify, +but changes are usually detected immediately, and if the file exists there +will be no polling. +.PP +\fI\s-1ABI\s0 Issues (Largefile Support)\fR +.IX Subsection "ABI Issues (Largefile Support)" +.PP +Libev by default (unless the user overrides this) uses the default +compilation environment, which means that on systems with optionally +disabled large file support, you get the 32 bit version of the stat +structure. When using the library from programs that change the \s-1ABI\s0 to +use 64 bit file offsets the programs will fail. In that case you have to +compile libev with the same flags to get binary compatibility. This is +obviously the case with any flags that change the \s-1ABI\s0, but the problem is +most noticably with ev_stat and largefile support. +.PP +\fIInotify\fR +.IX Subsection "Inotify" +.PP +When \f(CW\*(C`inotify (7)\*(C'\fR support has been compiled into libev (generally only +available on Linux) and present at runtime, it will be used to speed up +change detection where possible. The inotify descriptor will be created lazily +when the first \f(CW\*(C`ev_stat\*(C'\fR watcher is being started. +.PP +Inotify presence does not change the semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers +except that changes might be detected earlier, and in some cases, to avoid +making regular \f(CW\*(C`stat\*(C'\fR calls. Even in the presence of inotify support +there are many cases where libev has to resort to regular \f(CW\*(C`stat\*(C'\fR polling. +.PP +(There is no support for kqueue, as apparently it cannot be used to +implement this functionality, due to the requirement of having a file +descriptor open on the object at all times). +.PP +\fIThe special problem of stat time resolution\fR +.IX Subsection "The special problem of stat time resolution" +.PP +The \f(CW\*(C`stat ()\*(C'\fR syscall only supports full-second resolution portably, and +even on systems where the resolution is higher, many filesystems still +only support whole seconds. +.PP +That means that, if the time is the only thing that changes, you can +easily miss updates: on the first update, \f(CW\*(C`ev_stat\*(C'\fR detects a change and +calls your callback, which does something. When there is another update +within the same second, \f(CW\*(C`ev_stat\*(C'\fR will be unable to detect it as the stat +data does not change. +.PP +The solution to this is to delay acting on a change for slightly more +than second (or till slightly after the next full second boundary), using +a roughly one-second-delay \f(CW\*(C`ev_timer\*(C'\fR (e.g. \f(CW\*(C`ev_timer_set (w, 0., 1.02); +ev_timer_again (loop, w)\*(C'\fR). +.PP +The \f(CW.02\fR offset is added to work around small timing inconsistencies +of some operating systems (where the second counter of the current time +might be be delayed. One such system is the Linux kernel, where a call to +\&\f(CW\*(C`gettimeofday\*(C'\fR might return a timestamp with a full second later than +a subsequent \f(CW\*(C`time\*(C'\fR call \- if the equivalent of \f(CW\*(C`time ()\*(C'\fR is used to +update file times then there will be a small window where the kernel uses +the previous second to update file times but libev might already execute +the timer callback). +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" 4 +.IX Item "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" +.PD 0 +.IP "ev_stat_set (ev_stat *, const char *path, ev_tstamp interval)" 4 +.IX Item "ev_stat_set (ev_stat *, const char *path, ev_tstamp interval)" +.PD +Configures the watcher to wait for status changes of the given +\&\f(CW\*(C`path\*(C'\fR. The \f(CW\*(C`interval\*(C'\fR is a hint on how quickly a change is expected to +be detected and should normally be specified as \f(CW0\fR to let libev choose +a suitable value. The memory pointed to by \f(CW\*(C`path\*(C'\fR must point to the same +path for as long as the watcher is active. +.Sp +The callback will receive \f(CW\*(C`EV_STAT\*(C'\fR when a change was detected, relative +to the attributes at the time the watcher was started (or the last change +was detected). +.IP "ev_stat_stat (loop, ev_stat *)" 4 +.IX Item "ev_stat_stat (loop, ev_stat *)" +Updates the stat buffer immediately with new values. If you change the +watched path in your callback, you could call this function to avoid +detecting this change (while introducing a race condition if you are not +the only one changing the path). Can also be useful simply to find out the +new values. +.IP "ev_statdata attr [read\-only]" 4 +.IX Item "ev_statdata attr [read-only]" +The most-recently detected attributes of the file. Although the type is +\&\f(CW\*(C`ev_statdata\*(C'\fR, this is usually the (or one of the) \f(CW\*(C`struct stat\*(C'\fR types +suitable for your system, but you can only rely on the POSIX-standardised +members to be present. If the \f(CW\*(C`st_nlink\*(C'\fR member is \f(CW0\fR, then there was +some error while \f(CW\*(C`stat\*(C'\fRing the file. +.IP "ev_statdata prev [read\-only]" 4 +.IX Item "ev_statdata prev [read-only]" +The previous attributes of the file. The callback gets invoked whenever +\&\f(CW\*(C`prev\*(C'\fR != \f(CW\*(C`attr\*(C'\fR, or, more precisely, one or more of these members +differ: \f(CW\*(C`st_dev\*(C'\fR, \f(CW\*(C`st_ino\*(C'\fR, \f(CW\*(C`st_mode\*(C'\fR, \f(CW\*(C`st_nlink\*(C'\fR, \f(CW\*(C`st_uid\*(C'\fR, +\&\f(CW\*(C`st_gid\*(C'\fR, \f(CW\*(C`st_rdev\*(C'\fR, \f(CW\*(C`st_size\*(C'\fR, \f(CW\*(C`st_atime\*(C'\fR, \f(CW\*(C`st_mtime\*(C'\fR, \f(CW\*(C`st_ctime\*(C'\fR. +.IP "ev_tstamp interval [read\-only]" 4 +.IX Item "ev_tstamp interval [read-only]" +The specified interval. +.IP "const char *path [read\-only]" 4 +.IX Item "const char *path [read-only]" +The filesystem path that is being watched. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: Watch \f(CW\*(C`/etc/passwd\*(C'\fR for attribute changes. +.PP +.Vb 10 +\& static void +\& passwd_cb (struct ev_loop *loop, ev_stat *w, int revents) +\& { +\& /* /etc/passwd changed in some way */ +\& if (w\->attr.st_nlink) +\& { +\& printf ("passwd current size %ld\en", (long)w\->attr.st_size); +\& printf ("passwd current atime %ld\en", (long)w\->attr.st_mtime); +\& printf ("passwd current mtime %ld\en", (long)w\->attr.st_mtime); +\& } +\& else +\& /* you shalt not abuse printf for puts */ +\& puts ("wow, /etc/passwd is not there, expect problems. " +\& "if this is windows, they already arrived\en"); +\& } +\& +\& ... +\& ev_stat passwd; +\& +\& ev_stat_init (&passwd, passwd_cb, "/etc/passwd", 0.); +\& ev_stat_start (loop, &passwd); +.Ve +.PP +Example: Like above, but additionally use a one-second delay so we do not +miss updates (however, frequent updates will delay processing, too, so +one might do the work both on \f(CW\*(C`ev_stat\*(C'\fR callback invocation \fIand\fR on +\&\f(CW\*(C`ev_timer\*(C'\fR callback invocation). +.PP +.Vb 2 +\& static ev_stat passwd; +\& static ev_timer timer; +\& +\& static void +\& timer_cb (EV_P_ ev_timer *w, int revents) +\& { +\& ev_timer_stop (EV_A_ w); +\& +\& /* now it\*(Aqs one second after the most recent passwd change */ +\& } +\& +\& static void +\& stat_cb (EV_P_ ev_stat *w, int revents) +\& { +\& /* reset the one\-second timer */ +\& ev_timer_again (EV_A_ &timer); +\& } +\& +\& ... +\& ev_stat_init (&passwd, stat_cb, "/etc/passwd", 0.); +\& ev_stat_start (loop, &passwd); +\& ev_timer_init (&timer, timer_cb, 0., 1.02); +.Ve +.ie n .Sh """ev_idle"" \- when you've got nothing better to do..." +.el .Sh "\f(CWev_idle\fP \- when you've got nothing better to do..." +.IX Subsection "ev_idle - when you've got nothing better to do..." +Idle watchers trigger events when no other events of the same or higher +priority are pending (prepare, check and other idle watchers do not +count). +.PP +That is, as long as your process is busy handling sockets or timeouts +(or even signals, imagine) of the same or higher priority it will not be +triggered. But when your process is idle (or only lower-priority watchers +are pending), the idle watchers are being called once per event loop +iteration \- until stopped, that is, or your process receives more events +and becomes busy again with higher priority stuff. +.PP +The most noteworthy effect is that as long as any idle watchers are +active, the process will not block when waiting for new events. +.PP +Apart from keeping your process non-blocking (which is a useful +effect on its own sometimes), idle watchers are a good place to do +\&\*(L"pseudo-background processing\*(R", or delay processing stuff to after the +event loop has handled all outstanding events. +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_idle_init (ev_signal *, callback)" 4 +.IX Item "ev_idle_init (ev_signal *, callback)" +Initialises and configures the idle watcher \- it has no parameters of any +kind. There is a \f(CW\*(C`ev_idle_set\*(C'\fR macro, but using it is utterly pointless, +believe me. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: Dynamically allocate an \f(CW\*(C`ev_idle\*(C'\fR watcher, start it, and in the +callback, free it. Also, use no error checking, as usual. +.PP +.Vb 7 +\& static void +\& idle_cb (struct ev_loop *loop, struct ev_idle *w, int revents) +\& { +\& free (w); +\& // now do something you wanted to do when the program has +\& // no longer anything immediate to do. +\& } +\& +\& struct ev_idle *idle_watcher = malloc (sizeof (struct ev_idle)); +\& ev_idle_init (idle_watcher, idle_cb); +\& ev_idle_start (loop, idle_cb); +.Ve +.ie n .Sh """ev_prepare""\fP and \f(CW""ev_check"" \- customise your event loop!" +.el .Sh "\f(CWev_prepare\fP and \f(CWev_check\fP \- customise your event loop!" +.IX Subsection "ev_prepare and ev_check - customise your event loop!" +Prepare and check watchers are usually (but not always) used in tandem: +prepare watchers get invoked before the process blocks and check watchers +afterwards. +.PP +You \fImust not\fR call \f(CW\*(C`ev_loop\*(C'\fR or similar functions that enter +the current event loop from either \f(CW\*(C`ev_prepare\*(C'\fR or \f(CW\*(C`ev_check\*(C'\fR +watchers. Other loops than the current one are fine, however. The +rationale behind this is that you do not need to check for recursion in +those watchers, i.e. the sequence will always be \f(CW\*(C`ev_prepare\*(C'\fR, blocking, +\&\f(CW\*(C`ev_check\*(C'\fR so if you have one watcher of each kind they will always be +called in pairs bracketing the blocking call. +.PP +Their main purpose is to integrate other event mechanisms into libev and +their use is somewhat advanced. This could be used, for example, to track +variable changes, implement your own watchers, integrate net-snmp or a +coroutine library and lots more. They are also occasionally useful if +you cache some data and want to flush it before blocking (for example, +in X programs you might want to do an \f(CW\*(C`XFlush ()\*(C'\fR in an \f(CW\*(C`ev_prepare\*(C'\fR +watcher). +.PP +This is done by examining in each prepare call which file descriptors need +to be watched by the other library, registering \f(CW\*(C`ev_io\*(C'\fR watchers for +them and starting an \f(CW\*(C`ev_timer\*(C'\fR watcher for any timeouts (many libraries +provide just this functionality). Then, in the check watcher you check for +any events that occured (by checking the pending status of all watchers +and stopping them) and call back into the library. The I/O and timer +callbacks will never actually be called (but must be valid nevertheless, +because you never know, you know?). +.PP +As another example, the Perl Coro module uses these hooks to integrate +coroutines into libev programs, by yielding to other active coroutines +during each prepare and only letting the process block if no coroutines +are ready to run (it's actually more complicated: it only runs coroutines +with priority higher than or equal to the event loop and one coroutine +of lower priority, but only once, using idle watchers to keep the event +loop from blocking if lower-priority coroutines are active, thus mapping +low-priority coroutines to idle/background tasks). +.PP +It is recommended to give \f(CW\*(C`ev_check\*(C'\fR watchers highest (\f(CW\*(C`EV_MAXPRI\*(C'\fR) +priority, to ensure that they are being run before any other watchers +after the poll. Also, \f(CW\*(C`ev_check\*(C'\fR watchers (and \f(CW\*(C`ev_prepare\*(C'\fR watchers, +too) should not activate (\*(L"feed\*(R") events into libev. While libev fully +supports this, they might get executed before other \f(CW\*(C`ev_check\*(C'\fR watchers +did their job. As \f(CW\*(C`ev_check\*(C'\fR watchers are often used to embed other +(non-libev) event loops those other event loops might be in an unusable +state until their \f(CW\*(C`ev_check\*(C'\fR watcher ran (always remind yourself to +coexist peacefully with others). +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_prepare_init (ev_prepare *, callback)" 4 +.IX Item "ev_prepare_init (ev_prepare *, callback)" +.PD 0 +.IP "ev_check_init (ev_check *, callback)" 4 +.IX Item "ev_check_init (ev_check *, callback)" +.PD +Initialises and configures the prepare or check watcher \- they have no +parameters of any kind. There are \f(CW\*(C`ev_prepare_set\*(C'\fR and \f(CW\*(C`ev_check_set\*(C'\fR +macros, but using them is utterly, utterly and completely pointless. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +There are a number of principal ways to embed other event loops or modules +into libev. Here are some ideas on how to include libadns into libev +(there is a Perl module named \f(CW\*(C`EV::ADNS\*(C'\fR that does this, which you could +use as a working example. Another Perl module named \f(CW\*(C`EV::Glib\*(C'\fR embeds a +Glib main context into libev, and finally, \f(CW\*(C`Glib::EV\*(C'\fR embeds \s-1EV\s0 into the +Glib event loop). +.PP +Method 1: Add \s-1IO\s0 watchers and a timeout watcher in a prepare handler, +and in a check watcher, destroy them and call into libadns. What follows +is pseudo-code only of course. This requires you to either use a low +priority for the check watcher or use \f(CW\*(C`ev_clear_pending\*(C'\fR explicitly, as +the callbacks for the IO/timeout watchers might not have been called yet. +.PP +.Vb 2 +\& static ev_io iow [nfd]; +\& static ev_timer tw; +\& +\& static void +\& io_cb (ev_loop *loop, ev_io *w, int revents) +\& { +\& } +\& +\& // create io watchers for each fd and a timer before blocking +\& static void +\& adns_prepare_cb (ev_loop *loop, ev_prepare *w, int revents) +\& { +\& int timeout = 3600000; +\& struct pollfd fds [nfd]; +\& // actual code will need to loop here and realloc etc. +\& adns_beforepoll (ads, fds, &nfd, &timeout, timeval_from (ev_time ())); +\& +\& /* the callback is illegal, but won\*(Aqt be called as we stop during check */ +\& ev_timer_init (&tw, 0, timeout * 1e\-3); +\& ev_timer_start (loop, &tw); +\& +\& // create one ev_io per pollfd +\& for (int i = 0; i < nfd; ++i) +\& { +\& ev_io_init (iow + i, io_cb, fds [i].fd, +\& ((fds [i].events & POLLIN ? EV_READ : 0) +\& | (fds [i].events & POLLOUT ? EV_WRITE : 0))); +\& +\& fds [i].revents = 0; +\& ev_io_start (loop, iow + i); +\& } +\& } +\& +\& // stop all watchers after blocking +\& static void +\& adns_check_cb (ev_loop *loop, ev_check *w, int revents) +\& { +\& ev_timer_stop (loop, &tw); +\& +\& for (int i = 0; i < nfd; ++i) +\& { +\& // set the relevant poll flags +\& // could also call adns_processreadable etc. here +\& struct pollfd *fd = fds + i; +\& int revents = ev_clear_pending (iow + i); +\& if (revents & EV_READ ) fd\->revents |= fd\->events & POLLIN; +\& if (revents & EV_WRITE) fd\->revents |= fd\->events & POLLOUT; +\& +\& // now stop the watcher +\& ev_io_stop (loop, iow + i); +\& } +\& +\& adns_afterpoll (adns, fds, nfd, timeval_from (ev_now (loop)); +\& } +.Ve +.PP +Method 2: This would be just like method 1, but you run \f(CW\*(C`adns_afterpoll\*(C'\fR +in the prepare watcher and would dispose of the check watcher. +.PP +Method 3: If the module to be embedded supports explicit event +notification (adns does), you can also make use of the actual watcher +callbacks, and only destroy/create the watchers in the prepare watcher. +.PP +.Vb 5 +\& static void +\& timer_cb (EV_P_ ev_timer *w, int revents) +\& { +\& adns_state ads = (adns_state)w\->data; +\& update_now (EV_A); +\& +\& adns_processtimeouts (ads, &tv_now); +\& } +\& +\& static void +\& io_cb (EV_P_ ev_io *w, int revents) +\& { +\& adns_state ads = (adns_state)w\->data; +\& update_now (EV_A); +\& +\& if (revents & EV_READ ) adns_processreadable (ads, w\->fd, &tv_now); +\& if (revents & EV_WRITE) adns_processwriteable (ads, w\->fd, &tv_now); +\& } +\& +\& // do not ever call adns_afterpoll +.Ve +.PP +Method 4: Do not use a prepare or check watcher because the module you +want to embed is too inflexible to support it. Instead, youc na override +their poll function. The drawback with this solution is that the main +loop is now no longer controllable by \s-1EV\s0. The \f(CW\*(C`Glib::EV\*(C'\fR module does +this. +.PP +.Vb 4 +\& static gint +\& event_poll_func (GPollFD *fds, guint nfds, gint timeout) +\& { +\& int got_events = 0; +\& +\& for (n = 0; n < nfds; ++n) +\& // create/start io watcher that sets the relevant bits in fds[n] and increment got_events +\& +\& if (timeout >= 0) +\& // create/start timer +\& +\& // poll +\& ev_loop (EV_A_ 0); +\& +\& // stop timer again +\& if (timeout >= 0) +\& ev_timer_stop (EV_A_ &to); +\& +\& // stop io watchers again \- their callbacks should have set +\& for (n = 0; n < nfds; ++n) +\& ev_io_stop (EV_A_ iow [n]); +\& +\& return got_events; +\& } +.Ve +.ie n .Sh """ev_embed"" \- when one backend isn't enough..." +.el .Sh "\f(CWev_embed\fP \- when one backend isn't enough..." +.IX Subsection "ev_embed - when one backend isn't enough..." +This is a rather advanced watcher type that lets you embed one event loop +into another (currently only \f(CW\*(C`ev_io\*(C'\fR events are supported in the embedded +loop, other types of watchers might be handled in a delayed or incorrect +fashion and must not be used). +.PP +There are primarily two reasons you would want that: work around bugs and +prioritise I/O. +.PP +As an example for a bug workaround, the kqueue backend might only support +sockets on some platform, so it is unusable as generic backend, but you +still want to make use of it because you have many sockets and it scales +so nicely. In this case, you would create a kqueue-based loop and embed it +into your default loop (which might use e.g. poll). Overall operation will +be a bit slower because first libev has to poll and then call kevent, but +at least you can use both at what they are best. +.PP +As for prioritising I/O: rarely you have the case where some fds have +to be watched and handled very quickly (with low latency), and even +priorities and idle watchers might have too much overhead. In this case +you would put all the high priority stuff in one loop and all the rest in +a second one, and embed the second one in the first. +.PP +As long as the watcher is active, the callback will be invoked every time +there might be events pending in the embedded loop. The callback must then +call \f(CW\*(C`ev_embed_sweep (mainloop, watcher)\*(C'\fR to make a single sweep and invoke +their callbacks (you could also start an idle watcher to give the embedded +loop strictly lower priority for example). You can also set the callback +to \f(CW0\fR, in which case the embed watcher will automatically execute the +embedded loop sweep. +.PP +As long as the watcher is started it will automatically handle events. The +callback will be invoked whenever some events have been handled. You can +set the callback to \f(CW0\fR to avoid having to specify one if you are not +interested in that. +.PP +Also, there have not currently been made special provisions for forking: +when you fork, you not only have to call \f(CW\*(C`ev_loop_fork\*(C'\fR on both loops, +but you will also have to stop and restart any \f(CW\*(C`ev_embed\*(C'\fR watchers +yourself. +.PP +Unfortunately, not all backends are embeddable, only the ones returned by +\&\f(CW\*(C`ev_embeddable_backends\*(C'\fR are, which, unfortunately, does not include any +portable one. +.PP +So when you want to use this feature you will always have to be prepared +that you cannot get an embeddable loop. The recommended way to get around +this is to have a separate variables for your embeddable loop, try to +create it, and if that fails, use the normal loop for everything. +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)" 4 +.IX Item "ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)" +.PD 0 +.IP "ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop)" 4 +.IX Item "ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop)" +.PD +Configures the watcher to embed the given loop, which must be +embeddable. If the callback is \f(CW0\fR, then \f(CW\*(C`ev_embed_sweep\*(C'\fR will be +invoked automatically, otherwise it is the responsibility of the callback +to invoke it (it will continue to be called until the sweep has been done, +if you do not want thta, you need to temporarily stop the embed watcher). +.IP "ev_embed_sweep (loop, ev_embed *)" 4 +.IX Item "ev_embed_sweep (loop, ev_embed *)" +Make a single, non-blocking sweep over the embedded loop. This works +similarly to \f(CW\*(C`ev_loop (embedded_loop, EVLOOP_NONBLOCK)\*(C'\fR, but in the most +apropriate way for embedded loops. +.IP "struct ev_loop *other [read\-only]" 4 +.IX Item "struct ev_loop *other [read-only]" +The embedded event loop. +.PP +\fIExamples\fR +.IX Subsection "Examples" +.PP +Example: Try to get an embeddable event loop and embed it into the default +event loop. If that is not possible, use the default loop. The default +loop is stored in \f(CW\*(C`loop_hi\*(C'\fR, while the mebeddable loop is stored in +\&\f(CW\*(C`loop_lo\*(C'\fR (which is \f(CW\*(C`loop_hi\*(C'\fR in the acse no embeddable loop can be +used). +.PP +.Vb 3 +\& struct ev_loop *loop_hi = ev_default_init (0); +\& struct ev_loop *loop_lo = 0; +\& struct ev_embed embed; +\& +\& // see if there is a chance of getting one that works +\& // (remember that a flags value of 0 means autodetection) +\& loop_lo = ev_embeddable_backends () & ev_recommended_backends () +\& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ()) +\& : 0; +\& +\& // if we got one, then embed it, otherwise default to loop_hi +\& if (loop_lo) +\& { +\& ev_embed_init (&embed, 0, loop_lo); +\& ev_embed_start (loop_hi, &embed); +\& } +\& else +\& loop_lo = loop_hi; +.Ve +.PP +Example: Check if kqueue is available but not recommended and create +a kqueue backend for use with sockets (which usually work with any +kqueue implementation). Store the kqueue/socket\-only event loop in +\&\f(CW\*(C`loop_socket\*(C'\fR. (One might optionally use \f(CW\*(C`EVFLAG_NOENV\*(C'\fR, too). +.PP +.Vb 3 +\& struct ev_loop *loop = ev_default_init (0); +\& struct ev_loop *loop_socket = 0; +\& struct ev_embed embed; +\& +\& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) +\& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) +\& { +\& ev_embed_init (&embed, 0, loop_socket); +\& ev_embed_start (loop, &embed); +\& } +\& +\& if (!loop_socket) +\& loop_socket = loop; +\& +\& // now use loop_socket for all sockets, and loop for everything else +.Ve +.ie n .Sh """ev_fork"" \- the audacity to resume the event loop after a fork" +.el .Sh "\f(CWev_fork\fP \- the audacity to resume the event loop after a fork" +.IX Subsection "ev_fork - the audacity to resume the event loop after a fork" +Fork watchers are called when a \f(CW\*(C`fork ()\*(C'\fR was detected (usually because +whoever is a good citizen cared to tell libev about it by calling +\&\f(CW\*(C`ev_default_fork\*(C'\fR or \f(CW\*(C`ev_loop_fork\*(C'\fR). The invocation is done before the +event loop blocks next and before \f(CW\*(C`ev_check\*(C'\fR watchers are being called, +and only in the child after the fork. If whoever good citizen calling +\&\f(CW\*(C`ev_default_fork\*(C'\fR cheats and calls it in the wrong process, the fork +handlers will be invoked, too, of course. +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_fork_init (ev_signal *, callback)" 4 +.IX Item "ev_fork_init (ev_signal *, callback)" +Initialises and configures the fork watcher \- it has no parameters of any +kind. There is a \f(CW\*(C`ev_fork_set\*(C'\fR macro, but using it is utterly pointless, +believe me. +.ie n .Sh """ev_async"" \- how to wake up another event loop" +.el .Sh "\f(CWev_async\fP \- how to wake up another event loop" +.IX Subsection "ev_async - how to wake up another event loop" +In general, you cannot use an \f(CW\*(C`ev_loop\*(C'\fR from multiple threads or other +asynchronous sources such as signal handlers (as opposed to multiple event +loops \- those are of course safe to use in different threads). +.PP +Sometimes, however, you need to wake up another event loop you do not +control, for example because it belongs to another thread. This is what +\&\f(CW\*(C`ev_async\*(C'\fR watchers do: as long as the \f(CW\*(C`ev_async\*(C'\fR watcher is active, you +can signal it by calling \f(CW\*(C`ev_async_send\*(C'\fR, which is thread\- and signal +safe. +.PP +This functionality is very similar to \f(CW\*(C`ev_signal\*(C'\fR watchers, as signals, +too, are asynchronous in nature, and signals, too, will be compressed +(i.e. the number of callback invocations may be less than the number of +\&\f(CW\*(C`ev_async_sent\*(C'\fR calls). +.PP +Unlike \f(CW\*(C`ev_signal\*(C'\fR watchers, \f(CW\*(C`ev_async\*(C'\fR works with any event loop, not +just the default loop. +.PP +\fIQueueing\fR +.IX Subsection "Queueing" +.PP +\&\f(CW\*(C`ev_async\*(C'\fR does not support queueing of data in any way. The reason +is that the author does not know of a simple (or any) algorithm for a +multiple-writer-single-reader queue that works in all cases and doesn't +need elaborate support such as pthreads. +.PP +That means that if you want to queue data, you have to provide your own +queue. But at least I can tell you would implement locking around your +queue: +.IP "queueing from a signal handler context" 4 +.IX Item "queueing from a signal handler context" +To implement race-free queueing, you simply add to the queue in the signal +handler but you block the signal handler in the watcher callback. Here is an example that does that for +some fictitiuous \s-1SIGUSR1\s0 handler: +.Sp +.Vb 1 +\& static ev_async mysig; +\& +\& static void +\& sigusr1_handler (void) +\& { +\& sometype data; +\& +\& // no locking etc. +\& queue_put (data); +\& ev_async_send (EV_DEFAULT_ &mysig); +\& } +\& +\& static void +\& mysig_cb (EV_P_ ev_async *w, int revents) +\& { +\& sometype data; +\& sigset_t block, prev; +\& +\& sigemptyset (&block); +\& sigaddset (&block, SIGUSR1); +\& sigprocmask (SIG_BLOCK, &block, &prev); +\& +\& while (queue_get (&data)) +\& process (data); +\& +\& if (sigismember (&prev, SIGUSR1) +\& sigprocmask (SIG_UNBLOCK, &block, 0); +\& } +.Ve +.Sp +(Note: pthreads in theory requires you to use \f(CW\*(C`pthread_setmask\*(C'\fR +instead of \f(CW\*(C`sigprocmask\*(C'\fR when you use threads, but libev doesn't do it +either...). +.IP "queueing from a thread context" 4 +.IX Item "queueing from a thread context" +The strategy for threads is different, as you cannot (easily) block +threads but you can easily preempt them, so to queue safely you need to +employ a traditional mutex lock, such as in this pthread example: +.Sp +.Vb 2 +\& static ev_async mysig; +\& static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER; +\& +\& static void +\& otherthread (void) +\& { +\& // only need to lock the actual queueing operation +\& pthread_mutex_lock (&mymutex); +\& queue_put (data); +\& pthread_mutex_unlock (&mymutex); +\& +\& ev_async_send (EV_DEFAULT_ &mysig); +\& } +\& +\& static void +\& mysig_cb (EV_P_ ev_async *w, int revents) +\& { +\& pthread_mutex_lock (&mymutex); +\& +\& while (queue_get (&data)) +\& process (data); +\& +\& pthread_mutex_unlock (&mymutex); +\& } +.Ve +.PP +\fIWatcher-Specific Functions and Data Members\fR +.IX Subsection "Watcher-Specific Functions and Data Members" +.IP "ev_async_init (ev_async *, callback)" 4 +.IX Item "ev_async_init (ev_async *, callback)" +Initialises and configures the async watcher \- it has no parameters of any +kind. There is a \f(CW\*(C`ev_asynd_set\*(C'\fR macro, but using it is utterly pointless, +believe me. +.IP "ev_async_send (loop, ev_async *)" 4 +.IX Item "ev_async_send (loop, ev_async *)" +Sends/signals/activates the given \f(CW\*(C`ev_async\*(C'\fR watcher, that is, feeds +an \f(CW\*(C`EV_ASYNC\*(C'\fR event on the watcher into the event loop. Unlike +\&\f(CW\*(C`ev_feed_event\*(C'\fR, this call is safe to do in other threads, signal or +similar contexts (see the dicusssion of \f(CW\*(C`EV_ATOMIC_T\*(C'\fR in the embedding +section below on what exactly this means). +.Sp +This call incurs the overhead of a syscall only once per loop iteration, +so while the overhead might be noticable, it doesn't apply to repeated +calls to \f(CW\*(C`ev_async_send\*(C'\fR. +.IP "bool = ev_async_pending (ev_async *)" 4 +.IX Item "bool = ev_async_pending (ev_async *)" +Returns a non-zero value when \f(CW\*(C`ev_async_send\*(C'\fR has been called on the +watcher but the event has not yet been processed (or even noted) by the +event loop. +.Sp +\&\f(CW\*(C`ev_async_send\*(C'\fR sets a flag in the watcher and wakes up the loop. When +the loop iterates next and checks for the watcher to have become active, +it will reset the flag again. \f(CW\*(C`ev_async_pending\*(C'\fR can be used to very +quickly check wether invoking the loop might be a good idea. +.Sp +Not that this does \fInot\fR check wether the watcher itself is pending, only +wether it has been requested to make this watcher pending. +.SH "OTHER FUNCTIONS" +.IX Header "OTHER FUNCTIONS" +There are some other functions of possible interest. Described. Here. Now. +.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 +.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" +This function combines a simple timer and an I/O watcher, calls your +callback on whichever event happens first and automatically stop both +watchers. This is useful if you want to wait for a single event on an fd +or timeout without having to allocate/configure/start/stop/free one or +more watchers yourself. +.Sp +If \f(CW\*(C`fd\*(C'\fR is less than 0, then no I/O watcher will be started and events +is being ignored. Otherwise, an \f(CW\*(C`ev_io\*(C'\fR watcher for the given \f(CW\*(C`fd\*(C'\fR and +\&\f(CW\*(C`events\*(C'\fR set will be craeted and started. +.Sp +If \f(CW\*(C`timeout\*(C'\fR is less than 0, then no timeout watcher will be +started. Otherwise an \f(CW\*(C`ev_timer\*(C'\fR watcher with after = \f(CW\*(C`timeout\*(C'\fR (and +repeat = 0) will be started. While \f(CW0\fR is a valid timeout, it is of +dubious value. +.Sp +The callback has the type \f(CW\*(C`void (*cb)(int revents, void *arg)\*(C'\fR and gets +passed an \f(CW\*(C`revents\*(C'\fR set like normal event callbacks (a combination of +\&\f(CW\*(C`EV_ERROR\*(C'\fR, \f(CW\*(C`EV_READ\*(C'\fR, \f(CW\*(C`EV_WRITE\*(C'\fR or \f(CW\*(C`EV_TIMEOUT\*(C'\fR) and the \f(CW\*(C`arg\*(C'\fR +value passed to \f(CW\*(C`ev_once\*(C'\fR: +.Sp +.Vb 7 +\& static void stdin_ready (int revents, void *arg) +\& { +\& if (revents & EV_TIMEOUT) +\& /* doh, nothing entered */; +\& else if (revents & EV_READ) +\& /* stdin might have data for us, joy! */; +\& } +\& +\& ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0); +.Ve +.IP "ev_feed_event (ev_loop *, watcher *, int revents)" 4 +.IX Item "ev_feed_event (ev_loop *, watcher *, int revents)" +Feeds the given event set into the event loop, as if the specified event +had happened for the specified watcher (which must be a pointer to an +initialised but not necessarily started event watcher). +.IP "ev_feed_fd_event (ev_loop *, int fd, int revents)" 4 +.IX Item "ev_feed_fd_event (ev_loop *, int fd, int revents)" +Feed an event on the given fd, as if a file descriptor backend detected +the given events it. +.IP "ev_feed_signal_event (ev_loop *loop, int signum)" 4 +.IX Item "ev_feed_signal_event (ev_loop *loop, int signum)" +Feed an event as if the given signal occured (\f(CW\*(C`loop\*(C'\fR must be the default +loop!). +.SH "LIBEVENT EMULATION" +.IX Header "LIBEVENT EMULATION" +Libev offers a compatibility emulation layer for libevent. It cannot +emulate the internals of libevent, so here are some usage hints: +.IP "\(bu" 4 +Use it by including , as usual. +.IP "\(bu" 4 +The following members are fully supported: ev_base, ev_callback, +ev_arg, ev_fd, ev_res, ev_events. +.IP "\(bu" 4 +Avoid using ev_flags and the EVLIST_*\-macros, while it is +maintained by libev, it does not work exactly the same way as in libevent (consider +it a private \s-1API\s0). +.IP "\(bu" 4 +Priorities are not currently supported. Initialising priorities +will fail and all watchers will have the same priority, even though there +is an ev_pri field. +.IP "\(bu" 4 +In libevent, the last base created gets the signals, in libev, the +first base created (== the default loop) gets the signals. +.IP "\(bu" 4 +Other members are not supported. +.IP "\(bu" 4 +The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need +to use the libev header file and library. +.SH "\*(C+ SUPPORT" +.IX Header " SUPPORT" +Libev comes with some simplistic wrapper classes for \*(C+ that mainly allow +you to use some convinience methods to start/stop watchers and also change +the callback model to a model using method callbacks on objects. +.PP +To use it, +.PP +.Vb 1 +\& #include +.Ve +.PP +This automatically includes \fIev.h\fR and puts all of its definitions (many +of them macros) into the global namespace. All \*(C+ specific things are +put into the \f(CW\*(C`ev\*(C'\fR namespace. It should support all the same embedding +options as \fIev.h\fR, most notably \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. +.PP +Care has been taken to keep the overhead low. The only data member the \*(C+ +classes add (compared to plain C\-style watchers) is the event loop pointer +that the watcher is associated with (or no additional members at all if +you disable \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR when embedding libev). +.PP +Currently, functions, and static and non-static member functions can be +used as callbacks. Other types should be easy to add as long as they only +need one additional pointer for context. If you need support for other +types of functors please contact the author (preferably after implementing +it). +.PP +Here is a list of things available in the \f(CW\*(C`ev\*(C'\fR namespace: +.ie n .IP """ev::READ""\fR, \f(CW""ev::WRITE"" etc." 4 +.el .IP "\f(CWev::READ\fR, \f(CWev::WRITE\fR etc." 4 +.IX Item "ev::READ, ev::WRITE etc." +These are just enum values with the same values as the \f(CW\*(C`EV_READ\*(C'\fR etc. +macros from \fIev.h\fR. +.ie n .IP """ev::tstamp""\fR, \f(CW""ev::now""" 4 +.el .IP "\f(CWev::tstamp\fR, \f(CWev::now\fR" 4 +.IX Item "ev::tstamp, ev::now" +Aliases to the same types/functions as with the \f(CW\*(C`ev_\*(C'\fR prefix. +.ie n .IP """ev::io""\fR, \f(CW""ev::timer""\fR, \f(CW""ev::periodic""\fR, \f(CW""ev::idle""\fR, \f(CW""ev::sig"" etc." 4 +.el .IP "\f(CWev::io\fR, \f(CWev::timer\fR, \f(CWev::periodic\fR, \f(CWev::idle\fR, \f(CWev::sig\fR etc." 4 +.IX Item "ev::io, ev::timer, ev::periodic, ev::idle, ev::sig etc." +For each \f(CW\*(C`ev_TYPE\*(C'\fR watcher in \fIev.h\fR there is a corresponding class of +the same name in the \f(CW\*(C`ev\*(C'\fR namespace, with the exception of \f(CW\*(C`ev_signal\*(C'\fR +which is called \f(CW\*(C`ev::sig\*(C'\fR to avoid clashes with the \f(CW\*(C`signal\*(C'\fR macro +defines by many implementations. +.Sp +All of those classes have these methods: +.RS 4 +.IP "ev::TYPE::TYPE ()" 4 +.IX Item "ev::TYPE::TYPE ()" +.PD 0 +.IP "ev::TYPE::TYPE (struct ev_loop *)" 4 +.IX Item "ev::TYPE::TYPE (struct ev_loop *)" +.IP "ev::TYPE::~TYPE" 4 +.IX Item "ev::TYPE::~TYPE" +.PD +The constructor (optionally) takes an event loop to associate the watcher +with. If it is omitted, it will use \f(CW\*(C`EV_DEFAULT\*(C'\fR. +.Sp +The constructor calls \f(CW\*(C`ev_init\*(C'\fR for you, which means you have to call the +\&\f(CW\*(C`set\*(C'\fR method before starting it. +.Sp +It will not set a callback, however: You have to call the templated \f(CW\*(C`set\*(C'\fR +method to set a callback before you can start the watcher. +.Sp +(The reason why you have to use a method is a limitation in \*(C+ which does +not allow explicit template arguments for constructors). +.Sp +The destructor automatically stops the watcher if it is active. +.IP "w\->set (object *)" 4 +.IX Item "w->set (object *)" +This method sets the callback method to call. The method has to have a +signature of \f(CW\*(C`void (*)(ev_TYPE &, int)\*(C'\fR, it receives the watcher as +first argument and the \f(CW\*(C`revents\*(C'\fR as second. The object must be given as +parameter and is stored in the \f(CW\*(C`data\*(C'\fR member of the watcher. +.Sp +This method synthesizes efficient thunking code to call your method from +the C callback that libev requires. If your compiler can inline your +callback (i.e. it is visible to it at the place of the \f(CW\*(C`set\*(C'\fR call and +your compiler is good :), then the method will be fully inlined into the +thunking function, making it as fast as a direct C callback. +.Sp +Example: simple class declaration and watcher initialisation +.Sp +.Vb 4 +\& struct myclass +\& { +\& void io_cb (ev::io &w, int revents) { } +\& } +\& +\& myclass obj; +\& ev::io iow; +\& iow.set (&obj); +.Ve +.IP "w\->set (void *data = 0)" 4 +.IX Item "w->set (void *data = 0)" +Also sets a callback, but uses a static method or plain function as +callback. The optional \f(CW\*(C`data\*(C'\fR argument will be stored in the watcher's +\&\f(CW\*(C`data\*(C'\fR member and is free for you to use. +.Sp +The prototype of the \f(CW\*(C`function\*(C'\fR must be \f(CW\*(C`void (*)(ev::TYPE &w, int)\*(C'\fR. +.Sp +See the method\-\f(CW\*(C`set\*(C'\fR above for more details. +.Sp +Example: +.Sp +.Vb 2 +\& static void io_cb (ev::io &w, int revents) { } +\& iow.set (); +.Ve +.IP "w\->set (struct ev_loop *)" 4 +.IX Item "w->set (struct ev_loop *)" +Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only +do this when the watcher is inactive (and not pending either). +.IP "w\->set ([args])" 4 +.IX Item "w->set ([args])" +Basically the same as \f(CW\*(C`ev_TYPE_set\*(C'\fR, with the same args. Must be +called at least once. Unlike the C counterpart, an active watcher gets +automatically stopped and restarted when reconfiguring it with this +method. +.IP "w\->start ()" 4 +.IX Item "w->start ()" +Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the +constructor already stores the event loop. +.IP "w\->stop ()" 4 +.IX Item "w->stop ()" +Stops the watcher if it is active. Again, no \f(CW\*(C`loop\*(C'\fR argument. +.ie n .IP "w\->again () (""ev::timer""\fR, \f(CW""ev::periodic"" only)" 4 +.el .IP "w\->again () (\f(CWev::timer\fR, \f(CWev::periodic\fR only)" 4 +.IX Item "w->again () (ev::timer, ev::periodic only)" +For \f(CW\*(C`ev::timer\*(C'\fR and \f(CW\*(C`ev::periodic\*(C'\fR, this invokes the corresponding +\&\f(CW\*(C`ev_TYPE_again\*(C'\fR function. +.ie n .IP "w\->sweep () (""ev::embed"" only)" 4 +.el .IP "w\->sweep () (\f(CWev::embed\fR only)" 4 +.IX Item "w->sweep () (ev::embed only)" +Invokes \f(CW\*(C`ev_embed_sweep\*(C'\fR. +.ie n .IP "w\->update () (""ev::stat"" only)" 4 +.el .IP "w\->update () (\f(CWev::stat\fR only)" 4 +.IX Item "w->update () (ev::stat only)" +Invokes \f(CW\*(C`ev_stat_stat\*(C'\fR. +.RE +.RS 4 +.RE +.PP +Example: Define a class with an \s-1IO\s0 and idle watcher, start one of them in +the constructor. +.PP +.Vb 4 +\& class myclass +\& { +\& ev::io io; void io_cb (ev::io &w, int revents); +\& ev:idle idle void idle_cb (ev::idle &w, int revents); +\& +\& myclass (int fd) +\& { +\& io .set (this); +\& idle.set (this); +\& +\& io.start (fd, ev::READ); +\& } +\& }; +.Ve +.SH "OTHER LANGUAGE BINDINGS" +.IX Header "OTHER LANGUAGE BINDINGS" +Libev does not offer other language bindings itself, but bindings for a +numbe rof languages exist in the form of third-party packages. If you know +any interesting language binding in addition to the ones listed here, drop +me a note. +.IP "Perl" 4 +.IX Item "Perl" +The \s-1EV\s0 module implements the full libev \s-1API\s0 and is actually used to test +libev. \s-1EV\s0 is developed together with libev. Apart from the \s-1EV\s0 core module, +there are additional modules that implement libev-compatible interfaces +to \f(CW\*(C`libadns\*(C'\fR (\f(CW\*(C`EV::ADNS\*(C'\fR), \f(CW\*(C`Net::SNMP\*(C'\fR (\f(CW\*(C`Net::SNMP::EV\*(C'\fR) and the +\&\f(CW\*(C`libglib\*(C'\fR event core (\f(CW\*(C`Glib::EV\*(C'\fR and \f(CW\*(C`EV::Glib\*(C'\fR). +.Sp +It can be found and installed via \s-1CPAN\s0, its homepage is found at +. +.IP "Ruby" 4 +.IX Item "Ruby" +Tony Arcieri has written a ruby extension that offers access to a subset +of the libev \s-1API\s0 and adds filehandle abstractions, asynchronous \s-1DNS\s0 and +more on top of it. It can be found via gem servers. Its homepage is at +. +.IP "D" 4 +.IX Item "D" +Leandro Lucarella has written a D language binding (\fIev.d\fR) for libev, to +be found at . +.SH "MACRO MAGIC" +.IX Header "MACRO MAGIC" +Libev can be compiled with a variety of options, the most fundamantal +of which is \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. This option determines whether (most) +functions and callbacks have an initial \f(CW\*(C`struct ev_loop *\*(C'\fR argument. +.PP +To make it easier to write programs that cope with either variant, the +following macros are defined: +.ie n .IP """EV_A""\fR, \f(CW""EV_A_""" 4 +.el .IP "\f(CWEV_A\fR, \f(CWEV_A_\fR" 4 +.IX Item "EV_A, EV_A_" +This provides the loop \fIargument\fR for functions, if one is required (\*(L"ev +loop argument\*(R"). The \f(CW\*(C`EV_A\*(C'\fR form is used when this is the sole argument, +\&\f(CW\*(C`EV_A_\*(C'\fR is used when other arguments are following. Example: +.Sp +.Vb 3 +\& ev_unref (EV_A); +\& ev_timer_add (EV_A_ watcher); +\& ev_loop (EV_A_ 0); +.Ve +.Sp +It assumes the variable \f(CW\*(C`loop\*(C'\fR of type \f(CW\*(C`struct ev_loop *\*(C'\fR is in scope, +which is often provided by the following macro. +.ie n .IP """EV_P""\fR, \f(CW""EV_P_""" 4 +.el .IP "\f(CWEV_P\fR, \f(CWEV_P_\fR" 4 +.IX Item "EV_P, EV_P_" +This provides the loop \fIparameter\fR for functions, if one is required (\*(L"ev +loop parameter\*(R"). The \f(CW\*(C`EV_P\*(C'\fR form is used when this is the sole parameter, +\&\f(CW\*(C`EV_P_\*(C'\fR is used when other parameters are following. Example: +.Sp +.Vb 2 +\& // this is how ev_unref is being declared +\& static void ev_unref (EV_P); +\& +\& // this is how you can declare your typical callback +\& static void cb (EV_P_ ev_timer *w, int revents) +.Ve +.Sp +It declares a parameter \f(CW\*(C`loop\*(C'\fR of type \f(CW\*(C`struct ev_loop *\*(C'\fR, quite +suitable for use with \f(CW\*(C`EV_A\*(C'\fR. +.ie n .IP """EV_DEFAULT""\fR, \f(CW""EV_DEFAULT_""" 4 +.el .IP "\f(CWEV_DEFAULT\fR, \f(CWEV_DEFAULT_\fR" 4 +.IX Item "EV_DEFAULT, EV_DEFAULT_" +Similar to the other two macros, this gives you the value of the default +loop, if multiple loops are supported (\*(L"ev loop default\*(R"). +.ie n .IP """EV_DEFAULT_UC""\fR, \f(CW""EV_DEFAULT_UC_""" 4 +.el .IP "\f(CWEV_DEFAULT_UC\fR, \f(CWEV_DEFAULT_UC_\fR" 4 +.IX Item "EV_DEFAULT_UC, EV_DEFAULT_UC_" +Usage identical to \f(CW\*(C`EV_DEFAULT\*(C'\fR and \f(CW\*(C`EV_DEFAULT_\*(C'\fR, but requires that the +default loop has been initialised (\f(CW\*(C`UC\*(C'\fR == unchecked). Their behaviour +is undefined when the default loop has not been initialised by a previous +execution of \f(CW\*(C`EV_DEFAULT\*(C'\fR, \f(CW\*(C`EV_DEFAULT_\*(C'\fR or \f(CW\*(C`ev_default_init (...)\*(C'\fR. +.Sp +It is often prudent to use \f(CW\*(C`EV_DEFAULT\*(C'\fR when initialising the first +watcher in a function but use \f(CW\*(C`EV_DEFAULT_UC\*(C'\fR afterwards. +.PP +Example: Declare and initialise a check watcher, utilising the above +macros so it will work regardless of whether multiple loops are supported +or not. +.PP +.Vb 5 +\& static void +\& check_cb (EV_P_ ev_timer *w, int revents) +\& { +\& ev_check_stop (EV_A_ w); +\& } +\& +\& ev_check check; +\& ev_check_init (&check, check_cb); +\& ev_check_start (EV_DEFAULT_ &check); +\& ev_loop (EV_DEFAULT_ 0); +.Ve +.SH "EMBEDDING" +.IX Header "EMBEDDING" +Libev can (and often is) directly embedded into host +applications. Examples of applications that embed it include the Deliantra +Game Server, the \s-1EV\s0 perl module, the \s-1GNU\s0 Virtual Private Ethernet (gvpe) +and rxvt-unicode. +.PP +The goal is to enable you to just copy the necessary files into your +source directory without having to change even a single line in them, so +you can easily upgrade by simply copying (or having a checked-out copy of +libev somewhere in your source tree). +.Sh "\s-1FILESETS\s0" +.IX Subsection "FILESETS" +Depending on what features you need you need to include one or more sets of files +in your app. +.PP +\fI\s-1CORE\s0 \s-1EVENT\s0 \s-1LOOP\s0\fR +.IX Subsection "CORE EVENT LOOP" +.PP +To include only the libev core (all the \f(CW\*(C`ev_*\*(C'\fR functions), with manual +configuration (no autoconf): +.PP +.Vb 2 +\& #define EV_STANDALONE 1 +\& #include "ev.c" +.Ve +.PP +This will automatically include \fIev.h\fR, too, and should be done in a +single C source file only to provide the function implementations. To use +it, do the same for \fIev.h\fR in all files wishing to use this \s-1API\s0 (best +done by writing a wrapper around \fIev.h\fR that you can include instead and +where you can put other configuration options): +.PP +.Vb 2 +\& #define EV_STANDALONE 1 +\& #include "ev.h" +.Ve +.PP +Both header files and implementation files can be compiled with a \*(C+ +compiler (at least, thats a stated goal, and breakage will be treated +as a bug). +.PP +You need the following files in your source tree, or in a directory +in your include path (e.g. in libev/ when using \-Ilibev): +.PP +.Vb 4 +\& ev.h +\& ev.c +\& ev_vars.h +\& ev_wrap.h +\& +\& ev_win32.c required on win32 platforms only +\& +\& ev_select.c only when select backend is enabled (which is enabled by default) +\& ev_poll.c only when poll backend is enabled (disabled by default) +\& ev_epoll.c only when the epoll backend is enabled (disabled by default) +\& ev_kqueue.c only when the kqueue backend is enabled (disabled by default) +\& ev_port.c only when the solaris port backend is enabled (disabled by default) +.Ve +.PP +\&\fIev.c\fR includes the backend files directly when enabled, so you only need +to compile this single file. +.PP +\fI\s-1LIBEVENT\s0 \s-1COMPATIBILITY\s0 \s-1API\s0\fR +.IX Subsection "LIBEVENT COMPATIBILITY API" +.PP +To include the libevent compatibility \s-1API\s0, also include: +.PP +.Vb 1 +\& #include "event.c" +.Ve +.PP +in the file including \fIev.c\fR, and: +.PP +.Vb 1 +\& #include "event.h" +.Ve +.PP +in the files that want to use the libevent \s-1API\s0. This also includes \fIev.h\fR. +.PP +You need the following additional files for this: +.PP +.Vb 2 +\& event.h +\& event.c +.Ve +.PP +\fI\s-1AUTOCONF\s0 \s-1SUPPORT\s0\fR +.IX Subsection "AUTOCONF SUPPORT" +.PP +Instead of using \f(CW\*(C`EV_STANDALONE=1\*(C'\fR and providing your config in +whatever way you want, you can also \f(CW\*(C`m4_include([libev.m4])\*(C'\fR in your +\&\fIconfigure.ac\fR and leave \f(CW\*(C`EV_STANDALONE\*(C'\fR undefined. \fIev.c\fR will then +include \fIconfig.h\fR and configure itself accordingly. +.PP +For this of course you need the m4 file: +.PP +.Vb 1 +\& libev.m4 +.Ve +.Sh "\s-1PREPROCESSOR\s0 \s-1SYMBOLS/MACROS\s0" +.IX Subsection "PREPROCESSOR SYMBOLS/MACROS" +Libev can be configured via a variety of preprocessor symbols you have to +define before including any of its files. The default in the absense of +autoconf is noted for every option. +.IP "\s-1EV_STANDALONE\s0" 4 +.IX Item "EV_STANDALONE" +Must always be \f(CW1\fR if you do not use autoconf configuration, which +keeps libev from including \fIconfig.h\fR, and it also defines dummy +implementations for some libevent functions (such as logging, which is not +supported). It will also not define any of the structs usually found in +\&\fIevent.h\fR that are not directly supported by the libev core alone. +.IP "\s-1EV_USE_MONOTONIC\s0" 4 +.IX Item "EV_USE_MONOTONIC" +If defined to be \f(CW1\fR, libev will try to detect the availability of the +monotonic clock option at both compiletime and runtime. Otherwise no use +of the monotonic clock option will be attempted. If you enable this, you +usually have to link against librt or something similar. Enabling it when +the functionality isn't available is safe, though, although you have +to make sure you link against any libraries where the \f(CW\*(C`clock_gettime\*(C'\fR +function is hiding in (often \fI\-lrt\fR). +.IP "\s-1EV_USE_REALTIME\s0" 4 +.IX Item "EV_USE_REALTIME" +If defined to be \f(CW1\fR, libev will try to detect the availability of the +realtime clock option at compiletime (and assume its availability at +runtime if successful). Otherwise no use of the realtime clock option will +be attempted. This effectively replaces \f(CW\*(C`gettimeofday\*(C'\fR by \f(CW\*(C`clock_get +(CLOCK_REALTIME, ...)\*(C'\fR and will not normally affect correctness. See the +note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though. +.IP "\s-1EV_USE_NANOSLEEP\s0" 4 +.IX Item "EV_USE_NANOSLEEP" +If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available +and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. +.IP "\s-1EV_USE_EVENTFD\s0" 4 +.IX Item "EV_USE_EVENTFD" +If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is +available and will probe for kernel support at runtime. This will improve +\&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. +If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc +2.7 or newer, otherwise disabled. +.IP "\s-1EV_USE_SELECT\s0" 4 +.IX Item "EV_USE_SELECT" +If undefined or defined to be \f(CW1\fR, libev will compile in support for the +\&\f(CW\*(C`select\*(C'\fR(2) backend. No attempt at autodetection will be done: if no +other method takes over, select will be it. Otherwise the select backend +will not be compiled in. +.IP "\s-1EV_SELECT_USE_FD_SET\s0" 4 +.IX Item "EV_SELECT_USE_FD_SET" +If defined to \f(CW1\fR, then the select backend will use the system \f(CW\*(C`fd_set\*(C'\fR +structure. This is useful if libev doesn't compile due to a missing +\&\f(CW\*(C`NFDBITS\*(C'\fR or \f(CW\*(C`fd_mask\*(C'\fR definition or it misguesses the bitset layout on +exotic systems. This usually limits the range of file descriptors to some +low limit such as 1024 or might have other limitations (winsocket only +allows 64 sockets). The \f(CW\*(C`FD_SETSIZE\*(C'\fR macro, set before compilation, might +influence the size of the \f(CW\*(C`fd_set\*(C'\fR used. +.IP "\s-1EV_SELECT_IS_WINSOCKET\s0" 4 +.IX Item "EV_SELECT_IS_WINSOCKET" +When defined to \f(CW1\fR, the select backend will assume that +select/socket/connect etc. don't understand file descriptors but +wants osf handles on win32 (this is the case when the select to +be used is the winsock select). This means that it will call +\&\f(CW\*(C`_get_osfhandle\*(C'\fR on the fd to convert it to an \s-1OS\s0 handle. Otherwise, +it is assumed that all these functions actually work on fds, even +on win32. Should not be defined on non\-win32 platforms. +.IP "\s-1EV_FD_TO_WIN32_HANDLE\s0" 4 +.IX Item "EV_FD_TO_WIN32_HANDLE" +If \f(CW\*(C`EV_SELECT_IS_WINSOCKET\*(C'\fR is enabled, then libev needs a way to map +file descriptors to socket handles. When not defining this symbol (the +default), then libev will call \f(CW\*(C`_get_osfhandle\*(C'\fR, which is usually +correct. In some cases, programs use their own file descriptor management, +in which case they can provide this function to map fds to socket handles. +.IP "\s-1EV_USE_POLL\s0" 4 +.IX Item "EV_USE_POLL" +If defined to be \f(CW1\fR, libev will compile in support for the \f(CW\*(C`poll\*(C'\fR(2) +backend. Otherwise it will be enabled on non\-win32 platforms. It +takes precedence over select. +.IP "\s-1EV_USE_EPOLL\s0" 4 +.IX Item "EV_USE_EPOLL" +If defined to be \f(CW1\fR, libev will compile in support for the Linux +\&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, +otherwise another method will be used as fallback. This is the preferred +backend for GNU/Linux systems. If undefined, it will be enabled if the +headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. +.IP "\s-1EV_USE_KQUEUE\s0" 4 +.IX Item "EV_USE_KQUEUE" +If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style +\&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, +otherwise another method will be used as fallback. This is the preferred +backend for \s-1BSD\s0 and BSD-like systems, although on most BSDs kqueue only +supports some types of fds correctly (the only platform we found that +supports ptys for example was NetBSD), so kqueue might be compiled in, but +not be used unless explicitly requested. The best way to use it is to find +out whether kqueue supports your type of fd properly and use an embedded +kqueue loop. +.IP "\s-1EV_USE_PORT\s0" 4 +.IX Item "EV_USE_PORT" +If defined to be \f(CW1\fR, libev will compile in support for the Solaris +10 port style backend. Its availability will be detected at runtime, +otherwise another method will be used as fallback. This is the preferred +backend for Solaris 10 systems. +.IP "\s-1EV_USE_DEVPOLL\s0" 4 +.IX Item "EV_USE_DEVPOLL" +reserved for future expansion, works like the \s-1USE\s0 symbols above. +.IP "\s-1EV_USE_INOTIFY\s0" 4 +.IX Item "EV_USE_INOTIFY" +If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify +interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will +be detected at runtime. If undefined, it will be enabled if the headers +indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. +.IP "\s-1EV_ATOMIC_T\s0" 4 +.IX Item "EV_ATOMIC_T" +Libev requires an integer type (suitable for storing \f(CW0\fR or \f(CW1\fR) whose +access is atomic with respect to other threads or signal contexts. No such +type is easily found in the C language, so you can provide your own type +that you know is safe for your purposes. It is used both for signal handler \*(L"locking\*(R" +as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR watchers. +.Sp +In the absense of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR +(from \fIsignal.h\fR), which is usually good enough on most platforms. +.IP "\s-1EV_H\s0" 4 +.IX Item "EV_H" +The name of the \fIev.h\fR header file used to include it. The default if +undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be +used to virtually rename the \fIev.h\fR header file in case of conflicts. +.IP "\s-1EV_CONFIG_H\s0" 4 +.IX Item "EV_CONFIG_H" +If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn't \f(CW1\fR, this variable can be used to override +\&\fIev.c\fR's idea of where to find the \fIconfig.h\fR file, similarly to +\&\f(CW\*(C`EV_H\*(C'\fR, above. +.IP "\s-1EV_EVENT_H\s0" 4 +.IX Item "EV_EVENT_H" +Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR's idea +of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR. +.IP "\s-1EV_PROTOTYPES\s0" 4 +.IX Item "EV_PROTOTYPES" +If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function +prototypes, but still define all the structs and other symbols. This is +occasionally useful if you want to provide your own wrapper functions +around libev functions. +.IP "\s-1EV_MULTIPLICITY\s0" 4 +.IX Item "EV_MULTIPLICITY" +If undefined or defined to \f(CW1\fR, then all event-loop-specific functions +will have the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument, and you can create +additional independent event loops. Otherwise there will be no support +for multiple event loops and there is no first event loop pointer +argument. Instead, all functions act on the single default loop. +.IP "\s-1EV_MINPRI\s0" 4 +.IX Item "EV_MINPRI" +.PD 0 +.IP "\s-1EV_MAXPRI\s0" 4 +.IX Item "EV_MAXPRI" +.PD +The range of allowed priorities. \f(CW\*(C`EV_MINPRI\*(C'\fR must be smaller or equal to +\&\f(CW\*(C`EV_MAXPRI\*(C'\fR, but otherwise there are no non-obvious limitations. You can +provide for more priorities by overriding those symbols (usually defined +to be \f(CW\*(C`\-2\*(C'\fR and \f(CW2\fR, respectively). +.Sp +When doing priority-based operations, libev usually has to linearly search +all the priorities, so having many of them (hundreds) uses a lot of space +and time, so using the defaults of five priorities (\-2 .. +2) is usually +fine. +.Sp +If your embedding app does not need any priorities, defining these both to +\&\f(CW0\fR will save some memory and cpu. +.IP "\s-1EV_PERIODIC_ENABLE\s0" 4 +.IX Item "EV_PERIODIC_ENABLE" +If undefined or defined to be \f(CW1\fR, then periodic timers are supported. If +defined to be \f(CW0\fR, then they are not. Disabling them saves a few kB of +code. +.IP "\s-1EV_IDLE_ENABLE\s0" 4 +.IX Item "EV_IDLE_ENABLE" +If undefined or defined to be \f(CW1\fR, then idle watchers are supported. If +defined to be \f(CW0\fR, then they are not. Disabling them saves a few kB of +code. +.IP "\s-1EV_EMBED_ENABLE\s0" 4 +.IX Item "EV_EMBED_ENABLE" +If undefined or defined to be \f(CW1\fR, then embed watchers are supported. If +defined to be \f(CW0\fR, then they are not. +.IP "\s-1EV_STAT_ENABLE\s0" 4 +.IX Item "EV_STAT_ENABLE" +If undefined or defined to be \f(CW1\fR, then stat watchers are supported. If +defined to be \f(CW0\fR, then they are not. +.IP "\s-1EV_FORK_ENABLE\s0" 4 +.IX Item "EV_FORK_ENABLE" +If undefined or defined to be \f(CW1\fR, then fork watchers are supported. If +defined to be \f(CW0\fR, then they are not. +.IP "\s-1EV_ASYNC_ENABLE\s0" 4 +.IX Item "EV_ASYNC_ENABLE" +If undefined or defined to be \f(CW1\fR, then async watchers are supported. If +defined to be \f(CW0\fR, then they are not. +.IP "\s-1EV_MINIMAL\s0" 4 +.IX Item "EV_MINIMAL" +If you need to shave off some kilobytes of code at the expense of some +speed, define this symbol to \f(CW1\fR. Currently this is used to override some +inlining decisions, saves roughly 30% codesize of amd64. It also selects a +much smaller 2\-heap for timer management over the default 4\-heap. +.IP "\s-1EV_PID_HASHSIZE\s0" 4 +.IX Item "EV_PID_HASHSIZE" +\&\f(CW\*(C`ev_child\*(C'\fR watchers use a small hash table to distribute workload by +pid. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), usually more +than enough. If you need to manage thousands of children you might want to +increase this value (\fImust\fR be a power of two). +.IP "\s-1EV_INOTIFY_HASHSIZE\s0" 4 +.IX Item "EV_INOTIFY_HASHSIZE" +\&\f(CW\*(C`ev_stat\*(C'\fR watchers use a small hash table to distribute workload by +inotify watch id. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), +usually more than enough. If you need to manage thousands of \f(CW\*(C`ev_stat\*(C'\fR +watchers you might want to increase this value (\fImust\fR be a power of +two). +.IP "\s-1EV_USE_4HEAP\s0" 4 +.IX Item "EV_USE_4HEAP" +Heaps are not very cache-efficient. To improve the cache-efficiency of the +timer and periodics heap, libev uses a 4\-heap when this symbol is defined +to \f(CW1\fR. The 4\-heap uses more complicated (longer) code but has a +noticable after performance with many (thousands) of watchers. +.Sp +The default is \f(CW1\fR unless \f(CW\*(C`EV_MINIMAL\*(C'\fR is set in which case it is \f(CW0\fR +(disabled). +.IP "\s-1EV_HEAP_CACHE_AT\s0" 4 +.IX Item "EV_HEAP_CACHE_AT" +Heaps are not very cache-efficient. To improve the cache-efficiency of the +timer and periodics heap, libev can cache the timestamp (\fIat\fR) within +the heap structure (selected by defining \f(CW\*(C`EV_HEAP_CACHE_AT\*(C'\fR to \f(CW1\fR), +which uses 8\-12 bytes more per watcher and a few hundred bytes more code, +but avoids random read accesses on heap changes. This noticably improves +performance noticably with with many (hundreds) of watchers. +.Sp +The default is \f(CW1\fR unless \f(CW\*(C`EV_MINIMAL\*(C'\fR is set in which case it is \f(CW0\fR +(disabled). +.IP "\s-1EV_COMMON\s0" 4 +.IX Item "EV_COMMON" +By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining +this macro to a something else you can include more and other types of +members. You have to define it each time you include one of the files, +though, and it must be identical each time. +.Sp +For example, the perl \s-1EV\s0 module uses something like this: +.Sp +.Vb 3 +\& #define EV_COMMON \e +\& SV *self; /* contains this struct */ \e +\& SV *cb_sv, *fh /* note no trailing ";" */ +.Ve +.IP "\s-1EV_CB_DECLARE\s0 (type)" 4 +.IX Item "EV_CB_DECLARE (type)" +.PD 0 +.IP "\s-1EV_CB_INVOKE\s0 (watcher, revents)" 4 +.IX Item "EV_CB_INVOKE (watcher, revents)" +.IP "ev_set_cb (ev, cb)" 4 +.IX Item "ev_set_cb (ev, cb)" +.PD +Can be used to change the callback member declaration in each watcher, +and the way callbacks are invoked and set. Must expand to a struct member +definition and a statement, respectively. See the \fIev.h\fR header file for +their default definitions. One possible use for overriding these is to +avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use +method calls instead of plain function calls in \*(C+. +.Sh "\s-1EXPORTED\s0 \s-1API\s0 \s-1SYMBOLS\s0" +.IX Subsection "EXPORTED API SYMBOLS" +If you need to re-export the \s-1API\s0 (e.g. via a dll) and you need a list of +exported symbols, you can use the provided \fISymbol.*\fR files which list +all public symbols, one per line: +.PP +.Vb 2 +\& Symbols.ev for libev proper +\& Symbols.event for the libevent emulation +.Ve +.PP +This can also be used to rename all public symbols to avoid clashes with +multiple versions of libev linked together (which is obviously bad in +itself, but sometimes it is inconvinient to avoid this). +.PP +A sed command like this will create wrapper \f(CW\*(C`#define\*(C'\fR's that you need to +include before including \fIev.h\fR: +.PP +.Vb 1 +\& wrap.h +.Ve +.PP +This would create a file \fIwrap.h\fR which essentially looks like this: +.PP +.Vb 4 +\& #define ev_backend myprefix_ev_backend +\& #define ev_check_start myprefix_ev_check_start +\& #define ev_check_stop myprefix_ev_check_stop +\& ... +.Ve +.Sh "\s-1EXAMPLES\s0" +.IX Subsection "EXAMPLES" +For a real-world example of a program the includes libev +verbatim, you can have a look at the \s-1EV\s0 perl module +(). It has the libev files in +the \fIlibev/\fR subdirectory and includes them in the \fI\s-1EV/EVAPI\s0.h\fR (public +interface) and \fI\s-1EV\s0.xs\fR (implementation) files. Only the \fI\s-1EV\s0.xs\fR file +will be compiled. It is pretty complex because it provides its own header +file. +.PP +The usage in rxvt-unicode is simpler. It has a \fIev_cpp.h\fR header file +that everybody includes and which overrides some configure choices: +.PP +.Vb 9 +\& #define EV_MINIMAL 1 +\& #define EV_USE_POLL 0 +\& #define EV_MULTIPLICITY 0 +\& #define EV_PERIODIC_ENABLE 0 +\& #define EV_STAT_ENABLE 0 +\& #define EV_FORK_ENABLE 0 +\& #define EV_CONFIG_H +\& #define EV_MINPRI 0 +\& #define EV_MAXPRI 0 +\& +\& #include "ev++.h" +.Ve +.PP +And a \fIev_cpp.C\fR implementation file that contains libev proper and is compiled: +.PP +.Vb 2 +\& #include "ev_cpp.h" +\& #include "ev.c" +.Ve +.SH "THREADS AND COROUTINES" +.IX Header "THREADS AND COROUTINES" +.Sh "\s-1THREADS\s0" +.IX Subsection "THREADS" +Libev itself is completely threadsafe, but it uses no locking. This +means that you can use as many loops as you want in parallel, as long as +only one thread ever calls into one libev function with the same loop +parameter. +.PP +Or put differently: calls with different loop parameters can be done in +parallel from multiple threads, calls with the same loop parameter must be +done serially (but can be done from different threads, as long as only one +thread ever is inside a call at any point in time, e.g. by using a mutex +per loop). +.PP +If you want to know which design is best for your problem, then I cannot +help you but by giving some generic advice: +.IP "\(bu" 4 +most applications have a main thread: use the default libev loop +in that thread, or create a seperate thread running only the default loop. +.Sp +This helps integrating other libraries or software modules that use libev +themselves and don't care/know about threading. +.IP "\(bu" 4 +one loop per thread is usually a good model. +.Sp +Doing this is almost never wrong, sometimes a better-performance model +exists, but it is always a good start. +.IP "\(bu" 4 +other models exist, such as the leader/follower pattern, where one +loop is handed through multiple threads in a kind of round-robbin fashion. +.Sp +Chosing a model is hard \- look around, learn, know that usually you cna do +better than you currently do :\-) +.IP "\(bu" 4 +often you need to talk to some other thread which blocks in the +event loop \- \f(CW\*(C`ev_async\*(C'\fR watchers can be used to wake them up from other +threads safely (or from signal contexts...). +.Sh "\s-1COROUTINES\s0" +.IX Subsection "COROUTINES" +Libev is much more accomodating to coroutines (\*(L"cooperative threads\*(R"): +libev fully supports nesting calls to it's functions from different +coroutines (e.g. you can call \f(CW\*(C`ev_loop\*(C'\fR on the same loop from two +different coroutines and switch freely between both coroutines running the +loop, as long as you don't confuse yourself). The only exception is that +you must not do this from \f(CW\*(C`ev_periodic\*(C'\fR reschedule callbacks. +.PP +Care has been invested into making sure that libev does not keep local +state inside \f(CW\*(C`ev_loop\*(C'\fR, and other calls do not usually allow coroutine +switches. +.SH "COMPLEXITIES" +.IX Header "COMPLEXITIES" +In this section the complexities of (many of) the algorithms used inside +libev will be explained. For complexity discussions about backends see the +documentation for \f(CW\*(C`ev_default_init\*(C'\fR. +.PP +All of the following are about amortised time: If an array needs to be +extended, libev needs to realloc and move the whole array, but this +happens asymptotically never with higher number of elements, so O(1) might +mean it might do a lengthy realloc operation in rare cases, but on average +it is much faster and asymptotically approaches constant time. +.IP "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)" 4 +.IX Item "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)" +This means that, when you have a watcher that triggers in one hour and +there are 100 watchers that would trigger before that then inserting will +have to skip roughly seven (\f(CW\*(C`ld 100\*(C'\fR) of these watchers. +.IP "Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers)" 4 +.IX Item "Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers)" +That means that changing a timer costs less than removing/adding them +as only the relative motion in the event queue has to be paid for. +.IP "Starting io/check/prepare/idle/signal/child/fork/async watchers: O(1)" 4 +.IX Item "Starting io/check/prepare/idle/signal/child/fork/async watchers: O(1)" +These just add the watcher into an array or at the head of a list. +.IP "Stopping check/prepare/idle/fork/async watchers: O(1)" 4 +.IX Item "Stopping check/prepare/idle/fork/async watchers: O(1)" +.PD 0 +.IP "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % \s-1EV_PID_HASHSIZE\s0))" 4 +.IX Item "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))" +.PD +These watchers are stored in lists then need to be walked to find the +correct watcher to remove. The lists are usually short (you don't usually +have many watchers waiting for the same fd or signal). +.IP "Finding the next timer in each loop iteration: O(1)" 4 +.IX Item "Finding the next timer in each loop iteration: O(1)" +By virtue of using a binary or 4\-heap, the next timer is always found at a +fixed position in the storage array. +.IP "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 4 +.IX Item "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" +A change means an I/O watcher gets started or stopped, which requires +libev to recalculate its status (and possibly tell the kernel, depending +on backend and wether \f(CW\*(C`ev_io_set\*(C'\fR was used). +.IP "Activating one watcher (putting it into the pending state): O(1)" 4 +.IX Item "Activating one watcher (putting it into the pending state): O(1)" +.PD 0 +.IP "Priority handling: O(number_of_priorities)" 4 +.IX Item "Priority handling: O(number_of_priorities)" +.PD +Priorities are implemented by allocating some space for each +priority. When doing priority-based operations, libev usually has to +linearly search all the priorities, but starting/stopping and activating +watchers becomes O(1) w.r.t. priority handling. +.IP "Sending an ev_async: O(1)" 4 +.IX Item "Sending an ev_async: O(1)" +.PD 0 +.IP "Processing ev_async_send: O(number_of_async_watchers)" 4 +.IX Item "Processing ev_async_send: O(number_of_async_watchers)" +.IP "Processing signals: O(max_signal_number)" 4 +.IX Item "Processing signals: O(max_signal_number)" +.PD +Sending involves a syscall \fIiff\fR there were no other \f(CW\*(C`ev_async_send\*(C'\fR +calls in the current loop iteration. Checking for async and signal events +involves iterating over all running async watchers or all signal numbers. +.SH "Win32 platform limitations and workarounds" +.IX Header "Win32 platform limitations and workarounds" +Win32 doesn't support any of the standards (e.g. \s-1POSIX\s0) that libev +requires, and its I/O model is fundamentally incompatible with the \s-1POSIX\s0 +model. Libev still offers limited functionality on this platform in +the form of the \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR backend, and only supports socket +descriptors. This only applies when using Win32 natively, not when using +e.g. cygwin. +.PP +Lifting these limitations would basically require the full +re-implementation of the I/O system. If you are into these kinds of +things, then note that glib does exactly that for you in a very portable +way (note also that glib is the slowest event library known to man). +.PP +There is no supported compilation method available on windows except +embedding it into other applications. +.PP +Due to the many, low, and arbitrary limits on the win32 platform and +the abysmal performance of winsockets, using a large number of sockets +is not recommended (and not reasonable). If your program needs to use +more than a hundred or so sockets, then likely it needs to use a totally +different implementation for windows, as libev offers the \s-1POSIX\s0 readyness +notification model, which cannot be implemented efficiently on windows +(microsoft monopoly games). +.IP "The winsocket select function" 4 +.IX Item "The winsocket select function" +The winsocket \f(CW\*(C`select\*(C'\fR function doesn't follow \s-1POSIX\s0 in that it requires +socket \fIhandles\fR and not socket \fIfile descriptors\fR. This makes select +very inefficient, and also requires a mapping from file descriptors +to socket handles. See the discussion of the \f(CW\*(C`EV_SELECT_USE_FD_SET\*(C'\fR, +\&\f(CW\*(C`EV_SELECT_IS_WINSOCKET\*(C'\fR and \f(CW\*(C`EV_FD_TO_WIN32_HANDLE\*(C'\fR preprocessor +symbols for more info. +.Sp +The configuration for a \*(L"naked\*(R" win32 using the microsoft runtime +libraries and raw winsocket select is: +.Sp +.Vb 2 +\& #define EV_USE_SELECT 1 +\& #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */ +.Ve +.Sp +Note that winsockets handling of fd sets is O(n), so you can easily get a +complexity in the O(nA\*^X) range when using win32. +.IP "Limited number of file descriptors" 4 +.IX Item "Limited number of file descriptors" +Windows has numerous arbitrary (and low) limits on things. +.Sp +Early versions of winsocket's select only supported waiting for a maximum +of \f(CW64\fR handles (probably owning to the fact that all windows kernels +can only wait for \f(CW64\fR things at the same time internally; microsoft +recommends spawning a chain of threads and wait for 63 handles and the +previous thread in each. Great). +.Sp +Newer versions support more handles, but you need to define \f(CW\*(C`FD_SETSIZE\*(C'\fR +to some high number (e.g. \f(CW2048\fR) before compiling the winsocket select +call (which might be in libev or elsewhere, for example, perl does its own +select emulation on windows). +.Sp +Another limit is the number of file descriptors in the microsoft runtime +libraries, which by default is \f(CW64\fR (there must be a hidden \fI64\fR fetish +or something like this inside microsoft). You can increase this by calling +\&\f(CW\*(C`_setmaxstdio\*(C'\fR, which can increase this limit to \f(CW2048\fR (another +arbitrary limit), but is broken in many versions of the microsoft runtime +libraries. +.Sp +This might get you to about \f(CW512\fR or \f(CW2048\fR sockets (depending on +windows version and/or the phase of the moon). To get more, you need to +wrap all I/O functions and provide your own fd management, but the cost of +calling select (O(nA\*^X)) will likely make this unworkable. +.SH "PORTABILITY REQUIREMENTS" +.IX Header "PORTABILITY REQUIREMENTS" +In addition to a working ISO-C implementation, libev relies on a few +additional extensions: +.ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4 +.el .IP "\f(CWsig_atomic_t volatile\fR must be thread-atomic as well" 4 +.IX Item "sig_atomic_t volatile must be thread-atomic as well" +The type \f(CW\*(C`sig_atomic_t volatile\*(C'\fR (or whatever is defined as +\&\f(CW\*(C`EV_ATOMIC_T\*(C'\fR) must be atomic w.r.t. accesses from different +threads. This is not part of the specification for \f(CW\*(C`sig_atomic_t\*(C'\fR, but is +believed to be sufficiently portable. +.ie n .IP """sigprocmask"" must work in a threaded environment" 4 +.el .IP "\f(CWsigprocmask\fR must work in a threaded environment" 4 +.IX Item "sigprocmask must work in a threaded environment" +Libev uses \f(CW\*(C`sigprocmask\*(C'\fR to temporarily block signals. This is not +allowed in a threaded program (\f(CW\*(C`pthread_sigmask\*(C'\fR has to be used). Typical +pthread implementations will either allow \f(CW\*(C`sigprocmask\*(C'\fR in the \*(L"main +thread\*(R" or will block signals process-wide, both behaviours would +be compatible with libev. Interaction between \f(CW\*(C`sigprocmask\*(C'\fR and +\&\f(CW\*(C`pthread_sigmask\*(C'\fR could complicate things, however. +.Sp +The most portable way to handle signals is to block signals in all threads +except the initial one, and run the default loop in the initial thread as +well. +.ie n .IP """long"" must be large enough for common memory allocation sizes" 4 +.el .IP "\f(CWlong\fR must be large enough for common memory allocation sizes" 4 +.IX Item "long must be large enough for common memory allocation sizes" +To improve portability and simplify using libev, libev uses \f(CW\*(C`long\*(C'\fR +internally instead of \f(CW\*(C`size_t\*(C'\fR when allocating its data structures. On +non-POSIX systems (Microsoft...) this might be unexpectedly low, but +is still at least 31 bits everywhere, which is enough for hundreds of +millions of watchers. +.ie n .IP """double"" must hold a time value in seconds with enough accuracy" 4 +.el .IP "\f(CWdouble\fR must hold a time value in seconds with enough accuracy" 4 +.IX Item "double must hold a time value in seconds with enough accuracy" +The type \f(CW\*(C`double\*(C'\fR is used to represent timestamps. It is required to +have at least 51 bits of mantissa (and 9 bits of exponent), which is good +enough for at least into the year 4000. This requirement is fulfilled by +implementations implementing \s-1IEEE\s0 754 (basically all existing ones). +.PP +If you know of other additional requirements drop me a note. +.SH "AUTHOR" +.IX Header "AUTHOR" +Marc Lehmann . +.SH "POD ERRORS" +.IX Header "POD ERRORS" +Hey! \fBThe above document had some coding errors, which are explained below:\fR +.IP "Around line 3052:" 4 +.IX Item "Around line 3052:" +You forgot a '=back' before '=head2' diff --git a/src/rt/libuv/src/eio/eio.c b/src/rt/libuv/src/eio/eio.c new file mode 100644 index 00000000000..7f48add4019 --- /dev/null +++ b/src/rt/libuv/src/eio/eio.c @@ -0,0 +1,2133 @@ +/* + * libeio implementation + * + * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License ("GPL") version 2 or any later version, + * in which case the provisions of the GPL are applicable instead of + * the above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the BSD license, indicate your decision + * by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file under + * either the BSD or the GPL. + */ + +#include "eio.h" + +#ifdef EIO_STACKSIZE +# define XTHREAD_STACKSIZE EIO_STACKSIZE +#endif + +// For statically-linked pthreads-w32, use: +// #ifdef _WIN32 +// # define PTW32_STATIC_LIB 1 +// #endif +#include "xthread.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef _WIN32 +#include +#endif + +#ifndef EIO_FINISH +# define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 +#endif + +#ifndef EIO_DESTROY +# define EIO_DESTROY(req) do { if ((req)->destroy) (req)->destroy (req); } while (0) +#endif + +#ifndef EIO_FEED +# define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0) +#endif + +#ifdef _WIN32 + +# include +# include +# include +# include +# include +# include +# include + +# define ENOTSOCK WSAENOTSOCK +# define EOPNOTSUPP WSAEOPNOTSUPP +# define ECANCELED 140 + +# ifndef EIO_STRUCT_DIRENT +# define EIO_STRUCT_DIRENT struct dirent +# endif + +#else + +# ifdef EIO_CONFIG_H +# include EIO_CONFIG_H +# else +# include "config.h" +# endif + +# include +# include +# include +# include +# include +# include + +#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES +# include +#endif + +/* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ +# if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ +# define _DIRENT_HAVE_D_TYPE /* sigh */ +# define D_INO(de) (de)->d_fileno +# define D_NAMLEN(de) (de)->d_namlen +# elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 +# define D_INO(de) (de)->d_ino +# endif + +#ifdef _D_EXACT_NAMLEN +# undef D_NAMLEN +# define D_NAMLEN(de) _D_EXACT_NAMLEN (de) +#endif + +# ifdef _DIRENT_HAVE_D_TYPE +# define D_TYPE(de) (de)->d_type +# endif + +# ifndef EIO_STRUCT_DIRENT +# define EIO_STRUCT_DIRENT struct dirent +# endif + +#endif + +#if HAVE_SENDFILE +# if __linux +# include +# elif __FreeBSD__ || defined __APPLE__ +# include +# include +# elif __hpux +# include +# elif __solaris +# include +# else +# error sendfile support requested but not available +# endif +#endif + +#ifndef D_TYPE +# define D_TYPE(de) 0 +#endif +#ifndef D_INO +# define D_INO(de) 0 +#endif +#ifndef D_NAMLEN +# define D_NAMLEN(de) strlen ((de)->d_name) +#endif + +/* number of seconds after which an idle threads exit */ +#define IDLE_TIMEOUT 10 + +/* used for struct dirent, AIX doesn't provide it */ +#ifndef NAME_MAX +# define NAME_MAX 4096 +#endif + +/* used for readlink etc. */ +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif + +/* buffer size for various temporary buffers */ +#define EIO_BUFSIZE 65536 + +#define dBUF \ + char *eio_buf; \ + ETP_WORKER_LOCK (self); \ + self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ + ETP_WORKER_UNLOCK (self); \ + errno = ENOMEM; \ + if (!eio_buf) \ + return -1; + +#define EIO_TICKS ((1000000 + 1023) >> 10) + +/*****************************************************************************/ + +#if __GNUC__ >= 3 +# define expect(expr,value) __builtin_expect ((expr),(value)) +#else +# define expect(expr,value) (expr) +#endif + +#define expect_false(expr) expect ((expr) != 0, 0) +#define expect_true(expr) expect ((expr) != 0, 1) + +/*****************************************************************************/ + +#define ETP_PRI_MIN EIO_PRI_MIN +#define ETP_PRI_MAX EIO_PRI_MAX + +struct etp_worker; + +#define ETP_REQ eio_req +#define ETP_DESTROY(req) eio_destroy (req) +static int eio_finish (eio_req *req); +#define ETP_FINISH(req) eio_finish (req) +static void eio_execute (struct etp_worker *self, eio_req *req); +#define ETP_EXECUTE(wrk,req) eio_execute (wrk,req) + +#define ETP_WORKER_CLEAR(req) \ + if (wrk->dbuf) \ + { \ + free (wrk->dbuf); \ + wrk->dbuf = 0; \ + } \ + \ + if (wrk->dirp) \ + { \ + closedir (wrk->dirp); \ + wrk->dirp = 0; \ + } + +#define ETP_WORKER_COMMON \ + void *dbuf; \ + DIR *dirp; + +/*****************************************************************************/ + +#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) + +/* calculate time difference in ~1/EIO_TICKS of a second */ +static int tvdiff (struct timeval *tv1, struct timeval *tv2) +{ + return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS + + ((tv2->tv_usec - tv1->tv_usec) >> 10); +} + +static unsigned int started, idle, wanted = 4; + +static void (*want_poll_cb) (void); +static void (*done_poll_cb) (void); + +static unsigned int max_poll_time; /* reslock */ +static unsigned int max_poll_reqs; /* reslock */ + +static volatile unsigned int nreqs; /* reqlock */ +static volatile unsigned int nready; /* reqlock */ +static volatile unsigned int npending; /* reqlock */ +static volatile unsigned int max_idle = 4; + +static xmutex_t wrklock = X_MUTEX_INIT; +static xmutex_t reslock = X_MUTEX_INIT; +static xmutex_t reqlock = X_MUTEX_INIT; +static xcond_t reqwait = X_COND_INIT; + +#if defined (__APPLE__) +static xmutex_t apple_bug_writelock = X_MUTEX_INIT; +#endif + +#if !HAVE_PREADWRITE +/* + * make our pread/pwrite emulation safe against themselves, but not against + * normal read/write by using a mutex. slows down execution a lot, + * but that's your problem, not mine. + */ +static xmutex_t preadwritelock = X_MUTEX_INIT; +#endif + +typedef struct etp_worker +{ + /* locked by wrklock */ + struct etp_worker *prev, *next; + + xthread_t tid; + + /* locked by reslock, reqlock or wrklock */ + ETP_REQ *req; /* currently processed request */ + + ETP_WORKER_COMMON +} etp_worker; + +static etp_worker wrk_first = { &wrk_first, &wrk_first, 0 }; /* NOT etp */ + +#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) +#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) + +/* worker threads management */ + +static void etp_worker_clear (etp_worker *wrk) +{ + ETP_WORKER_CLEAR (wrk); +} + +static void etp_worker_free (etp_worker *wrk) +{ + wrk->next->prev = wrk->prev; + wrk->prev->next = wrk->next; + + free (wrk); +} + +static unsigned int etp_nreqs (void) +{ + int retval; + if (WORDACCESS_UNSAFE) X_LOCK (reqlock); + retval = nreqs; + if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); + return retval; +} + +static unsigned int etp_nready (void) +{ + unsigned int retval; + + if (WORDACCESS_UNSAFE) X_LOCK (reqlock); + retval = nready; + if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); + + return retval; +} + +static unsigned int etp_npending (void) +{ + unsigned int retval; + + if (WORDACCESS_UNSAFE) X_LOCK (reqlock); + retval = npending; + if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); + + return retval; +} + +static unsigned int etp_nthreads (void) +{ + unsigned int retval; + + if (WORDACCESS_UNSAFE) X_LOCK (reqlock); + retval = started; + if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); + + return retval; +} + +/* + * a somewhat faster data structure might be nice, but + * with 8 priorities this actually needs <20 insns + * per shift, the most expensive operation. + */ +typedef struct { + ETP_REQ *qs[ETP_NUM_PRI], *qe[ETP_NUM_PRI]; /* qstart, qend */ + int size; +} etp_reqq; + +static etp_reqq req_queue; +static etp_reqq res_queue; + +static int reqq_push (etp_reqq *q, ETP_REQ *req) +{ + int pri = req->pri; + req->next = 0; + + if (q->qe[pri]) + { + q->qe[pri]->next = req; + q->qe[pri] = req; + } + else + q->qe[pri] = q->qs[pri] = req; + + return q->size++; +} + +static ETP_REQ *reqq_shift (etp_reqq *q) +{ + int pri; + + if (!q->size) + return 0; + + --q->size; + + for (pri = ETP_NUM_PRI; pri--; ) + { + eio_req *req = q->qs[pri]; + + if (req) + { + if (!(q->qs[pri] = (eio_req *)req->next)) + q->qe[pri] = 0; + + return req; + } + } + + abort (); +} + +static void etp_atfork_prepare (void) +{ + X_LOCK (wrklock); + X_LOCK (reqlock); + X_LOCK (reslock); +#if !HAVE_PREADWRITE + X_LOCK (preadwritelock); +#endif +} + +static void etp_atfork_parent (void) +{ +#if !HAVE_PREADWRITE + X_UNLOCK (preadwritelock); +#endif + X_UNLOCK (reslock); + X_UNLOCK (reqlock); + X_UNLOCK (wrklock); +} + +static void etp_atfork_child (void) +{ + ETP_REQ *prv; + + while ((prv = reqq_shift (&req_queue))) + ETP_DESTROY (prv); + + while ((prv = reqq_shift (&res_queue))) + ETP_DESTROY (prv); + + while (wrk_first.next != &wrk_first) + { + etp_worker *wrk = wrk_first.next; + + if (wrk->req) + ETP_DESTROY (wrk->req); + + etp_worker_clear (wrk); + etp_worker_free (wrk); + } + + started = 0; + idle = 0; + nreqs = 0; + nready = 0; + npending = 0; + + etp_atfork_parent (); +} + +static void +etp_once_init (void) +{ + X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child); +} + +static int +etp_init (void (*want_poll)(void), void (*done_poll)(void)) +{ + static pthread_once_t doinit = PTHREAD_ONCE_INIT; + + pthread_once (&doinit, etp_once_init); + + want_poll_cb = want_poll; + done_poll_cb = done_poll; + + return 0; +} + +X_THREAD_PROC (etp_proc); + +static void etp_start_thread (void) +{ + etp_worker *wrk = calloc (1, sizeof (etp_worker)); + + /*TODO*/ + assert (("unable to allocate worker thread data", wrk)); + + X_LOCK (wrklock); + + if (thread_create (&wrk->tid, etp_proc, (void *)wrk)) + { + wrk->prev = &wrk_first; + wrk->next = wrk_first.next; + wrk_first.next->prev = wrk; + wrk_first.next = wrk; + ++started; + } + else + free (wrk); + + X_UNLOCK (wrklock); +} + +static void etp_maybe_start_thread (void) +{ + if (expect_true (etp_nthreads () >= wanted)) + return; + + /* todo: maybe use idle here, but might be less exact */ + if (expect_true (0 <= (int)etp_nthreads () + (int)etp_npending () - (int)etp_nreqs ())) + return; + + etp_start_thread (); +} + +static void etp_end_thread (void) +{ + eio_req *req = calloc (1, sizeof (eio_req)); + + req->type = -1; + req->pri = ETP_PRI_MAX - ETP_PRI_MIN; + + X_LOCK (reqlock); + reqq_push (&req_queue, req); + X_COND_SIGNAL (reqwait); + X_UNLOCK (reqlock); + + X_LOCK (wrklock); + --started; + X_UNLOCK (wrklock); +} + +static int etp_poll (void) +{ + unsigned int maxreqs; + unsigned int maxtime; + struct timeval tv_start, tv_now; + + X_LOCK (reslock); + maxreqs = max_poll_reqs; + maxtime = max_poll_time; + X_UNLOCK (reslock); + + if (maxtime) + gettimeofday (&tv_start, 0); + + for (;;) + { + ETP_REQ *req; + + etp_maybe_start_thread (); + + X_LOCK (reslock); + req = reqq_shift (&res_queue); + + if (req) + { + --npending; + + if (!res_queue.size && done_poll_cb) + done_poll_cb (); + } + + X_UNLOCK (reslock); + + if (!req) + return 0; + + X_LOCK (reqlock); + --nreqs; + X_UNLOCK (reqlock); + + if (expect_false (req->type == EIO_GROUP && req->size)) + { + req->int1 = 1; /* mark request as delayed */ + continue; + } + else + { + int res = ETP_FINISH (req); + if (expect_false (res)) + return res; + } + + if (expect_false (maxreqs && !--maxreqs)) + break; + + if (maxtime) + { + gettimeofday (&tv_now, 0); + + if (tvdiff (&tv_start, &tv_now) >= maxtime) + break; + } + } + + errno = EAGAIN; + return -1; +} + +static void etp_cancel (ETP_REQ *req) +{ + X_LOCK (wrklock); + req->flags |= EIO_FLAG_CANCELLED; + X_UNLOCK (wrklock); + + eio_grp_cancel (req); +} + +static void etp_submit (ETP_REQ *req) +{ + req->pri -= ETP_PRI_MIN; + + if (expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN; + if (expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN; + + if (expect_false (req->type == EIO_GROUP)) + { + /* I hope this is worth it :/ */ + X_LOCK (reqlock); + ++nreqs; + X_UNLOCK (reqlock); + + X_LOCK (reslock); + + ++npending; + + if (!reqq_push (&res_queue, req) && want_poll_cb) + want_poll_cb (); + + X_UNLOCK (reslock); + } + else + { + X_LOCK (reqlock); + ++nreqs; + ++nready; + reqq_push (&req_queue, req); + X_COND_SIGNAL (reqwait); + X_UNLOCK (reqlock); + + etp_maybe_start_thread (); + } +} + +static void etp_set_max_poll_time (double nseconds) +{ + if (WORDACCESS_UNSAFE) X_LOCK (reslock); + max_poll_time = nseconds * EIO_TICKS; + if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); +} + +static void etp_set_max_poll_reqs (unsigned int maxreqs) +{ + if (WORDACCESS_UNSAFE) X_LOCK (reslock); + max_poll_reqs = maxreqs; + if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); +} + +static void etp_set_max_idle (unsigned int nthreads) +{ + if (WORDACCESS_UNSAFE) X_LOCK (reqlock); + max_idle = nthreads <= 0 ? 1 : nthreads; + if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); +} + +static void etp_set_min_parallel (unsigned int nthreads) +{ + if (wanted < nthreads) + wanted = nthreads; +} + +static void etp_set_max_parallel (unsigned int nthreads) +{ + if (wanted > nthreads) + wanted = nthreads; + + while (started > wanted) + etp_end_thread (); +} + +/*****************************************************************************/ + +static void grp_try_feed (eio_req *grp) +{ + while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) + { + grp->flags &= ~EIO_FLAG_GROUPADD; + + EIO_FEED (grp); + + /* stop if no progress has been made */ + if (!(grp->flags & EIO_FLAG_GROUPADD)) + { + grp->feed = 0; + break; + } + } +} + +static int grp_dec (eio_req *grp) +{ + --grp->size; + + /* call feeder, if applicable */ + grp_try_feed (grp); + + /* finish, if done */ + if (!grp->size && grp->int1) + return eio_finish (grp); + else + return 0; +} + +void eio_destroy (eio_req *req) +{ + if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1); + if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2); + + EIO_DESTROY (req); +} + +static int eio_finish (eio_req *req) +{ + int res = EIO_FINISH (req); + + if (req->grp) + { + int res2; + eio_req *grp = req->grp; + + /* unlink request */ + if (req->grp_next) req->grp_next->grp_prev = req->grp_prev; + if (req->grp_prev) req->grp_prev->grp_next = req->grp_next; + + if (grp->grp_first == req) + grp->grp_first = req->grp_next; + + res2 = grp_dec (grp); + + if (!res && res2) + res = res2; + } + + eio_destroy (req); + + return res; +} + +void eio_grp_cancel (eio_req *grp) +{ + for (grp = grp->grp_first; grp; grp = grp->grp_next) + eio_cancel (grp); +} + +void eio_cancel (eio_req *req) +{ + etp_cancel (req); +} + +void eio_submit (eio_req *req) +{ + etp_submit (req); +} + +unsigned int eio_nreqs (void) +{ + return etp_nreqs (); +} + +unsigned int eio_nready (void) +{ + return etp_nready (); +} + +unsigned int eio_npending (void) +{ + return etp_npending (); +} + +unsigned int eio_nthreads (void) +{ + return etp_nthreads (); +} + +void eio_set_max_poll_time (double nseconds) +{ + etp_set_max_poll_time (nseconds); +} + +void eio_set_max_poll_reqs (unsigned int maxreqs) +{ + etp_set_max_poll_reqs (maxreqs); +} + +void eio_set_max_idle (unsigned int nthreads) +{ + etp_set_max_idle (nthreads); +} + +void eio_set_min_parallel (unsigned int nthreads) +{ + etp_set_min_parallel (nthreads); +} + +void eio_set_max_parallel (unsigned int nthreads) +{ + etp_set_max_parallel (nthreads); +} + +int eio_poll (void) +{ + return etp_poll (); +} + +/*****************************************************************************/ +/* work around various missing functions */ + +#if !HAVE_PREADWRITE +# undef pread +# undef pwrite +# define pread eio__pread +# define pwrite eio__pwrite + +ssize_t +eio__pread (int fd, void *buf, size_t count, off_t offset) +{ + ssize_t res; + off_t ooffset; + + X_LOCK (preadwritelock); + ooffset = lseek (fd, 0, SEEK_CUR); + lseek (fd, offset, SEEK_SET); + res = read (fd, buf, count); + lseek (fd, ooffset, SEEK_SET); + X_UNLOCK (preadwritelock); + + return res; +} + +ssize_t +eio__pwrite (int fd, void *buf, size_t count, off_t offset) +{ + ssize_t res; + off_t ooffset; + + X_LOCK (preadwritelock); + ooffset = lseek (fd, 0, SEEK_CUR); + lseek (fd, offset, SEEK_SET); + res = write (fd, buf, count); + lseek (fd, ooffset, SEEK_SET); + X_UNLOCK (preadwritelock); + + return res; +} +#endif + +#ifndef HAVE_UTIMES + +# undef utimes +# define utimes(path,times) eio__utimes (path, times) + +static int +eio__utimes (const char *filename, const struct timeval times[2]) +{ + if (times) + { + struct utimbuf buf; + + buf.actime = times[0].tv_sec; + buf.modtime = times[1].tv_sec; + + return utime (filename, &buf); + } + else + return utime (filename, 0); +} + +#endif + +#ifndef HAVE_FUTIMES + +# undef futimes +# define futimes(fd,times) eio__futimes (fd, times) + +static int eio__futimes (int fd, const struct timeval tv[2]) +{ + errno = ENOSYS; + return -1; +} + +#endif + +#ifdef _WIN32 +# define fsync(fd) (FlushFileBuffers((HANDLE)_get_osfhandle(fd)) ? 0 : -1) +#endif + +#if !HAVE_FDATASYNC +# undef fdatasync +# define fdatasync(fd) fsync (fd) +#endif + +// Use unicode and big file aware stat on windows +#ifdef _WIN32 +# undef stat +# undef fstat +# define stat _stati64 +# define fstat _fstati64 +#endif + +/* sync_file_range always needs emulation */ +int +eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) +{ +#if HAVE_SYNC_FILE_RANGE + int res; + + if (EIO_SYNC_FILE_RANGE_WAIT_BEFORE != SYNC_FILE_RANGE_WAIT_BEFORE + || EIO_SYNC_FILE_RANGE_WRITE != SYNC_FILE_RANGE_WRITE + || EIO_SYNC_FILE_RANGE_WAIT_AFTER != SYNC_FILE_RANGE_WAIT_AFTER) + { + flags = 0 + | (flags & EIO_SYNC_FILE_RANGE_WAIT_BEFORE ? SYNC_FILE_RANGE_WAIT_BEFORE : 0) + | (flags & EIO_SYNC_FILE_RANGE_WRITE ? SYNC_FILE_RANGE_WRITE : 0) + | (flags & EIO_SYNC_FILE_RANGE_WAIT_AFTER ? SYNC_FILE_RANGE_WAIT_AFTER : 0); + } + + res = sync_file_range (fd, offset, nbytes, flags); + + if (!res || errno != ENOSYS) + return res; +#endif + + /* even though we could play tricks with the flags, it's better to always + * call fdatasync, as that matches the expectation of its users best */ + return fdatasync (fd); +} + +#if !HAVE_READAHEAD +# undef readahead +# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) + +static ssize_t +eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) +{ + size_t todo = count; + dBUF; + + while (todo > 0) + { + size_t len = todo < EIO_BUFSIZE ? todo : EIO_BUFSIZE; + + pread (fd, eio_buf, len, offset); + offset += len; + todo -= len; + } + + errno = 0; + return count; +} + +#endif + +/* sendfile always needs emulation */ +static ssize_t +eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) +{ + ssize_t res; + + if (!count) + return 0; + +#if HAVE_SENDFILE +# if __linux + res = sendfile (ofd, ifd, &offset, count); + +# elif __FreeBSD__ + /* + * Of course, the freebsd sendfile is a dire hack with no thoughts + * wasted on making it similar to other I/O functions. + */ + { + off_t sbytes; + res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); + + #if 0 /* according to the manpage, this is correct, but broken behaviour */ + /* freebsd' sendfile will return 0 on success */ + /* freebsd 8 documents it as only setting *sbytes on EINTR and EAGAIN, but */ + /* not on e.g. EIO or EPIPE - sounds broken */ + if ((res < 0 && (errno == EAGAIN || errno == EINTR) && sbytes) || res == 0) + res = sbytes; + #endif + + /* according to source inspection, this is correct, and useful behaviour */ + if (sbytes) + res = sbytes; + } + +# elif defined (__APPLE__) + + { + off_t sbytes = count; + res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); + + /* according to the manpage, sbytes is always valid */ + if (sbytes) + res = sbytes; + } + +# elif __hpux + res = sendfile (ofd, ifd, offset, count, 0, 0); + +# elif __solaris + { + struct sendfilevec vec; + size_t sbytes; + + vec.sfv_fd = ifd; + vec.sfv_flag = 0; + vec.sfv_off = offset; + vec.sfv_len = count; + + res = sendfilev (ofd, &vec, 1, &sbytes); + + if (res < 0 && sbytes) + res = sbytes; + } + +# endif + +//#elif defined (_WIN32) +// +// /* does not work, just for documentation of what would need to be done */ +// { +// HANDLE h = TO_SOCKET (ifd); +// SetFilePointer (h, offset, 0, FILE_BEGIN); +// res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0); +// } + +#else + res = -1; + errno = ENOSYS; +#endif + + if (res < 0 + && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK + /* BSDs */ +#ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */ + || errno == ENOTSUP +#endif + || errno == EOPNOTSUPP /* BSDs */ +#if __solaris + || errno == EAFNOSUPPORT || errno == EPROTOTYPE +#endif + ) + ) + { + /* emulate sendfile. this is a major pain in the ass */ + dBUF; + + res = 0; + + while (count) + { + ssize_t cnt; + + cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset); + + if (cnt <= 0) + { + if (cnt && !res) res = -1; + break; + } + + cnt = write (ofd, eio_buf, cnt); + + if (cnt <= 0) + { + if (cnt && !res) res = -1; + break; + } + + offset += cnt; + res += cnt; + count -= cnt; + } + } + + return res; +} + +static signed char +eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) +{ + return a->score - b->score ? a->score - b->score /* works because our signed char is always 0..100 */ + : a->inode < b->inode ? -1 : a->inode > b->inode ? 1 : 0; +} + +#define EIO_DENT_CMP(i,op,j) eio_dent_cmp (&i, &j) op 0 + +#define EIO_SORT_CUTOFF 30 /* quite high, but performs well on many filesystems */ +#define EIO_SORT_FAST 60 /* when to only use insertion sort */ + +static void +eio_dent_radix_sort (eio_dirent *dents, int size, signed char score_bits, ino_t inode_bits) +{ + unsigned char bits [9 + sizeof (ino_t) * 8]; + unsigned char *bit = bits; + + assert (CHAR_BIT == 8); + assert (sizeof (eio_dirent) * 8 < 256); + assert (offsetof (eio_dirent, inode)); /* we use 0 as sentinel */ + assert (offsetof (eio_dirent, score)); /* we use 0 as sentinel */ + + if (size <= EIO_SORT_FAST) + return; + + /* first prepare an array of bits to test in our radix sort */ + /* try to take endianness into account, as well as differences in ino_t sizes */ + /* inode_bits must contain all inodes ORed together */ + /* which is used to skip bits that are 0 everywhere, which is very common */ + { + ino_t endianness; + int i, j; + + /* we store the byte offset of byte n into byte n of "endianness" */ + for (i = 0; i < sizeof (ino_t); ++i) + ((unsigned char *)&endianness)[i] = i; + + *bit++ = 0; + + for (i = 0; i < sizeof (ino_t); ++i) + { + /* shifting off the byte offsets out of "endianness" */ + int offs = (offsetof (eio_dirent, inode) + (endianness & 0xff)) * 8; + endianness >>= 8; + + for (j = 0; j < 8; ++j) + if (inode_bits & (((ino_t)1) << (i * 8 + j))) + *bit++ = offs + j; + } + + for (j = 0; j < 8; ++j) + if (score_bits & (1 << j)) + *bit++ = offsetof (eio_dirent, score) * 8 + j; + } + + /* now actually do the sorting (a variant of MSD radix sort) */ + { + eio_dirent *base_stk [9 + sizeof (ino_t) * 8], *base; + eio_dirent *end_stk [9 + sizeof (ino_t) * 8], *end; + unsigned char *bit_stk [9 + sizeof (ino_t) * 8]; + int stk_idx = 0; + + base_stk [stk_idx] = dents; + end_stk [stk_idx] = dents + size; + bit_stk [stk_idx] = bit - 1; + + do + { + base = base_stk [stk_idx]; + end = end_stk [stk_idx]; + bit = bit_stk [stk_idx]; + + for (;;) + { + unsigned char O = *bit >> 3; + unsigned char M = 1 << (*bit & 7); + + eio_dirent *a = base; + eio_dirent *b = end; + + if (b - a < EIO_SORT_CUTOFF) + break; + + /* now bit-partition the array on the bit */ + /* this ugly asymmetric loop seems to perform much better than typical */ + /* partition algos found in the literature */ + do + if (!(((unsigned char *)a)[O] & M)) + ++a; + else if (!(((unsigned char *)--b)[O] & M)) + { + eio_dirent tmp = *a; *a = *b; *b = tmp; + ++a; + } + while (b > a); + + /* next bit, or stop, if no bits left in this path */ + if (!*--bit) + break; + + base_stk [stk_idx] = a; + end_stk [stk_idx] = end; + bit_stk [stk_idx] = bit; + ++stk_idx; + + end = a; + } + } + while (stk_idx--); + } +} + +static void +eio_dent_insertion_sort (eio_dirent *dents, int size) +{ + /* first move the smallest element to the front, to act as a sentinel */ + { + int i; + eio_dirent *min = dents; + + /* the radix pre-pass ensures that the minimum element is in the first EIO_SORT_CUTOFF + 1 elements */ + for (i = size > EIO_SORT_FAST ? EIO_SORT_CUTOFF + 1 : size; --i; ) + if (EIO_DENT_CMP (dents [i], <, *min)) + min = &dents [i]; + + /* swap elements 0 and j (minimum) */ + { + eio_dirent tmp = *dents; *dents = *min; *min = tmp; + } + } + + /* then do standard insertion sort, assuming that all elements are >= dents [0] */ + { + eio_dirent *i, *j; + + for (i = dents + 1; i < dents + size; ++i) + { + eio_dirent value = *i; + + for (j = i - 1; EIO_DENT_CMP (*j, >, value); --j) + j [1] = j [0]; + + j [1] = value; + } + } +} + +static void +eio_dent_sort (eio_dirent *dents, int size, signed char score_bits, ino_t inode_bits) +{ + if (size <= 1) + return; /* our insertion sort relies on size > 0 */ + + /* first we use a radix sort, but only for dirs >= EIO_SORT_FAST */ + /* and stop sorting when the partitions are <= EIO_SORT_CUTOFF */ + eio_dent_radix_sort (dents, size, score_bits, inode_bits); + + /* use an insertion sort at the end, or for small arrays, */ + /* as insertion sort is more efficient for small partitions */ + eio_dent_insertion_sort (dents, size); +} + +/* read a full directory */ +static void +eio__scandir (eio_req *req, etp_worker *self) +{ + DIR *dirp; + EIO_STRUCT_DIRENT *entp; + char *name, *names; + int namesalloc = 4096; + int namesoffs = 0; + int flags = req->int1; + eio_dirent *dents = 0; + int dentalloc = 128; + int dentoffs = 0; + ino_t inode_bits = 0; + + req->result = -1; + + if (!(flags & EIO_READDIR_DENTS)) + flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); + + X_LOCK (wrklock); + /* the corresponding closedir is in ETP_WORKER_CLEAR */ + self->dirp = dirp = opendir (req->ptr1); + req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; + req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; + req->ptr2 = names = malloc (namesalloc); + X_UNLOCK (wrklock); + + if (dirp && names && (!flags || dents)) + for (;;) + { + errno = 0; + entp = readdir (dirp); + + if (!entp) + { + if (errno) + break; + + /* sort etc. */ + req->int1 = flags; + req->result = dentoffs; + + if (flags & EIO_READDIR_STAT_ORDER) + eio_dent_sort (dents, dentoffs, 0, inode_bits); /* sort by inode exclusively */ + else if (flags & EIO_READDIR_DIRS_FIRST) + if (flags & EIO_READDIR_FOUND_UNKNOWN) + eio_dent_sort (dents, dentoffs, 7, inode_bits); /* sort by score and inode */ + else + { + /* in this case, all is known, and we just put dirs first and sort them */ + eio_dirent *oth = dents + dentoffs; + eio_dirent *dir = dents; + + /* now partition dirs to the front, and non-dirs to the back */ + /* by walking from both sides and swapping if necessary */ + /* also clear score, so it doesn't influence sorting */ + while (oth > dir) + { + if (dir->type == EIO_DT_DIR) + ++dir; + else if ((--oth)->type == EIO_DT_DIR) + { + eio_dirent tmp = *dir; *dir = *oth; *oth = tmp; + + ++dir; + } + } + + /* now sort the dirs only */ + eio_dent_sort (dents, dir - dents, 0, inode_bits); + } + + break; + } + + /* now add the entry to our list(s) */ + name = entp->d_name; + + /* skip . and .. entries */ + if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) + { + int len = D_NAMLEN (entp) + 1; + + while (expect_false (namesoffs + len > namesalloc)) + { + namesalloc *= 2; + X_LOCK (wrklock); + req->ptr2 = names = realloc (names, namesalloc); + X_UNLOCK (wrklock); + + if (!names) + break; + } + + memcpy (names + namesoffs, name, len); + + if (dents) + { + struct eio_dirent *ent; + + if (expect_false (dentoffs == dentalloc)) + { + dentalloc *= 2; + X_LOCK (wrklock); + req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); + X_UNLOCK (wrklock); + + if (!dents) + break; + } + + ent = dents + dentoffs; + + ent->nameofs = namesoffs; /* rather dirtily we store the offset in the pointer */ + ent->namelen = len - 1; + ent->inode = D_INO (entp); + + inode_bits |= ent->inode; + + switch (D_TYPE (entp)) + { + default: + ent->type = EIO_DT_UNKNOWN; + flags |= EIO_READDIR_FOUND_UNKNOWN; + break; + + #ifdef DT_FIFO + case DT_FIFO: ent->type = EIO_DT_FIFO; break; + #endif + #ifdef DT_CHR + case DT_CHR: ent->type = EIO_DT_CHR; break; + #endif + #ifdef DT_MPC + case DT_MPC: ent->type = EIO_DT_MPC; break; + #endif + #ifdef DT_DIR + case DT_DIR: ent->type = EIO_DT_DIR; break; + #endif + #ifdef DT_NAM + case DT_NAM: ent->type = EIO_DT_NAM; break; + #endif + #ifdef DT_BLK + case DT_BLK: ent->type = EIO_DT_BLK; break; + #endif + #ifdef DT_MPB + case DT_MPB: ent->type = EIO_DT_MPB; break; + #endif + #ifdef DT_REG + case DT_REG: ent->type = EIO_DT_REG; break; + #endif + #ifdef DT_NWK + case DT_NWK: ent->type = EIO_DT_NWK; break; + #endif + #ifdef DT_CMP + case DT_CMP: ent->type = EIO_DT_CMP; break; + #endif + #ifdef DT_LNK + case DT_LNK: ent->type = EIO_DT_LNK; break; + #endif + #ifdef DT_SOCK + case DT_SOCK: ent->type = EIO_DT_SOCK; break; + #endif + #ifdef DT_DOOR + case DT_DOOR: ent->type = EIO_DT_DOOR; break; + #endif + #ifdef DT_WHT + case DT_WHT: ent->type = EIO_DT_WHT; break; + #endif + } + + ent->score = 7; + + if (flags & EIO_READDIR_DIRS_FIRST) + { + if (ent->type == EIO_DT_UNKNOWN) + { + if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ + ent->score = 1; + else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ + ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ + } + else if (ent->type == EIO_DT_DIR) + ent->score = 0; + } + } + + namesoffs += len; + ++dentoffs; + } + + if (EIO_CANCELLED (req)) + { + errno = ECANCELED; + break; + } + } +} + +#ifdef PAGESIZE +# define eio_pagesize() PAGESIZE + +#elif defined(_WIN32) + /* Windows */ + static intptr_t + eio_pagesize (void) + { + SYSTEM_INFO si; + GetSystemInfo(&si); + return si.dwPageSize; + } + +#else + /* POSIX */ + static intptr_t + eio_pagesize (void) + { + static intptr_t page; + + if (!page) + page = sysconf (_SC_PAGESIZE); + + return page; + } +#endif + +static void +eio_page_align (void **addr, size_t *length) +{ + intptr_t mask = eio_pagesize () - 1; + + /* round down addr */ + intptr_t adj = mask & (intptr_t)*addr; + + *addr = (void *)((intptr_t)*addr - adj); + *length += adj; + + /* round up length */ + *length = (*length + mask) & ~mask; +} + +#if !_POSIX_MEMLOCK +# define eio__mlockall(a) ((errno = ENOSYS), -1) +#else + +static int +eio__mlockall (int flags) +{ + #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 + extern int mallopt (int, int); + mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ + #endif + + if (EIO_MCL_CURRENT != MCL_CURRENT + || EIO_MCL_FUTURE != MCL_FUTURE) + { + flags = 0 + | (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0) + | (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0); + } + + return mlockall (flags); +} +#endif + +#if !_POSIX_MEMLOCK_RANGE +# define eio__mlock(a,b) ((errno = ENOSYS), -1) +#else + +static int +eio__mlock (void *addr, size_t length) +{ + eio_page_align (&addr, &length); + + return mlock (addr, length); +} + +#endif + +#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) +# define eio__msync(a,b,c) ((errno = ENOSYS), -1) +#else + +int +eio__msync (void *mem, size_t len, int flags) +{ + eio_page_align (&mem, &len); + + if (EIO_MS_ASYNC != MS_SYNC + || EIO_MS_INVALIDATE != MS_INVALIDATE + || EIO_MS_SYNC != MS_SYNC) + { + flags = 0 + | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0) + | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0) + | (flags & EIO_MS_SYNC ? MS_SYNC : 0); + } + + return msync (mem, len, flags); +} + +#endif + +int +eio__mtouch (void *mem, size_t len, int flags) +{ + eio_page_align (&mem, &len); + + { + intptr_t addr = (intptr_t)mem; + intptr_t end = addr + len; + intptr_t page = eio_pagesize (); + + if (addr < end) + if (flags & EIO_MT_MODIFY) /* modify */ + do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len); + else + do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len); + } + + return 0; +} + +/*****************************************************************************/ + +#define ALLOC(len) \ + if (!req->ptr2) \ + { \ + X_LOCK (wrklock); \ + req->flags |= EIO_FLAG_PTR2_FREE; \ + X_UNLOCK (wrklock); \ + req->ptr2 = malloc (len); \ + if (!req->ptr2) \ + { \ + errno = ENOMEM; \ + req->result = -1; \ + break; \ + } \ + } + +X_THREAD_PROC (etp_proc) +{ + ETP_REQ *req; + struct timespec ts; + etp_worker *self = (etp_worker *)thr_arg; + + /* try to distribute timeouts somewhat randomly */ + ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); + + for (;;) + { + X_LOCK (reqlock); + + for (;;) + { + self->req = req = reqq_shift (&req_queue); + + if (req) + break; + + ++idle; + + ts.tv_sec = time (0) + IDLE_TIMEOUT; + if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) + { + if (idle > max_idle) + { + --idle; + X_UNLOCK (reqlock); + X_LOCK (wrklock); + --started; + X_UNLOCK (wrklock); + goto quit; + } + + /* we are allowed to idle, so do so without any timeout */ + X_COND_WAIT (reqwait, reqlock); + } + + --idle; + } + + --nready; + + X_UNLOCK (reqlock); + + if (req->type < 0) + goto quit; + + if (!EIO_CANCELLED (req)) + ETP_EXECUTE (self, req); + + X_LOCK (reslock); + + ++npending; + + if (!reqq_push (&res_queue, req) && want_poll_cb) + want_poll_cb (); + + self->req = 0; + etp_worker_clear (self); + + X_UNLOCK (reslock); + } + +quit: + X_LOCK (wrklock); + etp_worker_free (self); + X_UNLOCK (wrklock); + + return 0; +} + +/*****************************************************************************/ + +int eio_init (void (*want_poll)(void), void (*done_poll)(void)) +{ + return etp_init (want_poll, done_poll); +} + +static void eio_api_destroy (eio_req *req) +{ + free (req); +} + +#define REQ(rtype) \ + eio_req *req; \ + \ + req = (eio_req *)calloc (1, sizeof *req); \ + if (!req) \ + return 0; \ + \ + req->type = rtype; \ + req->pri = pri; \ + req->finish = cb; \ + req->data = data; \ + req->destroy = eio_api_destroy; + +#define SEND eio_submit (req); return req + +#define PATH \ + req->flags |= EIO_FLAG_PTR1_FREE; \ + req->ptr1 = strdup (path); \ + if (!req->ptr1) \ + { \ + eio_api_destroy (req); \ + return 0; \ + } + +static void eio_execute (etp_worker *self, eio_req *req) +{ + switch (req->type) + { + case EIO_READ: ALLOC (req->size); + req->result = req->offs >= 0 + ? pread (req->int1, req->ptr2, req->size, req->offs) + : read (req->int1, req->ptr2, req->size); break; + case EIO_WRITE: +#if defined (__APPLE__) + pthread_mutex_lock (&apple_bug_writelock); +#endif + + req->result = req->offs >= 0 + ? pwrite (req->int1, req->ptr2, req->size, req->offs) + : write (req->int1, req->ptr2, req->size); + +#if defined (__APPLE__) + pthread_mutex_unlock (&apple_bug_writelock); +#endif + break; + + case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; + case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size, self); break; + + case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); + req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; +#ifndef _WIN32 + case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); + req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; +#endif + case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); + req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; + +#ifndef _WIN32 + case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = statvfs (req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; + case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = fstatvfs (req->int1, (EIO_STRUCT_STATVFS *)req->ptr2); break; + + case EIO_CHOWN: req->result = chown (req->ptr1, req->int2, req->int3); break; + case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; +#endif + case EIO_CHMOD: req->result = chmod (req->ptr1, (mode_t)req->int2); break; +#ifndef _WIN32 + case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; + case EIO_TRUNCATE: req->result = truncate (req->ptr1, req->offs); break; +#endif + case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; + + case EIO_OPEN: req->result = open (req->ptr1, req->int1, (mode_t)req->int2); break; + case EIO_CLOSE: req->result = close (req->int1); break; + case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; + case EIO_UNLINK: req->result = unlink (req->ptr1); break; + case EIO_RMDIR: req->result = rmdir (req->ptr1); break; +#ifdef _WIN32 + case EIO_MKDIR: req->result = mkdir (req->ptr1); break; +#else + case EIO_MKDIR: req->result = mkdir (req->ptr1, (mode_t)req->int2); break; +#endif + case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; +#ifndef _WIN32 + case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; + case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; + case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->int3); break; +#endif + +#ifndef _WIN32 + case EIO_READLINK: ALLOC (PATH_MAX); + req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; +#endif + +#ifndef _WIN32 + case EIO_SYNC: req->result = 0; sync (); break; +#endif + case EIO_FSYNC: req->result = fsync (req->int1); break; + case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; + case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; + case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; + case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; + case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; + case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; + + case EIO_READDIR: eio__scandir (req, self); break; + + case EIO_BUSY: +#ifdef _WIN32 + Sleep (req->nv1 * 1e3); +#else + { + struct timeval tv; + + tv.tv_sec = req->nv1; + tv.tv_usec = (req->nv1 - tv.tv_sec) * 1e6; + + req->result = select (0, 0, 0, 0, &tv); + } +#endif + break; + + case EIO_UTIME: + case EIO_FUTIME: + { + struct timeval tv[2]; + struct timeval *times; + + if (req->nv1 != -1. || req->nv2 != -1.) + { + tv[0].tv_sec = req->nv1; + tv[0].tv_usec = (req->nv1 - tv[0].tv_sec) * 1000000.; + tv[1].tv_sec = req->nv2; + tv[1].tv_usec = (req->nv2 - tv[1].tv_sec) * 1000000.; + + times = tv; + } + else + times = 0; + + req->result = req->type == EIO_FUTIME + ? futimes (req->int1, times) + : utimes (req->ptr1, times); + } + break; + + case EIO_GROUP: + abort (); /* handled in eio_request */ + + case EIO_NOP: + req->result = 0; + break; + + case EIO_CUSTOM: + ((void (*)(eio_req *))req->feed) (req); + break; + + default: + errno = ENOSYS; + req->result = -1; + break; + } + + req->errorno = errno; +} + +#ifndef EIO_NO_WRAPPERS + +eio_req *eio_nop (int pri, eio_cb cb, void *data) +{ + REQ (EIO_NOP); SEND; +} + +eio_req *eio_busy (double delay, int pri, eio_cb cb, void *data) +{ + REQ (EIO_BUSY); req->nv1 = delay; SEND; +} + +eio_req *eio_sync (int pri, eio_cb cb, void *data) +{ + REQ (EIO_SYNC); SEND; +} + +eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FSYNC); req->int1 = fd; SEND; +} + +eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) +{ + REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; +} + +eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) +{ + REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; +} + +eio_req *eio_mlock (void *addr, size_t length, int pri, eio_cb cb, void *data) +{ + REQ (EIO_MLOCK); req->ptr2 = addr; req->size = length; SEND; +} + +eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) +{ + REQ (EIO_MLOCKALL); req->int1 = flags; SEND; +} + +eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) +{ + REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; +} + +eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FDATASYNC); req->int1 = fd; SEND; +} + +eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) +{ + REQ (EIO_CLOSE); req->int1 = fd; SEND; +} + +eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data) +{ + REQ (EIO_READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND; +} + +eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) +{ + REQ (EIO_READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; +} + +eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) +{ + REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; +} + +eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FSTAT); req->int1 = fd; SEND; +} + +eio_req *eio_fstatvfs (int fd, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FSTATVFS); req->int1 = fd; SEND; +} + +eio_req *eio_futime (int fd, double atime, double mtime, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FUTIME); req->int1 = fd; req->nv1 = atime; req->nv2 = mtime; SEND; +} + +eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FTRUNCATE); req->int1 = fd; req->offs = offset; SEND; +} + +eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; +} + +eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; +} + +eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) +{ + REQ (EIO_DUP2); req->int1 = fd; req->int2 = fd2; SEND; +} + +eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, int pri, eio_cb cb, void *data) +{ + REQ (EIO_SENDFILE); req->int1 = out_fd; req->int2 = in_fd; req->offs = in_offset; req->size = length; SEND; +} + +eio_req *eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data) +{ + REQ (EIO_OPEN); PATH; req->int1 = flags; req->int2 = (long)mode; SEND; +} + +eio_req *eio_utime (const char *path, double atime, double mtime, int pri, eio_cb cb, void *data) +{ + REQ (EIO_UTIME); PATH; req->nv1 = atime; req->nv2 = mtime; SEND; +} + +eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) +{ + REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; +} + +eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) +{ + REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; +} + +eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) +{ + REQ (EIO_CHMOD); PATH; req->int2 = (long)mode; SEND; +} + +eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data) +{ + REQ (EIO_MKDIR); PATH; req->int2 = (long)mode; SEND; +} + +static eio_req * +eio__1path (int type, const char *path, int pri, eio_cb cb, void *data) +{ + REQ (type); PATH; SEND; +} + +eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_READLINK, path, pri, cb, data); +} + +eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_STAT, path, pri, cb, data); +} + +eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_LSTAT, path, pri, cb, data); +} + +eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_STATVFS, path, pri, cb, data); +} + +eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_UNLINK, path, pri, cb, data); +} + +eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_RMDIR, path, pri, cb, data); +} + +eio_req *eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data) +{ + REQ (EIO_READDIR); PATH; req->int1 = flags; SEND; +} + +eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data) +{ + REQ (EIO_MKNOD); PATH; req->int2 = (long)mode; req->int3 = (long)dev; SEND; +} + +static eio_req * +eio__2path (int type, const char *path, const char *new_path, int pri, eio_cb cb, void *data) +{ + REQ (type); PATH; + + req->flags |= EIO_FLAG_PTR2_FREE; + req->ptr2 = strdup (new_path); + if (!req->ptr2) + { + eio_api_destroy (req); + return 0; + } + + SEND; +} + +eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data) +{ + return eio__2path (EIO_LINK, path, new_path, pri, cb, data); +} + +eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data) +{ + return eio__2path (EIO_SYMLINK, path, new_path, pri, cb, data); +} + +eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) +{ + return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); +} + +eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data) +{ + REQ (EIO_CUSTOM); req->feed = (void (*)(eio_req *))execute; SEND; +} + +#endif + +eio_req *eio_grp (eio_cb cb, void *data) +{ + const int pri = EIO_PRI_MAX; + + REQ (EIO_GROUP); SEND; +} + +#undef REQ +#undef PATH +#undef SEND + +/*****************************************************************************/ +/* grp functions */ + +void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit) +{ + grp->int2 = limit; + grp->feed = feed; + + grp_try_feed (grp); +} + +void eio_grp_limit (eio_req *grp, int limit) +{ + grp->int2 = limit; + + grp_try_feed (grp); +} + +void eio_grp_add (eio_req *grp, eio_req *req) +{ + assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2)); + + grp->flags |= EIO_FLAG_GROUPADD; + + ++grp->size; + req->grp = grp; + + req->grp_prev = 0; + req->grp_next = grp->grp_first; + + if (grp->grp_first) + grp->grp_first->grp_prev = req; + + grp->grp_first = req; +} + +/*****************************************************************************/ +/* misc garbage */ + +ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) +{ + etp_worker wrk; + ssize_t ret; + + wrk.dbuf = 0; + + ret = eio__sendfile (ofd, ifd, offset, count, &wrk); + + if (wrk.dbuf) + free (wrk.dbuf); + + return ret; +} + diff --git a/src/rt/libuv/src/eio/eio.pod b/src/rt/libuv/src/eio/eio.pod new file mode 100644 index 00000000000..c83768ebf19 --- /dev/null +++ b/src/rt/libuv/src/eio/eio.pod @@ -0,0 +1,303 @@ +=head1 NAME + +libeio - truly asynchronous POSIX I/O + +=head1 SYNOPSIS + + #include + +=head1 DESCRIPTION + +The newest version of this document is also available as an html-formatted +web page you might find easier to navigate when reading it for the first +time: L. + +Note that this library is a by-product of the C perl +module, and many of the subtler points regarding requets lifetime +and so on are only documented in its documentation at the +moment: L. + +=head2 FEATURES + +This library provides fully asynchronous versions of most POSIX functions +dealign with I/O. Unlike most asynchronous libraries, this not only +includes C and C, but also C, C, C and +similar functions, as well as less rarely ones such as C, C +or C. + +It also offers wrappers around C (Solaris, Linux, HP-UX and +FreeBSD, with emulation on other platforms) and C (Linux, with +emulation elsewhere>). + +The goal is to enable you to write fully non-blocking programs. For +example, in a game server, you would not want to freeze for a few seconds +just because the server is running a backup and you happen to call +C. + +=head2 TIME REPRESENTATION + +Libeio represents time as a single floating point number, representing the +(fractional) number of seconds since the (POSIX) epoch (somewhere near +the beginning of 1970, details are complicated, don't ask). This type is +called C, but it is guarenteed to be of type C (or +better), so you can freely use C yourself. + +Unlike the name component C might indicate, it is also used for +time differences throughout libeio. + +=head2 FORK SUPPORT + +Calling C is fully supported by this module. It is implemented in these steps: + + 1. wait till all requests in "execute" state have been handled + (basically requests that are already handed over to the kernel). + 2. fork + 3. in the parent, continue business as usual, done + 4. in the child, destroy all ready and pending requests and free the + memory used by the worker threads. This gives you a fully empty + libeio queue. + +=head1 INITIALISATION/INTEGRATION + +Before you can call any eio functions you first have to initialise the +library. The library integrates into any event loop, but can also be used +without one, including in polling mode. + +You have to provide the necessary glue yourself, however. + +=over 4 + +=item int eio_init (void (*want_poll)(void), void (*done_poll)(void)) + +This function initialises the library. On success it returns C<0>, on +failure it returns C<-1> and sets C appropriately. + +It accepts two function pointers specifying callbacks as argument, both of +which can be C<0>, in which case the callback isn't called. + +=item want_poll callback + +The C callback is invoked whenever libeio wants attention (i.e. +it wants to be polled by calling C). It is "edge-triggered", +that is, it will only be called once when eio wants attention, until all +pending requests have been handled. + +This callback is called while locks are being held, so I. That includes +C. What you should do is notify some other thread, or wake up +your event loop, and then call C. + +=item done_poll callback + +This callback is invoked when libeio detects that all pending requests +have been handled. It is "edge-triggered", that is, it will only be +called once after C. To put it differently, C and +C are invoked in pairs: after C you have to call +C until either C indicates that everything has been +handled or C has been called, which signals the same. + +Note that C might return after C and C +have been called again, so watch out for races in your code. + +As with C, this callback is called while lcoks are being held, +so you I. + +=item int eio_poll () + +This function has to be called whenever there are pending requests that +need finishing. You usually call this after C has indicated +that you should do so, but you can also call this function regularly to +poll for new results. + +If any request invocation returns a non-zero value, then C +immediately returns with that value as return value. + +Otherwise, if all requests could be handled, it returns C<0>. If for some +reason not all requests have been handled, i.e. some are still pending, it +returns C<-1>. + +=back + +For libev, you would typically use an C watcher: the +C callback would invoke C to wake up the event +loop. Inside the callback set for the watcher, one would call C (followed by C again if C indicates that not +all requests have been handled yet). The race is taken care of because +libev resets/rearms the async watcher before calling your callback, +and therefore, before calling C. This might result in (some) +spurious wake-ups, but is generally harmless. + +For most other event loops, you would typically use a pipe - the event +loop should be told to wait for read readyness on the read end. In +C you would write a single byte, in C you would try +to read that byte, and in the callback for the read end, you would call +C. The race is avoided here because the event loop should invoke +your callback again and again until the byte has been read (as the pipe +read callback does not read it, only C). + +=head2 CONFIGURATION + +The functions in this section can sometimes be useful, but the default +configuration will do in most case, so you should skip this section on +first reading. + +=over 4 + +=item eio_set_max_poll_time (eio_tstamp nseconds) + +This causes C to return after it has detected that it was +running for C seconds or longer (this number can be fractional). + +This can be used to limit the amount of time spent handling eio requests, +for example, in interactive programs, you might want to limit this time to +C<0.01> seconds or so. + +Note that: + +a) libeio doesn't know how long your request callbacks take, so the time +spent in C is up to one callback invocation longer then this +interval. + +b) this is implemented by calling C after each request, +which can be costly. + +c) at least one request will be handled. + +=item eio_set_max_poll_reqs (unsigned int nreqs) + +When C is non-zero, then C will not handle more than +C requests per invocation. This is a less costly way to limit the +amount of work done by C then setting a time limit. + +If you know your callbacks are generally fast, you could use this to +encourage interactiveness in your programs by setting it to C<10>, C<100> +or even C<1000>. + +=item eio_set_min_parallel (unsigned int nthreads) + +Make sure libeio can handle at least this many requests in parallel. It +might be able handle more. + +=item eio_set_max_parallel (unsigned int nthreads) + +Set the maximum number of threads that libeio will spawn. + +=item eio_set_max_idle (unsigned int nthreads) + +Libeio uses threads internally to handle most requests, and will start and stop threads on demand. + +This call can be used to limit the number of idle threads (threads without +work to do): libeio will keep some threads idle in preperation for more +requests, but never longer than C threads. + +In addition to this, libeio will also stop threads when they are idle for +a few seconds, regardless of this setting. + +=item unsigned int eio_nthreads () + +Return the number of worker threads currently running. + +=item unsigned int eio_nreqs () + +Return the number of requests currently handled by libeio. This is the +total number of requests that have been submitted to libeio, but not yet +destroyed. + +=item unsigned int eio_nready () + +Returns the number of ready requests, i.e. requests that have been +submitted but have not yet entered the execution phase. + +=item unsigned int eio_npending () + +Returns the number of pending requests, i.e. requests that have been +executed and have results, but have not been finished yet by a call to +C). + +=back + + +=head1 ANATOMY OF AN EIO REQUEST + +#TODO + + +=head1 HIGH LEVEL REQUEST API + +#TODO + +=back + + +=head1 LOW LEVEL REQUEST API + +#TODO + +=head1 EMBEDDING + +Libeio can be embedded directly into programs. This functionality is not +documented and not (yet) officially supported. + +Note that, when including C, you are responsible for defining +the compilation environment (C<_LARGEFILE_SOURCE>, C<_GNU_SOURCE> etc.). + +If you need to know how, check the C perl module, which does +exactly that. + + +=head1 COMPILETIME CONFIGURATION + +These symbols, if used, must be defined when compiling F. + +=over 4 + +=item EIO_STACKSIZE + +This symbol governs the stack size for each eio thread. Libeio itself +was written to use very little stackspace, but when using C +requests, you might want to increase this. + +If this symbol is undefined (the default) then libeio will use its default +stack size (C currently). If it is defined, but +C<0>, then the default operating system stack size will be used. In all +other cases, the value must be an expression that evaluates to the desired +stack size. + +=back + + +=head1 PORTABILITY REQUIREMENTS + +In addition to a working ISO-C implementation, libeio relies on a few +additional extensions: + +=over 4 + +=item POSIX threads + +To be portable, this module uses threads, specifically, the POSIX threads +library must be available (and working, which partially excludes many xBSD +systems, where C is buggy). + +=item POSIX-compatible filesystem API + +This is actually a harder portability requirement: The libeio API is quite +demanding regarding POSIX API calls (symlinks, user/group management +etc.). + +=item C must hold a time value in seconds with enough accuracy + +The type C is used to represent timestamps. It is required to +have at least 51 bits of mantissa (and 9 bits of exponent), which is good +enough for at least into the year 4000. This requirement is fulfilled by +implementations implementing IEEE 754 (basically all existing ones). + +=back + +If you know of other additional requirements drop me a note. + + +=head1 AUTHOR + +Marc Lehmann . + diff --git a/src/rt/libuv/src/eio/libeio.m4 b/src/rt/libuv/src/eio/libeio.m4 new file mode 100644 index 00000000000..5302cfcc91a --- /dev/null +++ b/src/rt/libuv/src/eio/libeio.m4 @@ -0,0 +1,156 @@ +AC_SEARCH_LIBS( + pthread_create, + [pthread pthreads pthreadVC2], + , + [AC_MSG_ERROR(pthread functions not found)] +) + +AC_CACHE_CHECK(for utimes, ac_cv_utimes, [AC_LINK_IFELSE([[ +#include +#include +#include +struct timeval tv[2]; +int res; +int main (void) +{ + res = utimes ("/", tv); + return 0; +} +]],ac_cv_utimes=yes,ac_cv_utimes=no)]) +test $ac_cv_utimes = yes && AC_DEFINE(HAVE_UTIMES, 1, utimes(2) is available) + +AC_CACHE_CHECK(for futimes, ac_cv_futimes, [AC_LINK_IFELSE([[ +#include +#include +#include +struct timeval tv[2]; +int res; +int fd; +int main (void) +{ + res = futimes (fd, tv); + return 0; +} +]],ac_cv_futimes=yes,ac_cv_futimes=no)]) +test $ac_cv_futimes = yes && AC_DEFINE(HAVE_FUTIMES, 1, futimes(2) is available) + +AC_CACHE_CHECK(for readahead, ac_cv_readahead, [AC_LINK_IFELSE([ +#include +int main (void) +{ + int fd = 0; + size_t count = 2; + ssize_t res; + res = readahead (fd, 0, count); + return 0; +} +],ac_cv_readahead=yes,ac_cv_readahead=no)]) +test $ac_cv_readahead = yes && AC_DEFINE(HAVE_READAHEAD, 1, readahead(2) is available (linux)) + +AC_CACHE_CHECK(for fdatasync, ac_cv_fdatasync, [AC_LINK_IFELSE([ +#include +int main (void) +{ + int fd = 0; + fdatasync (fd); + return 0; +} +],ac_cv_fdatasync=yes,ac_cv_fdatasync=no)]) +test $ac_cv_fdatasync = yes && AC_DEFINE(HAVE_FDATASYNC, 1, fdatasync(2) is available) + +AC_CACHE_CHECK(for pread and pwrite, ac_cv_preadwrite, [AC_LINK_IFELSE([ +#include +int main (void) +{ + int fd = 0; + size_t count = 1; + char buf; + off_t offset = 1; + ssize_t res; + res = pread (fd, &buf, count, offset); + res = pwrite (fd, &buf, count, offset); + return 0; +} +],ac_cv_preadwrite=yes,ac_cv_preadwrite=no)]) +test $ac_cv_preadwrite = yes && AC_DEFINE(HAVE_PREADWRITE, 1, pread(2) and pwrite(2) are available) + +AC_CACHE_CHECK(for sendfile, ac_cv_sendfile, [AC_LINK_IFELSE([ +# include +#if __linux +# include +#elif __FreeBSD__ || defined __APPLE__ +# include +# include +#elif __hpux +# include +#else +# error unsupported architecture +#endif +int main (void) +{ + int fd = 0; + off_t offset = 1; + size_t count = 2; + ssize_t res; +#if __linux + res = sendfile (fd, fd, offset, count); +#elif __FreeBSD__ + res = sendfile (fd, fd, offset, count, 0, &offset, 0); +#elif __hpux + res = sendfile (fd, fd, offset, count, 0, 0); +#endif + return 0; +} +],ac_cv_sendfile=yes,ac_cv_sendfile=no)]) +test $ac_cv_sendfile = yes && AC_DEFINE(HAVE_SENDFILE, 1, sendfile(2) is available and supported) + +AC_CACHE_CHECK(for sync_file_range, ac_cv_sync_file_range, [AC_LINK_IFELSE([ +#include +int main (void) +{ + int fd = 0; + off64_t offset = 1; + off64_t nbytes = 1; + unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER; + ssize_t res; + res = sync_file_range (fd, offset, nbytes, flags); + return 0; +} +],ac_cv_sync_file_range=yes,ac_cv_sync_file_range=no)]) +test $ac_cv_sync_file_range = yes && AC_DEFINE(HAVE_SYNC_FILE_RANGE, 1, sync_file_range(2) is available) + +dnl ############################################################################# +dnl # these checks exist for the benefit of IO::AIO + +dnl at least uclibc defines _POSIX_ADVISORY_INFO without *any* of the required +dnl functionality actually being present. ugh. +AC_CACHE_CHECK(for posix_madvise, ac_cv_posix_madvise, [AC_LINK_IFELSE([ +#include +int main (void) +{ + int res = posix_madvise ((void *)0, (size_t)0, POSIX_MADV_NORMAL); + int a = POSIX_MADV_SEQUENTIAL; + int b = POSIX_MADV_RANDOM; + int c = POSIX_MADV_WILLNEED; + int d = POSIX_MADV_DONTNEED; + return 0; +} +],ac_cv_posix_madvise=yes,ac_cv_posix_madvise=no)]) +test $ac_cv_posix_madvise = yes && AC_DEFINE(HAVE_POSIX_MADVISE, 1, posix_madvise(2) is available) + +AC_CACHE_CHECK(for posix_fadvise, ac_cv_posix_fadvise, [AC_LINK_IFELSE([ +#define _XOPEN_SOURCE 600 +#include +int main (void) +{ + int res = posix_fadvise ((int)0, (off_t)0, (off_t)0, POSIX_FADV_NORMAL); + int a = POSIX_FADV_SEQUENTIAL; + int b = POSIX_FADV_NOREUSE; + int c = POSIX_FADV_RANDOM; + int d = POSIX_FADV_WILLNEED; + int e = POSIX_FADV_DONTNEED; + return 0; +} +],ac_cv_posix_fadvise=yes,ac_cv_posix_fadvise=no)]) +test $ac_cv_posix_fadvise = yes && AC_DEFINE(HAVE_POSIX_FADVISE, 1, posix_fadvise(2) is available) + diff --git a/src/rt/libuv/src/eio/xthread.h b/src/rt/libuv/src/eio/xthread.h new file mode 100644 index 00000000000..01e2933507d --- /dev/null +++ b/src/rt/libuv/src/eio/xthread.h @@ -0,0 +1,161 @@ +#ifndef XTHREAD_H_ +#define XTHREAD_H_ + +/* whether word reads are potentially non-atomic. + * this is conservatice, likely most arches this runs + * on have atomic word read/writes. + */ +#ifndef WORDACCESS_UNSAFE +# if __i386 || __x86_64 +# define WORDACCESS_UNSAFE 0 +# else +# define WORDACCESS_UNSAFE 1 +# endif +#endif + +///////////////////////////////////////////////////////////////////////////// + +#ifdef _WIN32 + +#ifndef __MINGW32__ +typedef int ssize_t +#endif + +#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x400 +#endif +#include //D +#include +#include +#include +#include +#include +#include +#include +#define sigset_t int +#define pthread_sigmask(a,b,c) +#define sigaddset(a,b) +#define sigemptyset(s) +#define sigfillset(s) + +typedef pthread_mutex_t xmutex_t; +#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER +#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) +#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) + +typedef pthread_cond_t xcond_t; +#define X_COND_INIT PTHREAD_COND_INITIALIZER +#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) +#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) +#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) + +typedef pthread_t xthread_t; +#define X_THREAD_PROC(name) void *name (void *thr_arg) +#define X_THREAD_ATFORK(a,b,c) + +static int +thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) +{ + int retval; + pthread_attr_t attr; + + pthread_attr_init (&attr); + pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + + retval = pthread_create (tid, &attr, proc, arg) == 0; + + pthread_attr_destroy (&attr); + + return retval; +} + +#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) +#define respipe_write(a,b,c) send ((a), (b), (c), 0) +#define respipe_close(a) PerlSock_closesocket ((a)) + +#else +///////////////////////////////////////////////////////////////////////////// + +#if __linux && !defined(_GNU_SOURCE) +# define _GNU_SOURCE +#endif + +/* just in case */ +#define _REENTRANT 1 + +#if __solaris +# define _POSIX_PTHREAD_SEMANTICS 1 +/* try to bribe solaris headers into providing a current pthread API + * despite environment being configured for an older version. + */ +# define __EXTENSIONS__ 1 +#endif + +#include +#include +#include +#include +#include + +typedef pthread_mutex_t xmutex_t; +#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) +# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP +#else +# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER +#endif +#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) +#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) + +typedef pthread_cond_t xcond_t; +#define X_COND_INIT PTHREAD_COND_INITIALIZER +#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) +#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) +#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) + +typedef pthread_t xthread_t; +#define X_THREAD_PROC(name) static void *name (void *thr_arg) +#define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) + +// the broken bsd's once more +#ifndef PTHREAD_STACK_MIN +# define PTHREAD_STACK_MIN 0 +#endif + +#ifndef X_STACKSIZE +# define X_STACKSIZE sizeof (long) * 4096 +#endif + +static int +thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) +{ + int retval; + sigset_t fullsigset, oldsigset; + pthread_attr_t attr; + + pthread_attr_init (&attr); + pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < X_STACKSIZE ? X_STACKSIZE : PTHREAD_STACK_MIN); +#ifdef PTHREAD_SCOPE_PROCESS + pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); +#endif + + sigfillset (&fullsigset); + + pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); + retval = pthread_create (tid, &attr, proc, arg) == 0; + pthread_sigmask (SIG_SETMASK, &oldsigset, 0); + + pthread_attr_destroy (&attr); + + return retval; +} + +#define respipe_read(a,b,c) read ((a), (b), (c)) +#define respipe_write(a,b,c) write ((a), (b), (c)) +#define respipe_close(a) close ((a)) + +#endif + +#endif + diff --git a/src/rt/libuv/ev/Changes b/src/rt/libuv/src/ev/Changes similarity index 100% rename from src/rt/libuv/ev/Changes rename to src/rt/libuv/src/ev/Changes diff --git a/src/rt/libuv/ev/LICENSE b/src/rt/libuv/src/ev/LICENSE similarity index 100% rename from src/rt/libuv/ev/LICENSE rename to src/rt/libuv/src/ev/LICENSE diff --git a/src/rt/libuv/ev/Makefile.am b/src/rt/libuv/src/ev/Makefile.am similarity index 100% rename from src/rt/libuv/ev/Makefile.am rename to src/rt/libuv/src/ev/Makefile.am diff --git a/src/rt/libuv/ev/Makefile.in b/src/rt/libuv/src/ev/Makefile.in similarity index 100% rename from src/rt/libuv/ev/Makefile.in rename to src/rt/libuv/src/ev/Makefile.in diff --git a/src/rt/libuv/ev/README b/src/rt/libuv/src/ev/README similarity index 100% rename from src/rt/libuv/ev/README rename to src/rt/libuv/src/ev/README diff --git a/src/rt/libuv/src/ev/aclocal.m4 b/src/rt/libuv/src/ev/aclocal.m4 new file mode 100644 index 00000000000..18abb73686c --- /dev/null +++ b/src/rt/libuv/src/ev/aclocal.m4 @@ -0,0 +1,8957 @@ +# generated automatically by aclocal 1.11.1 -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],, +[m4_warning([this file was generated for autoconf 2.67. +You have another version of autoconf. It may work, but is not guaranteed to. +If you have problems, you may need to regenerate the build system entirely. +To do so, use the procedure documented by the package, typically `autoreconf'.])]) + +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +m4_define([_LT_COPYING], [dnl +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, or +# obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +]) + +# serial 56 LT_INIT + + +# LT_PREREQ(VERSION) +# ------------------ +# Complain and exit if this libtool version is less that VERSION. +m4_defun([LT_PREREQ], +[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, + [m4_default([$3], + [m4_fatal([Libtool version $1 or higher is required], + 63)])], + [$2])]) + + +# _LT_CHECK_BUILDDIR +# ------------------ +# Complain if the absolute build directory name contains unusual characters +m4_defun([_LT_CHECK_BUILDDIR], +[case `pwd` in + *\ * | *\ *) + AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; +esac +]) + + +# LT_INIT([OPTIONS]) +# ------------------ +AC_DEFUN([LT_INIT], +[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS="$ltmain" + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +])# LT_INIT + +# Old names: +AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) +AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PROG_LIBTOOL], []) +dnl AC_DEFUN([AM_PROG_LIBTOOL], []) + + +# _LT_CC_BASENAME(CC) +# ------------------- +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +m4_defun([_LT_CC_BASENAME], +[for cc_temp in $1""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` +]) + + +# _LT_FILEUTILS_DEFAULTS +# ---------------------- +# It is okay to use these file commands and assume they have been set +# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'. +m4_defun([_LT_FILEUTILS_DEFAULTS], +[: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} +])# _LT_FILEUTILS_DEFAULTS + + +# _LT_SETUP +# --------- +m4_defun([_LT_SETUP], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +_LT_DECL([], [host_alias], [0], [The host system])dnl +_LT_DECL([], [host], [0])dnl +_LT_DECL([], [host_os], [0])dnl +dnl +_LT_DECL([], [build_alias], [0], [The build system])dnl +_LT_DECL([], [build], [0])dnl +_LT_DECL([], [build_os], [0])dnl +dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +dnl +AC_REQUIRE([AC_PROG_LN_S])dnl +test -z "$LN_S" && LN_S="ln -s" +_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl +dnl +AC_REQUIRE([LT_CMD_MAX_LEN])dnl +_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl +_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl +dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_CHECK_MAGIC_METHOD])dnl +m4_require([_LT_CMD_OLD_ARCHIVE])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl + +_LT_CONFIG_LIBTOOL_INIT([ +# See if we are running on zsh, and set the options which allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi +]) +if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi + +_LT_CHECK_OBJDIR + +m4_require([_LT_TAG_COMPILER])dnl +_LT_PROG_ECHO_BACKSLASH + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([["`\\]]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld="$lt_cv_prog_gnu_ld" + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + _LT_PATH_MAGIC + fi + ;; +esac + +# Use C for the default configuration in the libtool script +LT_SUPPORTED_TAG([CC]) +_LT_LANG_C_CONFIG +_LT_LANG_DEFAULT_CONFIG +_LT_CONFIG_COMMANDS +])# _LT_SETUP + + +# _LT_PROG_LTMAIN +# --------------- +# Note that this code is called both from `configure', and `config.status' +# now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, +# `config.status' has no value for ac_aux_dir unless we are using Automake, +# so we pass a copy along to make sure it has a sensible value anyway. +m4_defun([_LT_PROG_LTMAIN], +[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl +_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) +ltmain="$ac_aux_dir/ltmain.sh" +])# _LT_PROG_LTMAIN + + + +# So that we can recreate a full libtool script including additional +# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS +# in macros and then make a single call at the end using the `libtool' +# label. + + +# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) +# ---------------------------------------- +# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL_INIT], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_INIT], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_INIT]) + + +# _LT_CONFIG_LIBTOOL([COMMANDS]) +# ------------------------------ +# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) + + +# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) +# ----------------------------------------------------- +m4_defun([_LT_CONFIG_SAVE_COMMANDS], +[_LT_CONFIG_LIBTOOL([$1]) +_LT_CONFIG_LIBTOOL_INIT([$2]) +]) + + +# _LT_FORMAT_COMMENT([COMMENT]) +# ----------------------------- +# Add leading comment marks to the start of each line, and a trailing +# full-stop to the whole comment if one is not present already. +m4_define([_LT_FORMAT_COMMENT], +[m4_ifval([$1], [ +m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], + [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) +)]) + + + + + +# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) +# ------------------------------------------------------------------- +# CONFIGNAME is the name given to the value in the libtool script. +# VARNAME is the (base) name used in the configure script. +# VALUE may be 0, 1 or 2 for a computed quote escaped value based on +# VARNAME. Any other value will be used directly. +m4_define([_LT_DECL], +[lt_if_append_uniq([lt_decl_varnames], [$2], [, ], + [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], + [m4_ifval([$1], [$1], [$2])]) + lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) + m4_ifval([$4], + [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) + lt_dict_add_subkey([lt_decl_dict], [$2], + [tagged?], [m4_ifval([$5], [yes], [no])])]) +]) + + +# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) +# -------------------------------------------------------- +m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) + + +# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_tag_varnames], +[_lt_decl_filter([tagged?], [yes], $@)]) + + +# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) +# --------------------------------------------------------- +m4_define([_lt_decl_filter], +[m4_case([$#], + [0], [m4_fatal([$0: too few arguments: $#])], + [1], [m4_fatal([$0: too few arguments: $#: $1])], + [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], + [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], + [lt_dict_filter([lt_decl_dict], $@)])[]dnl +]) + + +# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) +# -------------------------------------------------- +m4_define([lt_decl_quote_varnames], +[_lt_decl_filter([value], [1], $@)]) + + +# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_dquote_varnames], +[_lt_decl_filter([value], [2], $@)]) + + +# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_varnames_tagged], +[m4_assert([$# <= 2])dnl +_$0(m4_quote(m4_default([$1], [[, ]])), + m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), + m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) +m4_define([_lt_decl_varnames_tagged], +[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) + + +# lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_all_varnames], +[_$0(m4_quote(m4_default([$1], [[, ]])), + m4_if([$2], [], + m4_quote(lt_decl_varnames), + m4_quote(m4_shift($@))))[]dnl +]) +m4_define([_lt_decl_all_varnames], +[lt_join($@, lt_decl_varnames_tagged([$1], + lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl +]) + + +# _LT_CONFIG_STATUS_DECLARE([VARNAME]) +# ------------------------------------ +# Quote a variable value, and forward it to `config.status' so that its +# declaration there will have the same value as in `configure'. VARNAME +# must have a single quote delimited value for this to work. +m4_define([_LT_CONFIG_STATUS_DECLARE], +[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`']) + + +# _LT_CONFIG_STATUS_DECLARATIONS +# ------------------------------ +# We delimit libtool config variables with single quotes, so when +# we write them to config.status, we have to be sure to quote all +# embedded single quotes properly. In configure, this macro expands +# each variable declared with _LT_DECL (and _LT_TAGDECL) into: +# +# ='`$ECHO "X$" | $Xsed -e "$delay_single_quote_subst"`' +m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], +[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), + [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAGS +# ---------------- +# Output comment and list of tags supported by the script +m4_defun([_LT_LIBTOOL_TAGS], +[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl +available_tags="_LT_TAGS"dnl +]) + + +# _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) +# ----------------------------------- +# Extract the dictionary values for VARNAME (optionally with TAG) and +# expand to a commented shell variable setting: +# +# # Some comment about what VAR is for. +# visible_name=$lt_internal_name +m4_define([_LT_LIBTOOL_DECLARE], +[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], + [description])))[]dnl +m4_pushdef([_libtool_name], + m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl +m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), + [0], [_libtool_name=[$]$1], + [1], [_libtool_name=$lt_[]$1], + [2], [_libtool_name=$lt_[]$1], + [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl +m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl +]) + + +# _LT_LIBTOOL_CONFIG_VARS +# ----------------------- +# Produce commented declarations of non-tagged libtool config variables +# suitable for insertion in the LIBTOOL CONFIG section of the `libtool' +# script. Tagged libtool config variables (even for the LIBTOOL CONFIG +# section) are produced by _LT_LIBTOOL_TAG_VARS. +m4_defun([_LT_LIBTOOL_CONFIG_VARS], +[m4_foreach([_lt_var], + m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAG_VARS(TAG) +# ------------------------- +m4_define([_LT_LIBTOOL_TAG_VARS], +[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) + + +# _LT_TAGVAR(VARNAME, [TAGNAME]) +# ------------------------------ +m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) + + +# _LT_CONFIG_COMMANDS +# ------------------- +# Send accumulated output to $CONFIG_STATUS. Thanks to the lists of +# variables for single and double quote escaping we saved from calls +# to _LT_DECL, we can put quote escaped variables declarations +# into `config.status', and then the shell code to quote escape them in +# for loops in `config.status'. Finally, any additional code accumulated +# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. +m4_defun([_LT_CONFIG_COMMANDS], +[AC_PROVIDE_IFELSE([LT_OUTPUT], + dnl If the libtool generation code has been placed in $CONFIG_LT, + dnl instead of duplicating it all over again into config.status, + dnl then we will have config.status run $CONFIG_LT later, so it + dnl needs to know what name is stored there: + [AC_CONFIG_COMMANDS([libtool], + [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], + dnl If the libtool generation code is destined for config.status, + dnl expand the accumulated commands and init code now: + [AC_CONFIG_COMMANDS([libtool], + [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) +])#_LT_CONFIG_COMMANDS + + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], +[ + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +_LT_CONFIG_STATUS_DECLARATIONS +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# Quote evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_quote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_dquote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Fix-up fallback echo if it was mangled by the above quoting rules. +case \$lt_ECHO in +*'\\\[$]0 --fallback-echo"')dnl " + lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\` + ;; +esac + +_LT_OUTPUT_LIBTOOL_INIT +]) + + +# LT_OUTPUT +# --------- +# This macro allows early generation of the libtool script (before +# AC_OUTPUT is called), incase it is used in configure for compilation +# tests. +AC_DEFUN([LT_OUTPUT], +[: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +cat >"$CONFIG_LT" <<_LTEOF +#! $SHELL +# Generated by $as_me. +# Run this file to recreate a libtool stub with the current configuration. + +lt_cl_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AS_SHELL_SANITIZE +_AS_PREPARE + +exec AS_MESSAGE_FD>&1 +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +\`$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2008 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test $[#] != 0 +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try \`$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try \`$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +if test "$no_create" != yes; then + lt_cl_success=: + test "$silent" = yes && + lt_config_lt_args="$lt_config_lt_args --quiet" + exec AS_MESSAGE_LOG_FD>/dev/null + $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false + exec AS_MESSAGE_LOG_FD>>config.log + $lt_cl_success || AS_EXIT(1) +fi +])# LT_OUTPUT + + +# _LT_CONFIG(TAG) +# --------------- +# If TAG is the built-in tag, create an initial libtool script with a +# default configuration from the untagged config vars. Otherwise add code +# to config.status for appending the configuration named by TAG from the +# matching tagged config vars. +m4_defun([_LT_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_CONFIG_SAVE_COMMANDS([ + m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl + m4_if(_LT_TAG, [C], [ + # See if we are running on zsh, and set the options which allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + + cfgfile="${ofile}T" + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL + +# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +_LT_COPYING +_LT_LIBTOOL_TAGS + +# ### BEGIN LIBTOOL CONFIG +_LT_LIBTOOL_CONFIG_VARS +_LT_LIBTOOL_TAG_VARS +# ### END LIBTOOL CONFIG + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + _LT_PROG_LTMAIN + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + _LT_PROG_XSI_SHELLFNS + + sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +], +[cat <<_LT_EOF >> "$ofile" + +dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded +dnl in a comment (ie after a #). +# ### BEGIN LIBTOOL TAG CONFIG: $1 +_LT_LIBTOOL_TAG_VARS(_LT_TAG) +# ### END LIBTOOL TAG CONFIG: $1 +_LT_EOF +])dnl /m4_if +], +[m4_if([$1], [], [ + PACKAGE='$PACKAGE' + VERSION='$VERSION' + TIMESTAMP='$TIMESTAMP' + RM='$RM' + ofile='$ofile'], []) +])dnl /_LT_CONFIG_SAVE_COMMANDS +])# _LT_CONFIG + + +# LT_SUPPORTED_TAG(TAG) +# --------------------- +# Trace this macro to discover what tags are supported by the libtool +# --tag option, using: +# autoconf --trace 'LT_SUPPORTED_TAG:$1' +AC_DEFUN([LT_SUPPORTED_TAG], []) + + +# C support is built-in for now +m4_define([_LT_LANG_C_enabled], []) +m4_define([_LT_TAGS], []) + + +# LT_LANG(LANG) +# ------------- +# Enable libtool support for the given language if not already enabled. +AC_DEFUN([LT_LANG], +[AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +])# LT_LANG + + +# _LT_LANG(LANGNAME) +# ------------------ +m4_defun([_LT_LANG], +[m4_ifdef([_LT_LANG_]$1[_enabled], [], + [LT_SUPPORTED_TAG([$1])dnl + m4_append([_LT_TAGS], [$1 ])dnl + m4_define([_LT_LANG_]$1[_enabled], [])dnl + _LT_LANG_$1_CONFIG($1)])dnl +])# _LT_LANG + + +# _LT_LANG_DEFAULT_CONFIG +# ----------------------- +m4_defun([_LT_LANG_DEFAULT_CONFIG], +[AC_PROVIDE_IFELSE([AC_PROG_CXX], + [LT_LANG(CXX)], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) + +AC_PROVIDE_IFELSE([AC_PROG_F77], + [LT_LANG(F77)], + [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [LT_LANG(FC)], + [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) + +dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal +dnl pulling things in needlessly. +AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([LT_PROG_GCJ], + [LT_LANG(GCJ)], + [m4_ifdef([AC_PROG_GCJ], + [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([A][M_PROG_GCJ], + [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([LT_PROG_GCJ], + [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) + +AC_PROVIDE_IFELSE([LT_PROG_RC], + [LT_LANG(RC)], + [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) +])# _LT_LANG_DEFAULT_CONFIG + +# Obsolete macros: +AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_CXX], []) +dnl AC_DEFUN([AC_LIBTOOL_F77], []) +dnl AC_DEFUN([AC_LIBTOOL_FC], []) +dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) + + +# _LT_TAG_COMPILER +# ---------------- +m4_defun([_LT_TAG_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl +_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl +_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl +_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_TAG_COMPILER + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +m4_defun([_LT_COMPILER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +m4_defun([_LT_LINKER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* +])# _LT_LINKER_BOILERPLATE + +# _LT_REQUIRED_DARWIN_CHECKS +# ------------------------- +m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ + case $host_os in + rhapsody* | darwin*) + AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) + AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) + AC_CHECK_TOOL([LIPO], [lipo], [:]) + AC_CHECK_TOOL([OTOOL], [otool], [:]) + AC_CHECK_TOOL([OTOOL64], [otool64], [:]) + _LT_DECL([], [DSYMUTIL], [1], + [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) + _LT_DECL([], [NMEDIT], [1], + [Tool to change global to local symbols on Mac OS X]) + _LT_DECL([], [LIPO], [1], + [Tool to manipulate fat objects and archives on Mac OS X]) + _LT_DECL([], [OTOOL], [1], + [ldd/readelf like tool for Mach-O binaries on Mac OS X]) + _LT_DECL([], [OTOOL64], [1], + [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) + + AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], + [lt_cv_apple_cc_single_mod=no + if test -z "${LT_MULTI_MODULE}"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi]) + AC_CACHE_CHECK([for -exported_symbols_list linker flag], + [lt_cv_ld_exported_symbols_list], + [lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [lt_cv_ld_exported_symbols_list=yes], + [lt_cv_ld_exported_symbols_list=no]) + LDFLAGS="$save_LDFLAGS" + ]) + case $host_os in + rhapsody* | darwin1.[[012]]) + _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + 10.[[012]]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test "$lt_cv_apple_cc_single_mod" = "yes"; then + _lt_dar_single_mod='$single_module' + fi + if test "$lt_cv_ld_exported_symbols_list" = "yes"; then + _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + if test "$DSYMUTIL" != ":"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac +]) + + +# _LT_DARWIN_LINKER_FEATURES +# -------------------------- +# Checks for linker and compiler features on darwin +m4_defun([_LT_DARWIN_LINKER_FEATURES], +[ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined" + case $cc_basename in + ifort*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=echo + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + m4_if([$1], [CXX], +[ if test "$lt_cv_apple_cc_single_mod" != "yes"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi +],[]) + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi +]) + +# _LT_SYS_MODULE_PATH_AIX +# ----------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +m4_defun([_LT_SYS_MODULE_PATH_AIX], +[m4_require([_LT_DECL_SED])dnl +AC_LINK_IFELSE(AC_LANG_PROGRAM,[ +lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\(.*\)$/\1/ + p + } + }' +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +fi],[]) +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi +])# _LT_SYS_MODULE_PATH_AIX + + +# _LT_SHELL_INIT(ARG) +# ------------------- +m4_define([_LT_SHELL_INIT], +[ifdef([AC_DIVERSION_NOTICE], + [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)], + [AC_DIVERT_PUSH(NOTICE)]) +$1 +AC_DIVERT_POP +])# _LT_SHELL_INIT + + +# _LT_PROG_ECHO_BACKSLASH +# ----------------------- +# Add some code to the start of the generated configure script which +# will find an echo command which doesn't interpret backslashes. +m4_defun([_LT_PROG_ECHO_BACKSLASH], +[_LT_SHELL_INIT([ +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$lt_ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','` + ;; +esac + +ECHO=${lt_ECHO-echo} +if test "X[$]1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X[$]1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then + # Yippee, $ECHO works! + : +else + # Restart under the correct shell. + exec $SHELL "[$]0" --no-reexec ${1+"[$]@"} +fi + +if test "X[$]1" = X--fallback-echo; then + # used as fallback echo + shift + cat <<_LT_EOF +[$]* +_LT_EOF + exit 0 +fi + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test -z "$lt_ECHO"; then + if test "X${echo_test_string+set}" != Xset; then + # find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if { echo_test_string=`eval $cmd`; } 2>/dev/null && + { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null + then + break + fi + done + fi + + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : + else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$ECHO" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + ECHO='print -r' + elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"} + else + # Try using printf. + ECHO='printf %s\n' + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do + if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "[$]0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"} + else + # Oops. We lost completely, so just stick with echo. + ECHO=echo + fi + fi + fi + fi + fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +lt_ECHO=$ECHO +if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then + lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo" +fi + +AC_SUBST(lt_ECHO) +]) +_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) +_LT_DECL([], [ECHO], [1], + [An echo program that does not interpret backslashes]) +])# _LT_PROG_ECHO_BACKSLASH + + +# _LT_ENABLE_LOCK +# --------------- +m4_defun([_LT_ENABLE_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AS_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out which ABI we are using. + echo '[#]line __oline__ "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test x"$lt_cv_cc_needs_belf" != x"yes"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS="$SAVE_CFLAGS" + fi + ;; +sparc*-*solaris*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) LD="${LD-ld} -m elf64_sparc" ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks="$enable_libtool_lock" +])# _LT_ENABLE_LOCK + + +# _LT_CMD_OLD_ARCHIVE +# ------------------- +m4_defun([_LT_CMD_OLD_ARCHIVE], +[AC_CHECK_TOOL(AR, ar, false) +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru +_LT_DECL([], [AR], [1], [The archiver]) +_LT_DECL([], [AR_FLAGS], [1]) + +AC_CHECK_TOOL(STRIP, strip, :) +test -z "$STRIP" && STRIP=: +_LT_DECL([], [STRIP], [1], [A symbol stripping program]) + +AC_CHECK_TOOL(RANLIB, ranlib, :) +test -z "$RANLIB" && RANLIB=: +_LT_DECL([], [RANLIB], [1], + [Commands used to install an old-style archive]) + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi +_LT_DECL([], [old_postinstall_cmds], [2]) +_LT_DECL([], [old_postuninstall_cmds], [2]) +_LT_TAGDECL([], [old_archive_cmds], [2], + [Commands used to build an old-style archive]) +])# _LT_CMD_OLD_ARCHIVE + + +# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([_LT_COMPILER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test x"[$]$2" = xyes; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +])# _LT_COMPILER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) + + +# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------- +# Check whether the given linker option works +AC_DEFUN([_LT_LINKER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS="$save_LDFLAGS" +]) + +if test x"[$]$2" = xyes; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +])# _LT_LINKER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) + + +# LT_CMD_MAX_LEN +#--------------- +AC_DEFUN([LT_CMD_MAX_LEN], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8 ; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \ + = "XX$teststring$teststring"; } >/dev/null 2>&1 && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n $lt_cv_sys_max_cmd_len ; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +])# LT_CMD_MAX_LEN + +# Old name: +AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) + + +# _LT_HEADER_DLFCN +# ---------------- +m4_defun([_LT_HEADER_DLFCN], +[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl +])# _LT_HEADER_DLFCN + + +# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ---------------------------------------------------------------- +m4_defun([_LT_TRY_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "$cross_compiling" = yes; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +[#line __oline__ "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_TRY_DLOPEN_SELF + + +# LT_SYS_DLOPEN_SELF +# ------------------ +AC_DEFUN([LT_SYS_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen="shl_load"], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen="dlopen"], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test "x$lt_cv_dlopen_self" = xyes; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +])# LT_SYS_DLOPEN_SELF + +# Old name: +AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) + + +# _LT_COMPILER_C_O([TAGNAME]) +# --------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler. +# This macro does not hard code the compiler like AC_PROG_CC_C_O. +m4_defun([_LT_COMPILER_C_O], +[m4_require([_LT_DECL_SED])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* +]) +_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], + [Does compiler simultaneously support -c and -o options?]) +])# _LT_COMPILER_C_O + + +# _LT_COMPILER_FILE_LOCKS([TAGNAME]) +# ---------------------------------- +# Check to see if we can do hard links to lock some files if needed +m4_defun([_LT_COMPILER_FILE_LOCKS], +[m4_require([_LT_ENABLE_LOCK])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_COMPILER_C_O([$1]) + +hard_links="nottested" +if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test "$hard_links" = no; then + AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) +])# _LT_COMPILER_FILE_LOCKS + + +# _LT_CHECK_OBJDIR +# ---------------- +m4_defun([_LT_CHECK_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +_LT_DECL([], [objdir], [0], + [The name of the directory that contains temporary libtool files])dnl +m4_pattern_allow([LT_OBJDIR])dnl +AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/", + [Define to the sub-directory in which libtool stores uninstalled libraries.]) +])# _LT_CHECK_OBJDIR + + +# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) +# -------------------------------------- +# Check hardcoding attributes. +m4_defun([_LT_LINKER_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || + test -n "$_LT_TAGVAR(runpath_var, $1)" || + test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then + + # We can hardcode non-existent directories. + if test "$_LT_TAGVAR(hardcode_direct, $1)" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no && + test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then + # Linking always hardcodes the temporary library directory. + _LT_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) + +if test "$_LT_TAGVAR(hardcode_action, $1)" = relink || + test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi +_LT_TAGDECL([], [hardcode_action], [0], + [How to hardcode a shared library path into an executable]) +])# _LT_LINKER_HARDCODE_LIBPATH + + +# _LT_CMD_STRIPLIB +# ---------------- +m4_defun([_LT_CMD_STRIPLIB], +[m4_require([_LT_DECL_EGREP]) +striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +_LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) +_LT_DECL([], [striplib], [1]) +])# _LT_CMD_STRIPLIB + + +# _LT_SYS_DYNAMIC_LINKER([TAG]) +# ----------------------------- +# PORTME Fill in your ld.so characteristics +m4_defun([_LT_SYS_DYNAMIC_LINKER], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_OBJDUMP])dnl +m4_require([_LT_DECL_SED])dnl +AC_MSG_CHECKING([dynamic linker characteristics]) +m4_if([$1], + [], [ +if test "$GCC" = yes; then + case $host_os in + darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; + *) lt_awk_arg="/^libraries:/" ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'` + else + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary. + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path/$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" + else + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk ' +BEGIN {RS=" "; FS="/|\n";} { + lt_foo=""; + lt_count=0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo="/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[[lt_foo]]++; } + if (lt_freq[[lt_foo]] == 1) { print lt_foo; } +}'` + sys_lib_search_path_spec=`$ECHO $lt_search_path_spec` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix[[4-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[123]]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix[[3-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # Some binutils ld are patched to set DT_RUNPATH + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[[89]] | openbsd2.[[89]].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then + sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" +fi +if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then + sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" +fi + +_LT_DECL([], [variables_saved_for_relink], [1], + [Variables whose values should be saved in libtool wrapper scripts and + restored at link time]) +_LT_DECL([], [need_lib_prefix], [0], + [Do we need the "lib" prefix for modules?]) +_LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) +_LT_DECL([], [version_type], [0], [Library versioning type]) +_LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) +_LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) +_LT_DECL([], [shlibpath_overrides_runpath], [0], + [Is shlibpath searched before the hard-coded library search path?]) +_LT_DECL([], [libname_spec], [1], [Format of library name prefix]) +_LT_DECL([], [library_names_spec], [1], + [[List of archive names. First name is the real one, the rest are links. + The last name is the one that the linker finds with -lNAME]]) +_LT_DECL([], [soname_spec], [1], + [[The coded name of the library, if different from the real name]]) +_LT_DECL([], [postinstall_cmds], [2], + [Command to use after installation of a shared archive]) +_LT_DECL([], [postuninstall_cmds], [2], + [Command to use after uninstallation of a shared archive]) +_LT_DECL([], [finish_cmds], [2], + [Commands used to finish a libtool library installation in a directory]) +_LT_DECL([], [finish_eval], [1], + [[As "finish_cmds", except a single script fragment to be evaled but + not shown]]) +_LT_DECL([], [hardcode_into_libs], [0], + [Whether we should hardcode library paths into libraries]) +_LT_DECL([], [sys_lib_search_path_spec], [2], + [Compile-time system search path for libraries]) +_LT_DECL([], [sys_lib_dlsearch_path_spec], [2], + [Run-time system search path for libraries]) +])# _LT_SYS_DYNAMIC_LINKER + + +# _LT_PATH_TOOL_PREFIX(TOOL) +# -------------------------- +# find a file program which can recognize shared library +AC_DEFUN([_LT_PATH_TOOL_PREFIX], +[m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$1; then + lt_cv_path_MAGIC_CMD="$ac_dir/$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac]) +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +])# _LT_PATH_TOOL_PREFIX + +# Old name: +AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) + + +# _LT_PATH_MAGIC +# -------------- +# find a file program which can recognize a shared library +m4_defun([_LT_PATH_MAGIC], +[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# _LT_PATH_MAGIC + + +# LT_PATH_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([LT_PATH_LD], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test "$withval" = no || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[[3-9]]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + +_LT_DECL([], [deplibs_check_method], [1], + [Method to check whether dependent libraries are shared objects]) +_LT_DECL([], [file_magic_cmd], [1], + [Command to use when deplibs_check_method == "file_magic"]) +])# _LT_CHECK_MAGIC_METHOD + + +# LT_PATH_NM +# ---------- +# find the pathname to a BSD- or MS-compatible name lister +AC_DEFUN([LT_PATH_NM], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_nm_to_check="${ac_tool_prefix}nm" + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/$lt_tmp_nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS="$lt_save_ifs" + done + : ${lt_cv_path_NM=no} +fi]) +if test "$lt_cv_path_NM" != "no"; then + NM="$lt_cv_path_NM" +else + # Didn't find any BSD compatible name lister, look for dumpbin. + AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :) + AC_SUBST([DUMPBIN]) + if test "$DUMPBIN" != ":"; then + NM="$DUMPBIN" + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +])# LT_PATH_NM + +# Old names: +AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) +AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_PROG_NM], []) +dnl AC_DEFUN([AC_PROG_NM], []) + + +# LT_LIB_M +# -------- +# check for math library +AC_DEFUN([LT_LIB_M], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM="-lm") + ;; +esac +AC_SUBST([LIBM]) +])# LT_LIB_M + +# Old name: +AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_CHECK_LIBM], []) + + +# _LT_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------- +m4_defun([_LT_COMPILER_NO_RTTI], +[m4_require([_LT_TAG_COMPILER])dnl + +_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + + _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], + [Compiler flag to turn off builtin functions]) +])# _LT_COMPILER_NO_RTTI + + +# _LT_CMD_GLOBAL_SYMBOLS +# ---------------------- +m4_defun([_LT_CMD_GLOBAL_SYMBOLS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_NM])dnl +AC_REQUIRE([LT_PATH_LD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_TAG_COMPILER])dnl + +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) + if test "$host_cpu" = ia64; then + symcode='[[ABCDEGRST]]' + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p'" +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"lib\2\", (void *) \&\2},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function + # and D for any global variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK ['"\ +" {last_section=section; section=\$ 3};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ +" {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ +" s[1]~/^[@?]/{print s[1], s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx]" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + nlist=conftest.nm + if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[[]] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi + +_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], + [Take the output of nm and produce a listing of raw symbols and C names]) +_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], + [Transform the output of nm in a proper C declaration]) +_LT_DECL([global_symbol_to_c_name_address], + [lt_cv_sys_global_symbol_to_c_name_address], [1], + [Transform the output of nm in a C name address pair]) +_LT_DECL([global_symbol_to_c_name_address_lib_prefix], + [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], + [Transform the output of nm in a C name address pair when lib prefix is needed]) +]) # _LT_CMD_GLOBAL_SYMBOLS + + +# _LT_COMPILER_PIC([TAGNAME]) +# --------------------------- +m4_defun([_LT_COMPILER_PIC], +[m4_require([_LT_TAG_COMPILER])dnl +_LT_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_TAGVAR(lt_prog_compiler_static, $1)= + +AC_MSG_CHECKING([for $compiler option to produce PIC]) +m4_if([$1], [CXX], [ + # C++ specific cases for pic, static, wl, etc. + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix[[4-9]]*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + if test "$host_cpu" != ia64; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64 which still supported -KPIC. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xlc* | xlC*) + # IBM XL 8.0 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd* | netbsdelf*-gnu) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + hpux9* | hpux10* | hpux11*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu) + case $cc_basename in + # old Intel for x86_64 which still supported -KPIC. + ecc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' + _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xl*) + # IBM XL C 8.0/Fortran 10.1 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + *Sun\ F*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='' + ;; + esac + ;; + esac + ;; + + newsos6) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + rdos*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" + ;; +esac +AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) +_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], + [How to pass a linker flag through the compiler]) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], + [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], + [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], + [Additional compiler flags for building library objects]) + +# +# Check to make sure the static flag actually works. +# +wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" +_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) +_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], + [Compiler flag to prevent dynamic linking]) +])# _LT_COMPILER_PIC + + +# _LT_LINKER_SHLIBS([TAGNAME]) +# ---------------------------- +# See if the linker supports building shared libraries. +m4_defun([_LT_LINKER_SHLIBS], +[AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +m4_if([$1], [CXX], [ + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + case $host_os in + aix[[4-9]]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" + ;; + cygwin* | mingw* | cegcc*) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + ;; + linux* | k*bsd*-gnu) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] +], [ + runpath_var= + _LT_TAGVAR(allow_undefined_flag, $1)= + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(archive_cmds, $1)= + _LT_TAGVAR(archive_expsym_cmds, $1)= + _LT_TAGVAR(compiler_needs_object, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(hardcode_automatic, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= + _LT_TAGVAR(hardcode_libdir_separator, $1)= + _LT_TAGVAR(hardcode_minus_L, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(inherit_rpath, $1)=no + _LT_TAGVAR(link_all_deplibs, $1)=unknown + _LT_TAGVAR(module_cmds, $1)= + _LT_TAGVAR(module_expsym_cmds, $1)= + _LT_TAGVAR(old_archive_from_new_cmds, $1)= + _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_TAGVAR(thread_safe_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. +dnl Note also adjust exclude_expsyms for C++ above. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + linux* | k*bsd*-gnu) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + esac + + _LT_TAGVAR(ld_shlibs, $1)=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[[3-9]]*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test "$host_os" = linux-dietlibc; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test "$tmp_diet" = no + then + tmp_addflag= + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + _LT_TAGVAR(whole_archive_flag_spec, $1)= + tmp_sharedflag='--shared' ;; + xl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + xlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir' + _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then + runpath_var= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GCC" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + _LT_TAGVAR(link_all_deplibs, $1)=no + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + bsdi[[45]]*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' + _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + freebsd1*) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" + AC_LINK_IFELSE(int foo(void) {}, + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' + ) + LDFLAGS="$save_LDFLAGS" + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *nto* | *qnx*) + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + else + case $host_os in + openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + ;; + esac + fi + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' + if test "$GCC" = yes; then + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. GCC discards it without `$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test "$GCC" = yes; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + fi + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + if test x$host_vendor = xsni; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym' + ;; + esac + fi + fi +]) +AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) +test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld + +_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl +_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl +_LT_DECL([], [extract_expsyms_cmds], [2], + [The commands to extract the exported symbol list from a shared archive]) + +# +# Do we need to explicitly link libc? +# +case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $_LT_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_MSG_CHECKING([whether -lc should be explicitly linked in]) + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)]) + ;; + esac + fi + ;; +esac + +_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], + [Whether or not to add -lc for building shared libraries]) +_LT_TAGDECL([allow_libtool_libs_with_static_runtimes], + [enable_shared_with_static_runtimes], [0], + [Whether or not to disallow shared libs when runtime libs are static]) +_LT_TAGDECL([], [export_dynamic_flag_spec], [1], + [Compiler flag to allow reflexive dlopens]) +_LT_TAGDECL([], [whole_archive_flag_spec], [1], + [Compiler flag to generate shared objects directly from archives]) +_LT_TAGDECL([], [compiler_needs_object], [1], + [Whether the compiler copes with passing no objects directly]) +_LT_TAGDECL([], [old_archive_from_new_cmds], [2], + [Create an old-style archive from a shared archive]) +_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], + [Create a temporary old-style archive to link instead of a shared archive]) +_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) +_LT_TAGDECL([], [archive_expsym_cmds], [2]) +_LT_TAGDECL([], [module_cmds], [2], + [Commands used to build a loadable module if different from building + a shared archive.]) +_LT_TAGDECL([], [module_expsym_cmds], [2]) +_LT_TAGDECL([], [with_gnu_ld], [1], + [Whether we are building with GNU ld or not]) +_LT_TAGDECL([], [allow_undefined_flag], [1], + [Flag that allows shared libraries with undefined symbols to be built]) +_LT_TAGDECL([], [no_undefined_flag], [1], + [Flag that enforces no undefined symbols]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], + [Flag to hardcode $libdir into a binary during linking. + This must work even if $libdir does not exist]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1], + [[If ld is used when linking, flag to hardcode $libdir into a binary + during linking. This must work even if $libdir does not exist]]) +_LT_TAGDECL([], [hardcode_libdir_separator], [1], + [Whether we need a single "-rpath" flag with a separated argument]) +_LT_TAGDECL([], [hardcode_direct], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary]) +_LT_TAGDECL([], [hardcode_direct_absolute], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary and the resulting library dependency is + "absolute", i.e impossible to change by setting ${shlibpath_var} if the + library is relocated]) +_LT_TAGDECL([], [hardcode_minus_L], [0], + [Set to "yes" if using the -LDIR flag during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_shlibpath_var], [0], + [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_automatic], [0], + [Set to "yes" if building a shared library automatically hardcodes DIR + into the library and all subsequent libraries and executables linked + against it]) +_LT_TAGDECL([], [inherit_rpath], [0], + [Set to yes if linker adds runtime paths of dependent libraries + to runtime path list]) +_LT_TAGDECL([], [link_all_deplibs], [0], + [Whether libtool must link a program against all its dependency libraries]) +_LT_TAGDECL([], [fix_srcfile_path], [1], + [Fix the shell variable $srcfile for the compiler]) +_LT_TAGDECL([], [always_export_symbols], [0], + [Set to "yes" if exported symbols are required]) +_LT_TAGDECL([], [export_symbols_cmds], [2], + [The commands to list exported symbols]) +_LT_TAGDECL([], [exclude_expsyms], [1], + [Symbols that should not be listed in the preloaded symbols]) +_LT_TAGDECL([], [include_expsyms], [1], + [Symbols that must always be exported]) +_LT_TAGDECL([], [prelink_cmds], [2], + [Commands necessary for linking programs (against libraries) with templates]) +_LT_TAGDECL([], [file_list_spec], [1], + [Specify filename containing input files]) +dnl FIXME: Not yet implemented +dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], +dnl [Compiler flag to generate thread safe objects]) +])# _LT_LINKER_SHLIBS + + +# _LT_LANG_C_CONFIG([TAG]) +# ------------------------ +# Ensure that the configuration variables for a C compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_C_CONFIG], +[m4_require([_LT_DECL_EGREP])dnl +lt_save_CC="$CC" +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + +_LT_TAG_COMPILER +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + LT_SYS_DLOPEN_SELF + _LT_CMD_STRIPLIB + + # Report which library types will actually be built + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_CONFIG($1) +fi +AC_LANG_POP +CC="$lt_save_CC" +])# _LT_LANG_C_CONFIG + + +# _LT_PROG_CXX +# ------------ +# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++ +# compiler, we have our own version here. +m4_defun([_LT_PROG_CXX], +[ +pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes]) +AC_PROG_CXX +if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_PROG_CXXCPP +else + _lt_caught_CXX_error=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_CXX + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_CXX], []) + + +# _LT_LANG_CXX_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a C++ compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_CXX_CONFIG], +[AC_REQUIRE([_LT_PROG_CXX])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_LANG_PUSH(C++) +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(compiler_needs_object, $1)=no +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_caught_CXX_error" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + else + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + fi + + if test "$GXX" = yes; then + # Set up default GNU C++ configuration + + LT_PATH_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test "$with_gnu_ld" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='${wl}' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) + _LT_TAGVAR(ld_shlibs, $1)=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GXX" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty + # executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared + # libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + freebsd[[12]]*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + freebsd-elf*) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + gnu*) + ;; + + hpux9*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test $with_gnu_ld = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + if test $with_gnu_ld = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test "$GXX" = yes; then + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib' + fi + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*) + _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"' + _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~ + $RANLIB $oldlib' + _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + *) # Version 6 will use weak symbols + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + xl*) + # IBM XL 8.0 on PPC, with GNU ld + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + openbsd2*) + # C++ shared libraries are fairly broken + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + fi + output_verbose_link_cmd=echo + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + case $host in + osf3*) + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + ;; + *) + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~ + $RM $lib.exp' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + case $host in + osf3*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + else + # g++ 2.7 appears to require `-G' NOT `-shared' on this + # platform. + _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + fi + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) + test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + + _LT_TAGVAR(GCC, $1)="$GXX" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + CC=$lt_save_CC + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test "$_lt_caught_CXX_error" != yes + +AC_LANG_POP +])# _LT_LANG_CXX_CONFIG + + +# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) +# --------------------------------- +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +m4_defun([_LT_SYS_HIDDEN_LIBDEPS], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +# Dependencies to place before and after the object being linked: +_LT_TAGVAR(predep_objects, $1)= +_LT_TAGVAR(postdep_objects, $1)= +_LT_TAGVAR(predeps, $1)= +_LT_TAGVAR(postdeps, $1)= +_LT_TAGVAR(compiler_lib_search_path, $1)= + +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF +int a; +void foo (void) { a = 0; } +_LT_EOF +], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF +], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer*4 a + a=0 + return + end +_LT_EOF +], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer a + a=0 + return + end +_LT_EOF +], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF +public class foo { + private int a; + public void bar (void) { + a = 0; + } +}; +_LT_EOF +]) +dnl Parse the compiler output and extract the necessary +dnl objects, libraries and library flags. +if AC_TRY_EVAL(ac_compile); then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test $p = "-L" || + test $p = "-R"; then + prev=$p + continue + else + prev= + fi + + if test "$pre_test_object_deps_done" = no; then + case $p in + -L* | -R*) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then + _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}" + else + _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$_LT_TAGVAR(postdeps, $1)"; then + _LT_TAGVAR(postdeps, $1)="${prev}${p}" + else + _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}" + fi + fi + ;; + + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test "$pre_test_object_deps_done" = no; then + if test -z "$_LT_TAGVAR(predep_objects, $1)"; then + _LT_TAGVAR(predep_objects, $1)="$p" + else + _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" + fi + else + if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then + _LT_TAGVAR(postdep_objects, $1)="$p" + else + _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling $1 test program" +fi + +$RM -f confest.$objext + +# PORTME: override above test on systems where it is broken +m4_if([$1], [CXX], +[case $host_os in +interix[[3-9]]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + _LT_TAGVAR(predep_objects,$1)= + _LT_TAGVAR(postdep_objects,$1)= + _LT_TAGVAR(postdeps,$1)= + ;; + +linux*) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; + +solaris*) + case $cc_basename in + CC*) + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + # Adding this requires a known-good setup of shared libraries for + # Sun compiler versions before 5.6, else PIC objects from an old + # archive will be linked into the output, leading to subtle bugs. + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; +esac +]) + +case " $_LT_TAGVAR(postdeps, $1) " in +*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; +esac + _LT_TAGVAR(compiler_lib_search_dirs, $1)= +if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then + _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'` +fi +_LT_TAGDECL([], [compiler_lib_search_dirs], [1], + [The directories searched by this compiler when creating a shared library]) +_LT_TAGDECL([], [predep_objects], [1], + [Dependencies to place before and after the objects being linked to + create a shared library]) +_LT_TAGDECL([], [postdep_objects], [1]) +_LT_TAGDECL([], [predeps], [1]) +_LT_TAGDECL([], [postdeps], [1]) +_LT_TAGDECL([], [compiler_lib_search_path], [1], + [The library search path used internally by the compiler when linking + a shared library]) +])# _LT_SYS_HIDDEN_LIBDEPS + + +# _LT_PROG_F77 +# ------------ +# Since AC_PROG_F77 is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_F77], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes]) +AC_PROG_F77 +if test -z "$F77" || test "X$F77" = "Xno"; then + _lt_disable_F77=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_F77 + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_F77], []) + + +# _LT_LANG_F77_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a Fortran 77 compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_F77_CONFIG], +[AC_REQUIRE([_LT_PROG_F77])dnl +AC_LANG_PUSH(Fortran 77) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the F77 compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_F77" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${F77-"f77"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + GCC=$G77 + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$G77" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_F77" != yes + +AC_LANG_POP +])# _LT_LANG_F77_CONFIG + + +# _LT_PROG_FC +# ----------- +# Since AC_PROG_FC is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_FC], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes]) +AC_PROG_FC +if test -z "$FC" || test "X$FC" = "Xno"; then + _lt_disable_FC=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_FC + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_FC], []) + + +# _LT_LANG_FC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for a Fortran compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_FC_CONFIG], +[AC_REQUIRE([_LT_PROG_FC])dnl +AC_LANG_PUSH(Fortran) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for fc test sources. +ac_ext=${ac_fc_srcext-f} + +# Object file extension for compiled fc test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the FC compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_FC" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${FC-"f95"} + compiler=$CC + GCC=$ac_cv_fc_compiler_gnu + + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_FC" != yes + +AC_LANG_POP +])# _LT_LANG_FC_CONFIG + + +# _LT_LANG_GCJ_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Java Compiler compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_GCJ_CONFIG], +[AC_REQUIRE([LT_PROG_GCJ])dnl +AC_LANG_SAVE + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC=yes +CC=${GCJ-"gcj"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)="$LD" +_LT_CC_BASENAME([$compiler]) + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds + +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC="$lt_save_CC" +])# _LT_LANG_GCJ_CONFIG + + +# _LT_LANG_RC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for the Windows resource compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_RC_CONFIG], +[AC_REQUIRE([LT_PROG_RC])dnl +AC_LANG_SAVE + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' + +# Code to be used in simple link tests +lt_simple_link_test_code="$lt_simple_compile_test_code" + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC= +CC=${RC-"windres"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) +_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + +if test -n "$compiler"; then + : + _LT_CONFIG($1) +fi + +GCC=$lt_save_GCC +AC_LANG_RESTORE +CC="$lt_save_CC" +])# _LT_LANG_RC_CONFIG + + +# LT_PROG_GCJ +# ----------- +AC_DEFUN([LT_PROG_GCJ], +[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_GCJ], []) + + +# LT_PROG_RC +# ---------- +AC_DEFUN([LT_PROG_RC], +[AC_CHECK_TOOL(RC, windres,) +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_RC], []) + + +# _LT_DECL_EGREP +# -------------- +# If we don't have a new enough Autoconf to choose the best grep +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_EGREP], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_REQUIRE([AC_PROG_FGREP])dnl +test -z "$GREP" && GREP=grep +_LT_DECL([], [GREP], [1], [A grep program that handles long lines]) +_LT_DECL([], [EGREP], [1], [An ERE matcher]) +_LT_DECL([], [FGREP], [1], [A literal string matcher]) +dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too +AC_SUBST([GREP]) +]) + + +# _LT_DECL_OBJDUMP +# -------------- +# If we don't have a new enough Autoconf to choose the best objdump +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_OBJDUMP], +[AC_CHECK_TOOL(OBJDUMP, objdump, false) +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) +AC_SUBST([OBJDUMP]) +]) + + +# _LT_DECL_SED +# ------------ +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +m4_defun([_LT_DECL_SED], +[AC_PROG_SED +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" +_LT_DECL([], [SED], [1], [A sed program that does not truncate output]) +_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], + [Sed that helps us avoid accidentally triggering echo(1) options like -n]) +])# _LT_DECL_SED + +m4_ifndef([AC_PROG_SED], [ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # + +m4_defun([AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f $lt_ac_sed && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test $lt_ac_count -gt 10 && break + lt_ac_count=`expr $lt_ac_count + 1` + if test $lt_ac_count -gt $lt_ac_max; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +])#AC_PROG_SED +])#m4_ifndef + +# Old name: +AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_SED], []) + + +# _LT_CHECK_SHELL_FEATURES +# ------------------------ +# Find out whether the shell is Bourne or XSI compatible, +# or has some other useful features. +m4_defun([_LT_CHECK_SHELL_FEATURES], +[AC_MSG_CHECKING([whether the shell understands some XSI constructs]) +# Try some XSI features +xsi_shell=no +( _lt_dummy="a/b/c" + test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \ + = c,a/b,, \ + && eval 'test $(( 1 + 1 )) -eq 2 \ + && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ + && xsi_shell=yes +AC_MSG_RESULT([$xsi_shell]) +_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell']) + +AC_MSG_CHECKING([whether the shell understands "+="]) +lt_shell_append=no +( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \ + >/dev/null 2>&1 \ + && lt_shell_append=yes +AC_MSG_RESULT([$lt_shell_append]) +_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append']) + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi +_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac +_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl +_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl +])# _LT_CHECK_SHELL_FEATURES + + +# _LT_PROG_XSI_SHELLFNS +# --------------------- +# Bourne and XSI compatible variants of some useful shell functions. +m4_defun([_LT_PROG_XSI_SHELLFNS], +[case $xsi_shell in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac +} + +# func_basename file +func_basename () +{ + func_basename_result="${1##*/}" +} + +# func_dirname_and_basename file append nondir_replacement +# perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# Implementation must be kept synchronized with func_dirname +# and func_basename. For efficiency, we do not delegate to +# those functions but instead duplicate the functionality here. +func_dirname_and_basename () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac + func_basename_result="${1##*/}" +} + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +func_stripname () +{ + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary parameter first. + func_stripname_result=${3} + func_stripname_result=${func_stripname_result#"${1}"} + func_stripname_result=${func_stripname_result%"${2}"} +} + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=${1%%=*} + func_opt_split_arg=${1#*=} +} + +# func_lo2o object +func_lo2o () +{ + case ${1} in + *.lo) func_lo2o_result=${1%.lo}.${objext} ;; + *) func_lo2o_result=${1} ;; + esac +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=${1%.*}.lo +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=$(( $[*] )) +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=${#1} +} + +_LT_EOF + ;; + *) # Bourne compatible functions. + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + # Extract subdirectory from the argument. + func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` + if test "X$func_dirname_result" = "X${1}"; then + func_dirname_result="${3}" + else + func_dirname_result="$func_dirname_result${2}" + fi +} + +# func_basename file +func_basename () +{ + func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` +} + +dnl func_dirname_and_basename +dnl A portable version of this function is already defined in general.m4sh +dnl so there is no need for it here. + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# func_strip_suffix prefix name +func_stripname () +{ + case ${2} in + .*) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;; + *) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;; + esac +} + +# sed scripts: +my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q' +my_sed_long_arg='1s/^-[[^=]]*=//' + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"` + func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"` +} + +# func_lo2o object +func_lo2o () +{ + func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"` +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'` +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=`expr "$[@]"` +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len` +} + +_LT_EOF +esac + +case $lt_shell_append in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]+=\$[2]" +} +_LT_EOF + ;; + *) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]=\$$[1]\$[2]" +} + +_LT_EOF + ;; + esac +]) + +# Helper functions for option handling. -*- Autoconf -*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltoptions.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) + + +# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) +# ------------------------------------------ +m4_define([_LT_MANGLE_OPTION], +[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) + + +# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) +# --------------------------------------- +# Set option OPTION-NAME for macro MACRO-NAME, and if there is a +# matching handler defined, dispatch to it. Other OPTION-NAMEs are +# saved as a flag. +m4_define([_LT_SET_OPTION], +[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl +m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), + _LT_MANGLE_DEFUN([$1], [$2]), + [m4_warning([Unknown $1 option `$2'])])[]dnl +]) + + +# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) +# ------------------------------------------------------------ +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +m4_define([_LT_IF_OPTION], +[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) + + +# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) +# ------------------------------------------------------- +# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME +# are set. +m4_define([_LT_UNLESS_OPTIONS], +[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), + [m4_define([$0_found])])])[]dnl +m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 +])[]dnl +]) + + +# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) +# ---------------------------------------- +# OPTION-LIST is a space-separated list of Libtool options associated +# with MACRO-NAME. If any OPTION has a matching handler declared with +# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about +# the unknown option and exit. +m4_defun([_LT_SET_OPTIONS], +[# Set options +m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [_LT_SET_OPTION([$1], _LT_Option)]) + +m4_if([$1],[LT_INIT],[ + dnl + dnl Simply set some default values (i.e off) if boolean options were not + dnl specified: + _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no + ]) + _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no + ]) + dnl + dnl If no reference was made to various pairs of opposing options, then + dnl we run the default mode handler for the pair. For example, if neither + dnl `shared' nor `disable-shared' was passed, we enable building of shared + dnl archives by default: + _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) + _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], + [_LT_ENABLE_FAST_INSTALL]) + ]) +])# _LT_SET_OPTIONS + + + +# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) +# ----------------------------------------- +m4_define([_LT_MANGLE_DEFUN], +[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) + + +# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) +# ----------------------------------------------- +m4_define([LT_OPTION_DEFINE], +[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl +])# LT_OPTION_DEFINE + + +# dlopen +# ------ +LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes +]) + +AU_DEFUN([AC_LIBTOOL_DLOPEN], +[_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `dlopen' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) + + +# win32-dll +# --------- +# Declare package support for building win32 dll's. +LT_OPTION_DEFINE([LT_INIT], [win32-dll], +[enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; +esac + +test -z "$AS" && AS=as +_LT_DECL([], [AS], [0], [Assembler program])dnl + +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl + +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl +])# win32-dll + +AU_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `win32-dll' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) + + +# _LT_ENABLE_SHARED([DEFAULT]) +# ---------------------------- +# implement the --enable-shared flag, and supports the `shared' and +# `disable-shared' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_SHARED], +[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) + + _LT_DECL([build_libtool_libs], [enable_shared], [0], + [Whether or not to build shared libraries]) +])# _LT_ENABLE_SHARED + +LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) + +AC_DEFUN([AC_DISABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) + +AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_SHARED], []) +dnl AC_DEFUN([AM_DISABLE_SHARED], []) + + + +# _LT_ENABLE_STATIC([DEFAULT]) +# ---------------------------- +# implement the --enable-static flag, and support the `static' and +# `disable-static' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_STATIC], +[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_static=]_LT_ENABLE_STATIC_DEFAULT) + + _LT_DECL([build_old_libs], [enable_static], [0], + [Whether or not to build static libraries]) +])# _LT_ENABLE_STATIC + +LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) + +AC_DEFUN([AC_DISABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], [disable-static]) +]) + +AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_STATIC], []) +dnl AC_DEFUN([AM_DISABLE_STATIC], []) + + + +# _LT_ENABLE_FAST_INSTALL([DEFAULT]) +# ---------------------------------- +# implement the --enable-fast-install flag, and support the `fast-install' +# and `disable-fast-install' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_FAST_INSTALL], +[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([fast-install], + [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) + +_LT_DECL([fast_install], [enable_fast_install], [0], + [Whether or not to optimize for fast installation])dnl +])# _LT_ENABLE_FAST_INSTALL + +LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) + +# Old names: +AU_DEFUN([AC_ENABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `fast-install' option into LT_INIT's first parameter.]) +]) + +AU_DEFUN([AC_DISABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `disable-fast-install' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) +dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) + + +# _LT_WITH_PIC([MODE]) +# -------------------- +# implement the --with-pic flag, and support the `pic-only' and `no-pic' +# LT_INIT options. +# MODE is either `yes' or `no'. If omitted, it defaults to `both'. +m4_define([_LT_WITH_PIC], +[AC_ARG_WITH([pic], + [AS_HELP_STRING([--with-pic], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [pic_mode="$withval"], + [pic_mode=default]) + +test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) + +_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl +])# _LT_WITH_PIC + +LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) + +# Old name: +AU_DEFUN([AC_LIBTOOL_PICMODE], +[_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `pic-only' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) + + +m4_define([_LTDL_MODE], []) +LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], + [m4_define([_LTDL_MODE], [nonrecursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [recursive], + [m4_define([_LTDL_MODE], [recursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [subproject], + [m4_define([_LTDL_MODE], [subproject])]) + +m4_define([_LTDL_TYPE], []) +LT_OPTION_DEFINE([LTDL_INIT], [installable], + [m4_define([_LTDL_TYPE], [installable])]) +LT_OPTION_DEFINE([LTDL_INIT], [convenience], + [m4_define([_LTDL_TYPE], [convenience])]) + +# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltsugar.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) + + +# lt_join(SEP, ARG1, [ARG2...]) +# ----------------------------- +# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their +# associated separator. +# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier +# versions in m4sugar had bugs. +m4_define([lt_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) +m4_define([_lt_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) + + +# lt_car(LIST) +# lt_cdr(LIST) +# ------------ +# Manipulate m4 lists. +# These macros are necessary as long as will still need to support +# Autoconf-2.59 which quotes differently. +m4_define([lt_car], [[$1]]) +m4_define([lt_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) +m4_define([lt_unquote], $1) + + +# lt_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. +# Note that neither SEPARATOR nor STRING are expanded; they are appended +# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). +# No SEPARATOR is output if MACRO-NAME was previously undefined (different +# than defined and empty). +# +# This macro is needed until we can rely on Autoconf 2.62, since earlier +# versions of m4sugar mistakenly expanded SEPARATOR but not STRING. +m4_define([lt_append], +[m4_define([$1], + m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) + + + +# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) +# ---------------------------------------------------------- +# Produce a SEP delimited list of all paired combinations of elements of +# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list +# has the form PREFIXmINFIXSUFFIXn. +# Needed until we can rely on m4_combine added in Autoconf 2.62. +m4_define([lt_combine], +[m4_if(m4_eval([$# > 3]), [1], + [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl +[[m4_foreach([_Lt_prefix], [$2], + [m4_foreach([_Lt_suffix], + ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, + [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) + + +# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) +# ----------------------------------------------------------------------- +# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited +# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. +m4_define([lt_if_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], + [lt_append([$1], [$2], [$3])$4], + [$5])], + [lt_append([$1], [$2], [$3])$4])]) + + +# lt_dict_add(DICT, KEY, VALUE) +# ----------------------------- +m4_define([lt_dict_add], +[m4_define([$1($2)], [$3])]) + + +# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) +# -------------------------------------------- +m4_define([lt_dict_add_subkey], +[m4_define([$1($2:$3)], [$4])]) + + +# lt_dict_fetch(DICT, KEY, [SUBKEY]) +# ---------------------------------- +m4_define([lt_dict_fetch], +[m4_ifval([$3], + m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), + m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) + + +# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------------------- +m4_define([lt_if_dict_fetch], +[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], + [$5], + [$6])]) + + +# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) +# -------------------------------------------------------------- +m4_define([lt_dict_filter], +[m4_if([$5], [], [], + [lt_join(m4_quote(m4_default([$4], [[, ]])), + lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), + [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl +]) + +# ltversion.m4 -- version numbers -*- Autoconf -*- +# +# Copyright (C) 2004 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# Generated from ltversion.in. + +# serial 3017 ltversion.m4 +# This file is part of GNU Libtool + +m4_define([LT_PACKAGE_VERSION], [2.2.6b]) +m4_define([LT_PACKAGE_REVISION], [1.3017]) + +AC_DEFUN([LTVERSION_VERSION], +[macro_version='2.2.6b' +macro_revision='1.3017' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) + +# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004. +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 4 lt~obsolete.m4 + +# These exist entirely to fool aclocal when bootstrapping libtool. +# +# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) +# which have later been changed to m4_define as they aren't part of the +# exported API, or moved to Autoconf or Automake where they belong. +# +# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN +# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us +# using a macro with the same name in our local m4/libtool.m4 it'll +# pull the old libtool.m4 in (it doesn't see our shiny new m4_define +# and doesn't know about Autoconf macros at all.) +# +# So we provide this file, which has a silly filename so it's always +# included after everything else. This provides aclocal with the +# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything +# because those macros already exist, or will be overwritten later. +# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. +# +# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. +# Yes, that means every name once taken will need to remain here until +# we give up compatibility with versions before 1.7, at which point +# we need to keep only those names which we still refer to. + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) + +m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) +m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) +m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) +m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) +m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) +m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) +m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) +m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) +m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) +m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) +m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) +m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) +m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) +m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) +m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) +m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) +m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) +m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) +m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) +m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) +m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) +m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) +m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) +m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) +m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) +m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) +m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) +m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) +m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) +m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) +m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) +m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) +m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) +m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) +m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) +m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) +m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])]) +m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) +m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) +m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) +m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) +m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) +m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) +m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) +m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) + +# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_AUTOMAKE_VERSION(VERSION) +# ---------------------------- +# Automake X.Y traces this macro to ensure aclocal.m4 has been +# generated from the m4 files accompanying Automake X.Y. +# (This private macro should not be called outside this file.) +AC_DEFUN([AM_AUTOMAKE_VERSION], +[am__api_version='1.11' +dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to +dnl require some minimum version. Point them to the right macro. +m4_if([$1], [1.11.1], [], + [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl +]) + +# _AM_AUTOCONF_VERSION(VERSION) +# ----------------------------- +# aclocal traces this macro to find the Autoconf version. +# This is a private macro too. Using m4_define simplifies +# the logic in aclocal, which can simply ignore this definition. +m4_define([_AM_AUTOCONF_VERSION], []) + +# AM_SET_CURRENT_AUTOMAKE_VERSION +# ------------------------------- +# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. +# This function is AC_REQUIREd by AM_INIT_AUTOMAKE. +AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], +[AM_AUTOMAKE_VERSION([1.11.1])dnl +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) + +# AM_AUX_DIR_EXPAND -*- Autoconf -*- + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets +# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to +# `$srcdir', `$srcdir/..', or `$srcdir/../..'. +# +# Of course, Automake must honor this variable whenever it calls a +# tool from the auxiliary directory. The problem is that $srcdir (and +# therefore $ac_aux_dir as well) can be either absolute or relative, +# depending on how configure is run. This is pretty annoying, since +# it makes $ac_aux_dir quite unusable in subdirectories: in the top +# source directory, any form will work fine, but in subdirectories a +# relative path needs to be adjusted first. +# +# $ac_aux_dir/missing +# fails when called from a subdirectory if $ac_aux_dir is relative +# $top_srcdir/$ac_aux_dir/missing +# fails if $ac_aux_dir is absolute, +# fails when called from a subdirectory in a VPATH build with +# a relative $ac_aux_dir +# +# The reason of the latter failure is that $top_srcdir and $ac_aux_dir +# are both prefixed by $srcdir. In an in-source build this is usually +# harmless because $srcdir is `.', but things will broke when you +# start a VPATH build or use an absolute $srcdir. +# +# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, +# iff we strip the leading $srcdir from $ac_aux_dir. That would be: +# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` +# and then we would define $MISSING as +# MISSING="\${SHELL} $am_aux_dir/missing" +# This will work as long as MISSING is not called from configure, because +# unfortunately $(top_srcdir) has no meaning in configure. +# However there are other variables, like CC, which are often used in +# configure, and could therefore not use this "fixed" $ac_aux_dir. +# +# Another solution, used here, is to always expand $ac_aux_dir to an +# absolute PATH. The drawback is that using absolute paths prevent a +# configured tree to be moved without reconfiguration. + +AC_DEFUN([AM_AUX_DIR_EXPAND], +[dnl Rely on autoconf to set up CDPATH properly. +AC_PREREQ([2.50])dnl +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` +]) + +# AM_CONDITIONAL -*- Autoconf -*- + +# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 9 + +# AM_CONDITIONAL(NAME, SHELL-CONDITION) +# ------------------------------------- +# Define a conditional. +AC_DEFUN([AM_CONDITIONAL], +[AC_PREREQ(2.52)dnl + ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE])dnl +AC_SUBST([$1_FALSE])dnl +_AM_SUBST_NOTMAKE([$1_TRUE])dnl +_AM_SUBST_NOTMAKE([$1_FALSE])dnl +m4_define([_AM_COND_VALUE_$1], [$2])dnl +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 10 + +# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be +# written in clear, in which case automake, when reading aclocal.m4, +# will think it sees a *use*, and therefore will trigger all it's +# C support machinery. Also note that it means that autoscan, seeing +# CC etc. in the Makefile, will ask for an AC_PROG_CC use... + + +# _AM_DEPENDENCIES(NAME) +# ---------------------- +# See how the compiler implements dependency checking. +# NAME is "CC", "CXX", "GCJ", or "OBJC". +# We try a few techniques and use that to set a single cache variable. +# +# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was +# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular +# dependency, and given that the user is not expected to run this macro, +# just rely on AC_PROG_CC. +AC_DEFUN([_AM_DEPENDENCIES], +[AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +ifelse([$1], CC, [depcc="$CC" am_compiler_list=], + [$1], CXX, [depcc="$CXX" am_compiler_list=], + [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], UPC, [depcc="$UPC" am_compiler_list=], + [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + am__universal=false + m4_case([$1], [CC], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac], + [CXX], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac]) + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvisualcpp | msvcmsys) + # This compiler won't grok `-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) + + +# AM_SET_DEPDIR +# ------------- +# Choose a directory name for dependency files. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES +AC_DEFUN([AM_SET_DEPDIR], +[AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) + + +# AM_DEP_TRACK +# ------------ +AC_DEFUN([AM_DEP_TRACK], +[AC_ARG_ENABLE(dependency-tracking, +[ --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH])dnl +_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl +]) + +# Generate code to set up dependency tracking. -*- Autoconf -*- + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +#serial 5 + +# _AM_OUTPUT_DEPENDENCY_COMMANDS +# ------------------------------ +AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], +[{ + # Autoconf 2.62 quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named `Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running `make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} +])# _AM_OUTPUT_DEPENDENCY_COMMANDS + + +# AM_OUTPUT_DEPENDENCY_COMMANDS +# ----------------------------- +# This macro should only be invoked once -- use via AC_REQUIRE. +# +# This code is only required when automatic dependency tracking +# is enabled. FIXME. This creates each `.P' file that we will +# need in order to bootstrap the dependency handling code. +AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], +[AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) + +# Do all the work for Automake. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2008, 2009 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 16 + +# This macro actually does too much. Some checks are only needed if +# your package does certain things. But this isn't really a big deal. + +# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) +# AM_INIT_AUTOMAKE([OPTIONS]) +# ----------------------------------------------- +# The call with PACKAGE and VERSION arguments is the old style +# call (pre autoconf-2.50), which is being phased out. PACKAGE +# and VERSION should now be passed to AC_INIT and removed from +# the call to AM_INIT_AUTOMAKE. +# We support both call styles for the transition. After +# the next Automake release, Autoconf can make the AC_INIT +# arguments mandatory, and then we can depend on a new Autoconf +# release and drop the old call support. +AC_DEFUN([AM_INIT_AUTOMAKE], +[AC_PREREQ([2.62])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl +dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. +m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, + [m4_fatal([AC_INIT should be called with package and version arguments])])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) + AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) +AM_MISSING_PROG(AUTOCONF, autoconf) +AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) +AM_MISSING_PROG(AUTOHEADER, autoheader) +AM_MISSING_PROG(MAKEINFO, makeinfo) +AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl +AC_REQUIRE([AM_PROG_MKDIR_P])dnl +# We need awk for the "check" target. The system "awk" is bad on +# some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES(CC)], + [define([AC_PROG_CC], + defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES(CXX)], + [define([AC_PROG_CXX], + defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJC], + [_AM_DEPENDENCIES(OBJC)], + [define([AC_PROG_OBJC], + defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl +]) +_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl +dnl The `parallel-tests' driver may need to know about EXEEXT, so add the +dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro +dnl is hooked onto _AC_COMPILER_EXEEXT early, see below. +AC_CONFIG_COMMANDS_PRE(dnl +[m4_provide_if([_AM_COMPILER_EXEEXT], + [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl +]) + +dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not +dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further +dnl mangled by Autoconf and run in a shell conditional statement. +m4_define([_AC_COMPILER_EXEEXT], +m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) + + +# When config.status generates a header, we must update the stamp-h file. +# This file resides in the same directory as the config header +# that is generated. The stamp files are numbered to have different names. + +# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the +# loop where config.status creates the headers, so we can generate +# our stamp files there. +AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], +[# Compute $1's index in $config_headers. +_am_arg=$1 +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) + +# Copyright (C) 2001, 2003, 2005, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_SH +# ------------------ +# Define $install_sh. +AC_DEFUN([AM_PROG_INSTALL_SH], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +if test x"${install_sh}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi +AC_SUBST(install_sh)]) + +# Copyright (C) 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# Check whether the underlying file-system supports filenames +# with a leading dot. For instance MS-DOS doesn't. +AC_DEFUN([AM_SET_LEADING_DOT], +[rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) + +# Add --enable-maintainer-mode option to configure. -*- Autoconf -*- +# From Jim Meyering + +# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 5 + +# AM_MAINTAINER_MODE([DEFAULT-MODE]) +# ---------------------------------- +# Control maintainer-specific portions of Makefiles. +# Default is to disable them, unless `enable' is passed literally. +# For symmetry, `disable' may be passed as well. Anyway, the user +# can override the default with the --enable/--disable switch. +AC_DEFUN([AM_MAINTAINER_MODE], +[m4_case(m4_default([$1], [disable]), + [enable], [m4_define([am_maintainer_other], [disable])], + [disable], [m4_define([am_maintainer_other], [enable])], + [m4_define([am_maintainer_other], [enable]) + m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) +AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles]) + dnl maintainer-mode's default is 'disable' unless 'enable' is passed + AC_ARG_ENABLE([maintainer-mode], +[ --][am_maintainer_other][-maintainer-mode am_maintainer_other make rules and dependencies not useful + (and sometimes confusing) to the casual installer], + [USE_MAINTAINER_MODE=$enableval], + [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) + AC_MSG_RESULT([$USE_MAINTAINER_MODE]) + AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) + MAINT=$MAINTAINER_MODE_TRUE + AC_SUBST([MAINT])dnl +] +) + +AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE]) + +# Check to see how 'make' treats includes. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# AM_MAKE_INCLUDE() +# ----------------- +# Check to see how make treats includes. +AC_DEFUN([AM_MAKE_INCLUDE], +[am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from `make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) + +# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- + +# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 6 + +# AM_MISSING_PROG(NAME, PROGRAM) +# ------------------------------ +AC_DEFUN([AM_MISSING_PROG], +[AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) + + +# AM_MISSING_HAS_RUN +# ------------------ +# Define MISSING if not defined so far and test if it supports --run. +# If it does, set am_missing_run to use it, otherwise, to nothing. +AC_DEFUN([AM_MISSING_HAS_RUN], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([missing])dnl +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --run true"; then + am_missing_run="$MISSING --run " +else + am_missing_run= + AC_MSG_WARN([`missing' script is too old or missing]) +fi +]) + +# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_MKDIR_P +# --------------- +# Check for `mkdir -p'. +AC_DEFUN([AM_PROG_MKDIR_P], +[AC_PREREQ([2.60])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, +dnl while keeping a definition of mkdir_p for backward compatibility. +dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. +dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of +dnl Makefile.ins that do not define MKDIR_P, so we do our own +dnl adjustment using top_builddir (which is defined more often than +dnl MKDIR_P). +AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl +case $mkdir_p in + [[\\/$]]* | ?:[[\\/]]*) ;; + */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; +esac +]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# _AM_MANGLE_OPTION(NAME) +# ----------------------- +AC_DEFUN([_AM_MANGLE_OPTION], +[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) + +# _AM_SET_OPTION(NAME) +# ------------------------------ +# Set option NAME. Presently that only means defining a flag for this option. +AC_DEFUN([_AM_SET_OPTION], +[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) + +# _AM_SET_OPTIONS(OPTIONS) +# ---------------------------------- +# OPTIONS is a space-separated list of Automake options. +AC_DEFUN([_AM_SET_OPTIONS], +[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) + +# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) +# ------------------------------------------- +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +AC_DEFUN([_AM_IF_OPTION], +[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) + +# Check to make sure that the build environment is sane. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 5 + +# AM_SANITY_CHECK +# --------------- +AC_DEFUN([AM_SANITY_CHECK], +[AC_MSG_CHECKING([whether build environment is sane]) +# Just in case +sleep 1 +echo timestamp > conftest.file +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[[\\\"\#\$\&\'\`$am_lf]]*) + AC_MSG_ERROR([unsafe absolute working directory name]);; +esac +case $srcdir in + *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) + AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; +esac + +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + rm -f conftest.file + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken +alias in your environment]) + fi + + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT(yes)]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_STRIP +# --------------------- +# One issue with vendor `install' (even GNU) is that you can't +# specify the program used to strip binaries. This is especially +# annoying in cross-compiling environments, where the build's strip +# is unlikely to handle the host's binaries. +# Fortunately install-sh will honor a STRIPPROG variable, so we +# always use install-sh in `make install-strip', and initialize +# STRIPPROG with the value of the STRIP variable (set by the user). +AC_DEFUN([AM_PROG_INSTALL_STRIP], +[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the `STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be `maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) + +# Copyright (C) 2006, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# _AM_SUBST_NOTMAKE(VARIABLE) +# --------------------------- +# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. +# This macro is traced by Automake. +AC_DEFUN([_AM_SUBST_NOTMAKE]) + +# AM_SUBST_NOTMAKE(VARIABLE) +# --------------------------- +# Public sister of _AM_SUBST_NOTMAKE. +AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) + +# Check how to create a tarball. -*- Autoconf -*- + +# Copyright (C) 2004, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# _AM_PROG_TAR(FORMAT) +# -------------------- +# Check how to create a tarball in format FORMAT. +# FORMAT should be one of `v7', `ustar', or `pax'. +# +# Substitute a variable $(am__tar) that is a command +# writing to stdout a FORMAT-tarball containing the directory +# $tardir. +# tardir=directory && $(am__tar) > result.tar +# +# Substitute a variable $(am__untar) that extract such +# a tarball read from stdin. +# $(am__untar) < result.tar +AC_DEFUN([_AM_PROG_TAR], +[# Always define AMTAR for backward compatibility. +AM_MISSING_PROG([AMTAR], [tar]) +m4_if([$1], [v7], + [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'], + [m4_case([$1], [ustar],, [pax],, + [m4_fatal([Unknown tar format])]) +AC_MSG_CHECKING([how to create a $1 tar archive]) +# Loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' +_am_tools=${am_cv_prog_tar_$1-$_am_tools} +# Do not fold the above two line into one, because Tru64 sh and +# Solaris sh will not grok spaces in the rhs of `-'. +for _am_tool in $_am_tools +do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; + do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi +done +rm -rf conftest.dir + +AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) +AC_MSG_RESULT([$am_cv_prog_tar_$1])]) +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) # _AM_PROG_TAR + diff --git a/src/rt/libuv/ev/autogen.sh b/src/rt/libuv/src/ev/autogen.sh similarity index 100% rename from src/rt/libuv/ev/autogen.sh rename to src/rt/libuv/src/ev/autogen.sh diff --git a/src/rt/libuv/ev/config.guess b/src/rt/libuv/src/ev/config.guess similarity index 100% rename from src/rt/libuv/ev/config.guess rename to src/rt/libuv/src/ev/config.guess diff --git a/src/rt/libuv/ev/config.h.in b/src/rt/libuv/src/ev/config.h.in similarity index 100% rename from src/rt/libuv/ev/config.h.in rename to src/rt/libuv/src/ev/config.h.in diff --git a/src/rt/libuv/ev/config.sub b/src/rt/libuv/src/ev/config.sub similarity index 100% rename from src/rt/libuv/ev/config.sub rename to src/rt/libuv/src/ev/config.sub diff --git a/src/rt/libuv/src/ev/config_cygwin.h b/src/rt/libuv/src/ev/config_cygwin.h new file mode 100644 index 00000000000..1f6f6d98c81 --- /dev/null +++ b/src/rt/libuv/src/ev/config_cygwin.h @@ -0,0 +1,123 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `clock_gettime' function. */ +/* #undef HAVE_CLOCK_GETTIME */ + +/* "use syscall interface for clock_gettime" */ +/* #undef HAVE_CLOCK_SYSCALL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `epoll_ctl' function. */ +/* #undef HAVE_EPOLL_CTL */ + +/* Define to 1 if you have the `eventfd' function. */ +/* #undef HAVE_EVENTFD */ + +/* Define to 1 if you have the `inotify_init' function. */ +/* #undef HAVE_INOTIFY_INIT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `kqueue' function. */ +/* #undef HAVE_KQUEUE */ + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +/* #undef HAVE_LIBRT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `nanosleep' function. */ +/* #undef HAVE_NANOSLEEP */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `port_create' function. */ +/* #undef HAVE_PORT_CREATE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PORT_H */ + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EPOLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENTFD_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INOTIFY_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libev" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "3.9" diff --git a/src/rt/libuv/src/ev/config_darwin.h b/src/rt/libuv/src/ev/config_darwin.h new file mode 100644 index 00000000000..03e3b219ec9 --- /dev/null +++ b/src/rt/libuv/src/ev/config_darwin.h @@ -0,0 +1,122 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `clock_gettime' function. */ +/* #undef HAVE_CLOCK_GETTIME */ + +/* "use syscall interface for clock_gettime" */ +/* #undef HAVE_CLOCK_SYSCALL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `epoll_ctl' function. */ +/* #undef HAVE_EPOLL_CTL */ + +/* Define to 1 if you have the `eventfd' function. */ +/* #undef HAVE_EVENTFD */ + +/* Define to 1 if you have the `inotify_init' function. */ +/* #undef HAVE_INOTIFY_INIT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `kqueue' function. */ +#define HAVE_KQUEUE 1 + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +/* #undef HAVE_LIBRT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `nanosleep' function. */ +/* #undef HAVE_NANOSLEEP */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `port_create' function. */ +/* #undef HAVE_PORT_CREATE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PORT_H */ + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `signalfd' function. */ +/* #undef HAVE_SIGNALFD */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EPOLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENTFD_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_EVENT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INOTIFY_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SIGNALFD_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Name of package */ +#define PACKAGE "libev" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "3.9" diff --git a/src/rt/libuv/src/ev/config_freebsd.h b/src/rt/libuv/src/ev/config_freebsd.h new file mode 100644 index 00000000000..ebebd4156d2 --- /dev/null +++ b/src/rt/libuv/src/ev/config_freebsd.h @@ -0,0 +1,120 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `clock_gettime' function. */ +/* #undef HAVE_CLOCK_GETTIME */ + +/* "use syscall interface for clock_gettime" */ +/* #undef HAVE_CLOCK_SYSCALL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `epoll_ctl' function. */ +/* #undef HAVE_EPOLL_CTL */ + +/* Define to 1 if you have the `eventfd' function. */ +/* #undef HAVE_EVENTFD */ + +/* Define to 1 if you have the `inotify_init' function. */ +/* #undef HAVE_INOTIFY_INIT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `kqueue' function. */ +#define HAVE_KQUEUE 1 + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +/* #undef HAVE_LIBRT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `nanosleep' function. */ +/* #undef HAVE_NANOSLEEP */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `port_create' function. */ +/* #undef HAVE_PORT_CREATE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PORT_H */ + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EPOLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENTFD_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_EVENT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INOTIFY_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libev" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "3.9" diff --git a/src/rt/libuv/src/ev/config_linux.h b/src/rt/libuv/src/ev/config_linux.h new file mode 100644 index 00000000000..b147b591c43 --- /dev/null +++ b/src/rt/libuv/src/ev/config_linux.h @@ -0,0 +1,130 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +#include + +#define LINUX_VERSION_CODE_FOR(major, minor, patch) \ + (((major & 255) << 16) | ((minor & 255) << 8) | (patch & 255)) + +#define LINUX_VERSION_AT_LEAST(major, minor, patch) \ + (LINUX_VERSION_CODE >= LINUX_VERSION_CODE_FOR(major, minor, patch)) + +/* Define to 1 if you have the `clock_gettime' function. */ +/* #undef HAVE_CLOCK_GETTIME */ + +/* "use syscall interface for clock_gettime" */ +#define HAVE_CLOCK_SYSCALL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `epoll_ctl' function. */ +#define HAVE_EPOLL_CTL 1 + +/* Define to 1 if you have the `eventfd' function. */ +#define HAVE_EVENTFD LINUX_VERSION_AT_LEAST(2, 6, 22) + +/* Define to 1 if you have the `inotify_init' function. */ +#define HAVE_INOTIFY_INIT LINUX_VERSION_AT_LEAST(2, 6, 13) + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `kqueue' function. */ +/* #undef HAVE_KQUEUE */ + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +/* #undef HAVE_LIBRT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `nanosleep' function. */ +/* #undef HAVE_NANOSLEEP */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `port_create' function. */ +/* #undef HAVE_PORT_CREATE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PORT_H */ + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `signalfd' function. */ +#define HAVE_SIGNALFD LINUX_VERSION_AT_LEAST(2, 6, 22) + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_EPOLL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_EVENTFD_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_INOTIFY_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SIGNALFD_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Name of package */ +#define PACKAGE "libev" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "3.9" diff --git a/src/rt/libuv/src/ev/config_sunos.h b/src/rt/libuv/src/ev/config_sunos.h new file mode 100644 index 00000000000..9f8861d8a36 --- /dev/null +++ b/src/rt/libuv/src/ev/config_sunos.h @@ -0,0 +1,122 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `clock_gettime' function. */ +/* #undef HAVE_CLOCK_GETTIME */ + +/* "use syscall interface for clock_gettime" */ +/* #undef HAVE_CLOCK_SYSCALL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `epoll_ctl' function. */ +/* #undef HAVE_EPOLL_CTL */ + +/* Define to 1 if you have the `eventfd' function. */ +/* #undef HAVE_EVENTFD */ + +/* Define to 1 if you have the `inotify_init' function. */ +/* #undef HAVE_INOTIFY_INIT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `kqueue' function. */ +/* #undef HAVE_KQUEUE */ + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +/* #undef HAVE_LIBRT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `nanosleep' function. */ +/* #undef HAVE_NANOSLEEP */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `port_create' function. */ +#define HAVE_PORT_CREATE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_PORT_H 1 + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `signalfd' function. */ +/* #undef HAVE_SIGNALFD */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EPOLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENTFD_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INOTIFY_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SIGNALFD_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Name of package */ +#define PACKAGE "libev" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "3.9" diff --git a/src/rt/libuv/ev/configure b/src/rt/libuv/src/ev/configure similarity index 100% rename from src/rt/libuv/ev/configure rename to src/rt/libuv/src/ev/configure diff --git a/src/rt/libuv/ev/configure.ac b/src/rt/libuv/src/ev/configure.ac similarity index 100% rename from src/rt/libuv/ev/configure.ac rename to src/rt/libuv/src/ev/configure.ac diff --git a/src/rt/libuv/ev/depcomp b/src/rt/libuv/src/ev/depcomp similarity index 100% rename from src/rt/libuv/ev/depcomp rename to src/rt/libuv/src/ev/depcomp diff --git a/src/rt/libuv/ev/ev++.h b/src/rt/libuv/src/ev/ev++.h similarity index 100% rename from src/rt/libuv/ev/ev++.h rename to src/rt/libuv/src/ev/ev++.h diff --git a/src/rt/libuv/ev/ev.3 b/src/rt/libuv/src/ev/ev.3 similarity index 100% rename from src/rt/libuv/ev/ev.3 rename to src/rt/libuv/src/ev/ev.3 diff --git a/src/rt/libuv/ev/ev.c b/src/rt/libuv/src/ev/ev.c similarity index 100% rename from src/rt/libuv/ev/ev.c rename to src/rt/libuv/src/ev/ev.c diff --git a/src/rt/libuv/ev/ev.pod b/src/rt/libuv/src/ev/ev.pod similarity index 100% rename from src/rt/libuv/ev/ev.pod rename to src/rt/libuv/src/ev/ev.pod diff --git a/src/rt/libuv/ev/ev_epoll.c b/src/rt/libuv/src/ev/ev_epoll.c similarity index 100% rename from src/rt/libuv/ev/ev_epoll.c rename to src/rt/libuv/src/ev/ev_epoll.c diff --git a/src/rt/libuv/ev/ev_kqueue.c b/src/rt/libuv/src/ev/ev_kqueue.c similarity index 100% rename from src/rt/libuv/ev/ev_kqueue.c rename to src/rt/libuv/src/ev/ev_kqueue.c diff --git a/src/rt/libuv/ev/ev_poll.c b/src/rt/libuv/src/ev/ev_poll.c similarity index 100% rename from src/rt/libuv/ev/ev_poll.c rename to src/rt/libuv/src/ev/ev_poll.c diff --git a/src/rt/libuv/ev/ev_port.c b/src/rt/libuv/src/ev/ev_port.c similarity index 100% rename from src/rt/libuv/ev/ev_port.c rename to src/rt/libuv/src/ev/ev_port.c diff --git a/src/rt/libuv/ev/ev_select.c b/src/rt/libuv/src/ev/ev_select.c similarity index 100% rename from src/rt/libuv/ev/ev_select.c rename to src/rt/libuv/src/ev/ev_select.c diff --git a/src/rt/libuv/ev/ev_vars.h b/src/rt/libuv/src/ev/ev_vars.h similarity index 100% rename from src/rt/libuv/ev/ev_vars.h rename to src/rt/libuv/src/ev/ev_vars.h diff --git a/src/rt/libuv/ev/ev_win32.c b/src/rt/libuv/src/ev/ev_win32.c similarity index 100% rename from src/rt/libuv/ev/ev_win32.c rename to src/rt/libuv/src/ev/ev_win32.c diff --git a/src/rt/libuv/ev/ev_wrap.h b/src/rt/libuv/src/ev/ev_wrap.h similarity index 100% rename from src/rt/libuv/ev/ev_wrap.h rename to src/rt/libuv/src/ev/ev_wrap.h diff --git a/src/rt/libuv/ev/event.c b/src/rt/libuv/src/ev/event.c similarity index 100% rename from src/rt/libuv/ev/event.c rename to src/rt/libuv/src/ev/event.c diff --git a/src/rt/libuv/ev/event.h b/src/rt/libuv/src/ev/event.h similarity index 100% rename from src/rt/libuv/ev/event.h rename to src/rt/libuv/src/ev/event.h diff --git a/src/rt/libuv/ev/install-sh b/src/rt/libuv/src/ev/install-sh similarity index 100% rename from src/rt/libuv/ev/install-sh rename to src/rt/libuv/src/ev/install-sh diff --git a/src/rt/libuv/ev/libev.m4 b/src/rt/libuv/src/ev/libev.m4 similarity index 100% rename from src/rt/libuv/ev/libev.m4 rename to src/rt/libuv/src/ev/libev.m4 diff --git a/src/rt/libuv/ev/ltmain.sh b/src/rt/libuv/src/ev/ltmain.sh similarity index 100% rename from src/rt/libuv/ev/ltmain.sh rename to src/rt/libuv/src/ev/ltmain.sh diff --git a/src/rt/libuv/ev/missing b/src/rt/libuv/src/ev/missing similarity index 100% rename from src/rt/libuv/ev/missing rename to src/rt/libuv/src/ev/missing diff --git a/src/rt/libuv/ev/mkinstalldirs b/src/rt/libuv/src/ev/mkinstalldirs similarity index 100% rename from src/rt/libuv/ev/mkinstalldirs rename to src/rt/libuv/src/ev/mkinstalldirs diff --git a/src/rt/libuv/uv-common.c b/src/rt/libuv/src/uv-common.c similarity index 60% rename from src/rt/libuv/uv-common.c rename to src/rt/libuv/src/uv-common.c index 921ac20df3d..2c4e0cc7659 100644 --- a/src/rt/libuv/uv-common.c +++ b/src/rt/libuv/src/uv-common.c @@ -20,15 +20,24 @@ */ #include "uv.h" +#include "uv-common.h" #include #include /* NULL */ +#include /* memset */ + +/* use inet_pton from c-ares if necessary */ +#include "ares_config.h" +#include "ares/inet_net_pton.h" + +/* list used for ares task handles */ +static uv_ares_task_t* uv_ares_handles_ = NULL; static uv_counters_t counters; -uv_counters_t* const uv_counters() { +uv_counters_t* uv_counters() { return &counters; } @@ -75,3 +84,76 @@ const char* uv_err_name(uv_err_t err) { return NULL; } } + + +struct sockaddr_in uv_ip4_addr(const char* ip, int port) { + struct sockaddr_in addr; + + memset(&addr, 0, sizeof(struct sockaddr_in)); + + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr.s_addr = inet_addr(ip); + + return addr; +} + + +struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) { + struct sockaddr_in6 addr; + + memset(&addr, 0, sizeof(struct sockaddr_in6)); + + addr.sin6_family = AF_INET6; + addr.sin6_port = htons(port); + ares_inet_pton(AF_INET6, ip, &addr.sin6_addr); + + return addr; +} + + +/* find matching ares handle in list */ +void uv_add_ares_handle(uv_ares_task_t* handle) { + handle->ares_next = uv_ares_handles_; + handle->ares_prev = NULL; + + if (uv_ares_handles_) { + uv_ares_handles_->ares_prev = handle; + } + uv_ares_handles_ = handle; +} + +/* find matching ares handle in list */ +/* TODO: faster lookup */ +uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) { + uv_ares_task_t* handle = uv_ares_handles_; + while (handle != NULL) { + if (handle->sock == sock) { + break; + } + handle = handle->ares_next; + } + + return handle; +} + +/* remove ares handle in list */ +void uv_remove_ares_handle(uv_ares_task_t* handle) { + if (handle == uv_ares_handles_) { + uv_ares_handles_ = handle->ares_next; + } + + if (handle->ares_next) { + handle->ares_next->ares_prev = handle->ares_prev; + } + + if (handle->ares_prev) { + handle->ares_prev->ares_next = handle->ares_next; + } +} + + +/* Returns 1 if the uv_ares_handles_ list is empty. 0 otherwise. */ +int uv_ares_handles_empty() { + return uv_ares_handles_ ? 0 : 1; +} diff --git a/src/rt/libuv/src/uv-common.h b/src/rt/libuv/src/uv-common.h new file mode 100644 index 00000000000..74b4c4e38bb --- /dev/null +++ b/src/rt/libuv/src/uv-common.h @@ -0,0 +1,51 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* + * This file is private to libuv. It provides common functionality to both + * Windows and Unix backends. + */ + +#ifndef UV_COMMON_H_ +#define UV_COMMON_H_ + +#include "uv.h" + +/* + * Subclass of uv_handle_t. Used for integration of c-ares. + */ +typedef struct uv_ares_task_s uv_ares_task_t; + +struct uv_ares_task_s { + UV_HANDLE_FIELDS + UV_ARES_TASK_PRIVATE_FIELDS + uv_ares_task_t* ares_prev; + uv_ares_task_t* ares_next; +}; + + +void uv_remove_ares_handle(uv_ares_task_t* handle); +uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock); +void uv_add_ares_handle(uv_ares_task_t* handle); +int uv_ares_handles_empty(); + + +#endif /* UV_COMMON_H_ */ diff --git a/src/rt/libuv/src/uv-cygwin.c b/src/rt/libuv/src/uv-cygwin.c new file mode 100644 index 00000000000..d56a8e839ba --- /dev/null +++ b/src/rt/libuv/src/uv-cygwin.c @@ -0,0 +1,52 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" + +#include +#include +#include + +#undef NANOSEC +#define NANOSEC 1000000000 + + +uint64_t uv_hrtime() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (ts.tv_sec * NANOSEC + ts.tv_nsec); +} + + +int uv_exepath(char* buffer, size_t* size) { + uint32_t usize; + int result; + char* path; + char* fullpath; + + if (!buffer || !size) { + return -1; + } + + *size = readlink("/proc/self/exe", buffer, *size - 1); + if (*size <= 0) return -1; + buffer[*size] = '\0'; + return 0; +} diff --git a/src/rt/libuv/src/uv-darwin.c b/src/rt/libuv/src/uv-darwin.c new file mode 100644 index 00000000000..fa2948cd217 --- /dev/null +++ b/src/rt/libuv/src/uv-darwin.c @@ -0,0 +1,64 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" + +#include +#include +#include +#include + + +uint64_t uv_hrtime() { + uint64_t time; + Nanoseconds enano; + time = mach_absolute_time(); + enano = AbsoluteToNanoseconds(*(AbsoluteTime *)&time); + return (*(uint64_t *)&enano); +} + + +int uv_exepath(char* buffer, size_t* size) { + uint32_t usize; + int result; + char* path; + char* fullpath; + + if (!buffer || !size) { + return -1; + } + + usize = *size; + result = _NSGetExecutablePath(buffer, &usize); + if (result) return result; + + path = (char*)malloc(2 * PATH_MAX); + fullpath = realpath(buffer, path); + + if (fullpath == NULL) { + free(path); + return -1; + } + + strncpy(buffer, fullpath, *size); + free(fullpath); + *size = strlen(buffer); + return 0; +} diff --git a/src/rt/libuv/src/uv-eio.c b/src/rt/libuv/src/uv-eio.c new file mode 100644 index 00000000000..b07735cad8a --- /dev/null +++ b/src/rt/libuv/src/uv-eio.c @@ -0,0 +1,113 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* This file integrates the libuv event loop with the libeio thread pool */ + +#include "uv.h" +#include "eio.h" +#include + + +static uv_async_t uv_eio_want_poll_notifier; +static uv_async_t uv_eio_done_poll_notifier; +static uv_idle_t uv_eio_poller; +static int uv_eio_init_count; + + +static void uv_eio_do_poll(uv_idle_t* watcher, int status) { + assert(watcher == &uv_eio_poller); + + /* printf("uv_eio_poller\n"); */ + + if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &uv_eio_poller)) { + /* printf("uv_eio_poller stop\n"); */ + uv_idle_stop(&uv_eio_poller); + uv_unref(); + } +} + + +/* Called from the main thread. */ +static void uv_eio_want_poll_notifier_cb(uv_async_t* watcher, int status) { + assert(watcher == &uv_eio_want_poll_notifier); + + /* printf("want poll notifier\n"); */ + + if (eio_poll() == -1 && !uv_is_active((uv_handle_t*) &uv_eio_poller)) { + /* printf("uv_eio_poller start\n"); */ + uv_idle_start(&uv_eio_poller, uv_eio_do_poll); + uv_ref(); + } +} + + +static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) { + assert(watcher == &uv_eio_done_poll_notifier); + + /* printf("done poll notifier\n"); */ + + if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &uv_eio_poller)) { + /* printf("uv_eio_poller stop\n"); */ + uv_idle_stop(&uv_eio_poller); + uv_unref(); + } +} + + +/* + * uv_eio_want_poll() is called from the EIO thread pool each time an EIO + * request (that is, one of the node.fs.* functions) has completed. + */ +static void uv_eio_want_poll(void) { + /* Signal the main thread that eio_poll need to be processed. */ + uv_async_send(&uv_eio_want_poll_notifier); +} + + +static void uv_eio_done_poll(void) { + /* + * Signal the main thread that we should stop calling eio_poll(). + * from the idle watcher. + */ + uv_async_send(&uv_eio_done_poll_notifier); +} + + +void uv_eio_init() { + if (uv_eio_init_count == 0) { + uv_eio_init_count++; + + uv_idle_init(&uv_eio_poller); + uv_idle_start(&uv_eio_poller, uv_eio_do_poll); + + uv_async_init(&uv_eio_want_poll_notifier, uv_eio_want_poll_notifier_cb); + uv_unref(); + + uv_async_init(&uv_eio_done_poll_notifier, uv_eio_done_poll_notifier_cb); + uv_unref(); + + eio_init(uv_eio_want_poll, uv_eio_done_poll); + /* + * Don't handle more than 10 reqs on each eio_poll(). This is to avoid + * race conditions. See Node's test/simple/test-eio-race.js + */ + eio_set_max_poll_reqs(10); + } +} diff --git a/src/rt/libuv/src/uv-eio.h b/src/rt/libuv/src/uv-eio.h new file mode 100644 index 00000000000..2f2d3486bf3 --- /dev/null +++ b/src/rt/libuv/src/uv-eio.h @@ -0,0 +1,13 @@ +/* This header is private to libuv */ +#ifndef UV_EIO_H_ +#define UV_EIO_H_ + +#include "eio.h" + +/* + * Call this function to integrate libeio into the libuv event loop. It is + * safe to call more than once. + * TODO: uv_eio_deinit + */ +void uv_eio_init(void); +#endif diff --git a/src/rt/libuv/src/uv-freebsd.c b/src/rt/libuv/src/uv-freebsd.c new file mode 100644 index 00000000000..108455d8804 --- /dev/null +++ b/src/rt/libuv/src/uv-freebsd.c @@ -0,0 +1,49 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" + + +int uv_exepath(char* buffer, size_t* size) { + uint32_t usize; + int result; + char* path; + char* fullpath; + + if (!buffer || !size) { + return -1; + } + + int mib[4]; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + + size_t cb = *size; + if (sysctl(mib, 4, buffer, &cb, NULL, 0) < 0) { + *size = 0; + return -1; + } + *size = strlen(buffer); + + return 0; +} diff --git a/src/rt/libuv/src/uv-linux.c b/src/rt/libuv/src/uv-linux.c new file mode 100644 index 00000000000..dc718c6decd --- /dev/null +++ b/src/rt/libuv/src/uv-linux.c @@ -0,0 +1,55 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" + +#include +#include +#include + +#undef NANOSEC +#define NANOSEC 1000000000 + +/* + * There's probably some way to get time from Linux than gettimeofday(). What + * it is, I don't know. + */ +uint64_t uv_hrtime() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (ts.tv_sec * NANOSEC + ts.tv_nsec); +} + + +int uv_exepath(char* buffer, size_t* size) { + uint32_t usize; + int result; + char* path; + char* fullpath; + + if (!buffer || !size) { + return -1; + } + + *size = readlink("/proc/self/exe", buffer, *size - 1); + if (*size <= 0) return -1; + buffer[*size] = '\0'; + return 0; +} diff --git a/src/rt/libuv/src/uv-sunos.c b/src/rt/libuv/src/uv-sunos.c new file mode 100644 index 00000000000..4a75461413e --- /dev/null +++ b/src/rt/libuv/src/uv-sunos.c @@ -0,0 +1,60 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" + +#include +#include +#include +#include + + +uint64_t uv_hrtime() { + return (gethrtime()); +} + + +/* + * We could use a static buffer for the path manipulations that we need outside + * of the function, but this function could be called by multiple consumers and + * we don't want to potentially create a race condition in the use of snprintf. + */ +int uv_exepath(char* buffer, size_t* size) { + size_t res; + pid_t pid; + char buf[128]; + + if (buffer == NULL) + return (-1); + + if (size == NULL) + return (-1); + + pid = getpid(); + (void) snprintf(buf, sizeof (buf), "/proc/%d/path/a.out", pid); + res = readlink(buf, buffer, *size - 1); + + if (res < 0) + return (res); + + buffer[res] = '\0'; + *size = res; + return (0); +} diff --git a/src/rt/libuv/uv-unix.c b/src/rt/libuv/src/uv-unix.c similarity index 67% rename from src/rt/libuv/uv-unix.c rename to src/rt/libuv/src/uv-unix.c index b0e85d95706..e29c842bfae 100644 --- a/src/rt/libuv/uv-unix.c +++ b/src/rt/libuv/src/uv-unix.c @@ -19,6 +19,8 @@ */ #include "uv.h" +#include "uv-common.h" +#include "uv-eio.h" #include /* NULL */ #include /* printf */ @@ -44,6 +46,18 @@ static uv_err_t last_err; +struct uv_ares_data_s { + ares_channel channel; + /* + * While the channel is active this timer is called once per second to be sure + * that we're always calling ares_process. See the warning above the + * definition of ares_timeout(). + */ + ev_timer timer; +}; + +static struct uv_ares_data_s ares_data; + void uv__tcp_io(EV_P_ ev_io* watcher, int revents); void uv__next(EV_P_ ev_idle* watcher, int revents); @@ -51,7 +65,6 @@ static void uv__tcp_connect(uv_tcp_t*); int uv_tcp_open(uv_tcp_t*, int fd); static void uv__finish_close(uv_handle_t* handle); - /* flags */ enum { UV_CLOSING = 0x00000001, /* uv_close() called but not finished. */ @@ -67,6 +80,29 @@ void uv_flag_set(uv_handle_t* handle, int flag) { } +/* TODO Share this code with Windows. */ +/* TODO Expose callback to user to handle fatal error like V8 does. */ +static void uv_fatal_error(const int errorno, const char* syscall) { + char* buf = NULL; + const char* errmsg; + + if (buf) { + errmsg = buf; + } else { + errmsg = "Unknown error"; + } + + if (syscall) { + fprintf(stderr, "\nlibuv fatal error. %s: (%d) %s\n", syscall, errorno, + errmsg); + } else { + fprintf(stderr, "\nlibuv fatal error. (%d) %s\n", errorno, errmsg); + } + + abort(); +} + + uv_err_t uv_last_error() { return last_err; } @@ -122,17 +158,6 @@ static uv_err_t uv_err_new(uv_handle_t* handle, int sys_error) { } -struct sockaddr_in uv_ip4_addr(char* ip, int port) { - struct sockaddr_in addr; - - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(ip); - - return addr; -} - - int uv_close(uv_handle_t* handle, uv_close_cb close_cb) { uv_tcp_t* tcp; uv_async_t* async; @@ -229,6 +254,7 @@ int uv_tcp_init(uv_tcp_t* tcp) { tcp->fd = -1; tcp->delayed_error = 0; ngx_queue_init(&tcp->write_queue); + ngx_queue_init(&tcp->write_completed_queue); tcp->write_queue_size = 0; ev_init(&tcp->read_watcher, uv__tcp_io); @@ -238,19 +264,18 @@ int uv_tcp_init(uv_tcp_t* tcp) { tcp->write_watcher.data = tcp; assert(ngx_queue_empty(&tcp->write_queue)); + assert(ngx_queue_empty(&tcp->write_completed_queue)); assert(tcp->write_queue_size == 0); return 0; } -int uv_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { - int addrsize = sizeof(struct sockaddr_in); - int domain = AF_INET; +int uv__bind(uv_tcp_t* tcp, int domain, struct sockaddr* addr, int addrsize) { int r; if (tcp->fd <= 0) { - int fd = socket(AF_INET, SOCK_STREAM, 0); + int fd = socket(domain, SOCK_STREAM, 0); if (fd < 0) { uv_err_new((uv_handle_t*)tcp, errno); @@ -265,12 +290,7 @@ int uv_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { assert(tcp->fd >= 0); - if (addr.sin_family != AF_INET) { - uv_err_new((uv_handle_t*)tcp, EFAULT); - return -1; - } - - r = bind(tcp->fd, (struct sockaddr*) &addr, addrsize); + r = bind(tcp->fd, addr, addrsize); tcp->delayed_error = 0; if (r) { @@ -289,6 +309,26 @@ int uv_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { } +int uv_tcp_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { + if (addr.sin_family != AF_INET) { + uv_err_new((uv_handle_t*)tcp, EFAULT); + return -1; + } + + return uv__bind(tcp, AF_INET, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)); +} + + +int uv_tcp_bind6(uv_tcp_t* tcp, struct sockaddr_in6 addr) { + if (addr.sin6_family != AF_INET6) { + uv_err_new((uv_handle_t*)tcp, EFAULT); + return -1; + } + + return uv__bind(tcp, AF_INET6, (struct sockaddr*)&addr, sizeof(struct sockaddr_in6)); +} + + int uv_tcp_open(uv_tcp_t* tcp, int fd) { int yes; int r; @@ -322,8 +362,8 @@ int uv_tcp_open(uv_tcp_t* tcp, int fd) { void uv__server_io(EV_P_ ev_io* watcher, int revents) { int fd; - struct sockaddr addr; - socklen_t addrlen; + struct sockaddr_storage addr; + socklen_t addrlen = sizeof(struct sockaddr_storage); uv_tcp_t* tcp = watcher->data; assert(watcher == &tcp->read_watcher || @@ -339,7 +379,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { while (1) { assert(tcp->accepted_fd < 0); - fd = accept(tcp->fd, &addr, &addrlen); + fd = accept(tcp->fd, (struct sockaddr*)&addr, &addrlen); if (fd < 0) { if (errno == EAGAIN) { @@ -350,12 +390,12 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { return; } else { uv_err_new((uv_handle_t*)tcp, errno); - tcp->connection_cb(tcp, -1); + tcp->connection_cb((uv_handle_t*)tcp, -1); } } else { tcp->accepted_fd = fd; - tcp->connection_cb(tcp, 0); + tcp->connection_cb((uv_handle_t*)tcp, 0); if (tcp->accepted_fd >= 0) { /* The user hasn't yet accepted called uv_accept() */ ev_io_stop(EV_DEFAULT_ &tcp->read_watcher); @@ -366,26 +406,29 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { } -int uv_accept(uv_tcp_t* server, uv_tcp_t* client) { - if (server->accepted_fd < 0) { - uv_err_new((uv_handle_t*) server, EAGAIN); +int uv_accept(uv_handle_t* server, uv_stream_t* client) { + uv_tcp_t* tcpServer = (uv_tcp_t*)server; + uv_tcp_t* tcpClient = (uv_tcp_t*)client; + + if (tcpServer->accepted_fd < 0) { + uv_err_new(server, EAGAIN); return -1; } - if (uv_tcp_open(client, server->accepted_fd)) { + if (uv_tcp_open(tcpClient, tcpServer->accepted_fd)) { /* Ignore error for now */ - server->accepted_fd = -1; - close(server->accepted_fd); + tcpServer->accepted_fd = -1; + close(tcpServer->accepted_fd); return -1; } else { - server->accepted_fd = -1; - ev_io_start(EV_DEFAULT_ &server->read_watcher); + tcpServer->accepted_fd = -1; + ev_io_start(EV_DEFAULT_ &tcpServer->read_watcher); return 0; } } -int uv_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { +int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { int r; assert(tcp->fd >= 0); @@ -539,12 +582,14 @@ static void uv__drain(uv_tcp_t* tcp) { } -void uv__write(uv_tcp_t* tcp) { +/* On success returns NULL. On error returns a pointer to the write request + * which had the error. + */ +static uv_req_t* uv__write(uv_tcp_t* tcp) { uv_req_t* req; struct iovec* iov; int iovcnt; ssize_t n; - uv_write_cb cb; assert(tcp->fd >= 0); @@ -554,8 +599,7 @@ void uv__write(uv_tcp_t* tcp) { req = uv_write_queue_head(tcp); if (!req) { assert(tcp->write_queue_size == 0); - uv__drain(tcp); - return; + return NULL; } assert(req->handle == (uv_handle_t*)tcp); @@ -571,23 +615,23 @@ void uv__write(uv_tcp_t* tcp) { * inside the iov each time we write. So there is no need to offset it. */ - n = writev(tcp->fd, iov, iovcnt); - - cb = (uv_write_cb)req->cb; + if (iovcnt == 1) { + n = write(tcp->fd, iov[0].iov_base, iov[0].iov_len); + } + else { + n = writev(tcp->fd, iov, iovcnt); + } if (n < 0) { if (errno != EAGAIN) { - uv_err_t err = uv_err_new((uv_handle_t*)tcp, errno); - - if (cb) { - cb(req, -1); - } - return; + /* Error */ + uv_err_new((uv_handle_t*)tcp, errno); + return req; } } else { /* Successful write */ - /* The loop updates the counters. */ + /* Update the counters. */ while (n > 0) { uv_buf_t* buf = &(req->bufs[req->write_index]); size_t len = buf->len; @@ -619,22 +663,18 @@ void uv__write(uv_tcp_t* tcp) { /* Pop the req off tcp->write_queue. */ ngx_queue_remove(&req->queue); - free(req->bufs); /* FIXME: we should not be allocing for each read */ + if (req->bufs != req->bufsml) { + free(req->bufs); + } req->bufs = NULL; - /* NOTE: call callback AFTER freeing the request data. */ - if (cb) { - cb(req, 0); - } - - if (!ngx_queue_empty(&tcp->write_queue)) { - assert(tcp->write_queue_size > 0); - } else { - /* Write queue drained. */ - uv__drain(tcp); - } - - return; + /* Add it to the write_completed_queue where it will have its + * callback called in the near future. + * TODO: start trying to write the next request. + */ + ngx_queue_insert_tail(&tcp->write_completed_queue, &req->queue); + ev_feed_event(EV_DEFAULT_ &tcp->write_watcher, EV_WRITE); + return NULL; } } } @@ -643,9 +683,42 @@ void uv__write(uv_tcp_t* tcp) { /* Either we've counted n down to zero or we've got EAGAIN. */ assert(n == 0 || n == -1); - /* We're not done yet. */ - assert(ev_is_active(&tcp->write_watcher)); + /* We're not done. */ ev_io_start(EV_DEFAULT_ &tcp->write_watcher); + + return NULL; +} + + +static void uv__write_callbacks(uv_tcp_t* tcp) { + uv_write_cb cb; + int callbacks_made = 0; + ngx_queue_t* q; + uv_req_t* req; + + while (!ngx_queue_empty(&tcp->write_completed_queue)) { + /* Pop a req off write_completed_queue. */ + q = ngx_queue_head(&tcp->write_completed_queue); + assert(q); + req = ngx_queue_data(q, struct uv_req_s, queue); + ngx_queue_remove(q); + + cb = (uv_write_cb) req->cb; + + /* NOTE: call callback AFTER freeing the request data. */ + if (cb) { + cb(req, 0); + } + + callbacks_made++; + } + + assert(ngx_queue_empty(&tcp->write_completed_queue)); + + /* Write queue drained. */ + if (!uv_write_queue_head(tcp)) { + uv__drain(tcp); + } } @@ -659,14 +732,14 @@ void uv__read(uv_tcp_t* tcp) { */ while (tcp->read_cb && uv_flag_is_set((uv_handle_t*)tcp, UV_READING)) { assert(tcp->alloc_cb); - buf = tcp->alloc_cb(tcp, 64 * 1024); + buf = tcp->alloc_cb((uv_stream_t*)tcp, 64 * 1024); assert(buf.len > 0); assert(buf.base); iov = (struct iovec*) &buf; - nread = readv(tcp->fd, iov, 1); + nread = read(tcp->fd, buf.base, buf.len); if (nread < 0) { /* Error */ @@ -676,12 +749,12 @@ void uv__read(uv_tcp_t* tcp) { ev_io_start(EV_DEFAULT_UC_ &tcp->read_watcher); } uv_err_new((uv_handle_t*)tcp, EAGAIN); - tcp->read_cb(tcp, 0, buf); + tcp->read_cb((uv_stream_t*)tcp, 0, buf); return; } else { /* Error. User should call uv_close(). */ uv_err_new((uv_handle_t*)tcp, errno); - tcp->read_cb(tcp, -1, buf); + tcp->read_cb((uv_stream_t*)tcp, -1, buf); assert(!ev_is_active(&tcp->read_watcher)); return; } @@ -689,11 +762,11 @@ void uv__read(uv_tcp_t* tcp) { /* EOF */ uv_err_new_artificial((uv_handle_t*)tcp, UV_EOF); ev_io_stop(EV_DEFAULT_UC_ &tcp->read_watcher); - tcp->read_cb(tcp, -1, buf); + tcp->read_cb((uv_stream_t*)tcp, -1, buf); return; } else { /* Successful read */ - tcp->read_cb(tcp, nread, buf); + tcp->read_cb((uv_stream_t*)tcp, nread, buf); } } } @@ -738,7 +811,17 @@ void uv__tcp_io(EV_P_ ev_io* watcher, int revents) { } if (revents & EV_WRITE) { - uv__write(tcp); + uv_req_t* req = uv__write(tcp); + if (req) { + /* Error. Notify the user. */ + uv_write_cb cb = (uv_write_cb) req->cb; + + if (cb) { + cb(req, -1); + } + } else { + uv__write_callbacks(tcp); + } } } } @@ -799,13 +882,13 @@ static void uv__tcp_connect(uv_tcp_t* tcp) { } -int uv_connect(uv_req_t* req, struct sockaddr_in addr) { +static int uv__connect(uv_req_t* req, struct sockaddr* addr, + socklen_t addrlen) { uv_tcp_t* tcp = (uv_tcp_t*)req->handle; - int addrsize; int r; if (tcp->fd <= 0) { - int fd = socket(AF_INET, SOCK_STREAM, 0); + int fd = socket(addr->sa_family, SOCK_STREAM, 0); if (fd < 0) { uv_err_new((uv_handle_t*)tcp, errno); @@ -833,10 +916,8 @@ int uv_connect(uv_req_t* req, struct sockaddr_in addr) { tcp->connect_req = req; - addrsize = sizeof(struct sockaddr_in); - assert(addr.sin_family == AF_INET); + r = connect(tcp->fd, addr, addrlen); - r = connect(tcp->fd, (struct sockaddr*)&addr, addrsize); tcp->delayed_error = 0; if (r != 0 && errno != EINPROGRESS) { @@ -866,6 +947,20 @@ int uv_connect(uv_req_t* req, struct sockaddr_in addr) { } +int uv_tcp_connect(uv_req_t* req, struct sockaddr_in addr) { + assert(addr.sin_family == AF_INET); + return uv__connect(req, (struct sockaddr*) &addr, + sizeof(struct sockaddr_in)); +} + + +int uv_tcp_connect6(uv_req_t* req, struct sockaddr_in6 addr) { + assert(addr.sin6_family == AF_INET6); + return uv__connect(req, (struct sockaddr*) &addr, + sizeof(struct sockaddr_in6)); +} + + static size_t uv__buf_count(uv_buf_t bufs[], int bufcnt) { size_t total = 0; int i; @@ -883,16 +978,27 @@ static size_t uv__buf_count(uv_buf_t bufs[], int bufcnt) { */ int uv_write(uv_req_t* req, uv_buf_t bufs[], int bufcnt) { uv_tcp_t* tcp = (uv_tcp_t*)req->handle; + int empty_queue = (tcp->write_queue_size == 0); assert(tcp->fd >= 0); ngx_queue_init(&req->queue); req->type = UV_WRITE; - /* TODO: Don't malloc for each write... */ - req->bufs = malloc(sizeof(uv_buf_t) * bufcnt); + + if (bufcnt < UV_REQ_BUFSML_SIZE) { + req->bufs = req->bufsml; + } + else { + req->bufs = malloc(sizeof(uv_buf_t) * bufcnt); + } + memcpy(req->bufs, bufs, bufcnt * sizeof(uv_buf_t)); req->bufcnt = bufcnt; + /* + * fprintf(stderr, "cnt: %d bufs: %p bufsml: %p\n", bufcnt, req->bufs, req->bufsml); + */ + req->write_index = 0; tcp->write_queue_size += uv__buf_count(bufs, bufcnt); @@ -904,7 +1010,29 @@ int uv_write(uv_req_t* req, uv_buf_t bufs[], int bufcnt) { assert(tcp->write_watcher.data == tcp); assert(tcp->write_watcher.fd == tcp->fd); - ev_io_start(EV_DEFAULT_ &tcp->write_watcher); + /* If the queue was empty when this function began, we should attempt to + * do the write immediately. Otherwise start the write_watcher and wait + * for the fd to become writable. + */ + if (empty_queue) { + if (uv__write(tcp)) { + /* Error. uv_last_error has been set. */ + return -1; + } + } + + /* If the queue is now empty - we've flushed the request already. That + * means we need to make the callback. The callback can only be done on a + * fresh stack so we feed the event loop in order to service it. + */ + if (ngx_queue_empty(&tcp->write_queue)) { + ev_feed_event(EV_DEFAULT_ &tcp->write_watcher, EV_WRITE); + } else { + /* Otherwise there is data to write - so we should wait for the file + * descriptor to become writable. + */ + ev_io_start(EV_DEFAULT_ &tcp->write_watcher); + } return 0; } @@ -930,7 +1058,9 @@ int64_t uv_now() { } -int uv_read_start(uv_tcp_t* tcp, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { +int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { + uv_tcp_t* tcp = (uv_tcp_t*)stream; + /* The UV_READING flag is irrelevant of the state of the tcp - it just * expresses the desired state of the user. */ @@ -955,7 +1085,9 @@ int uv_read_start(uv_tcp_t* tcp, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { } -int uv_read_stop(uv_tcp_t* tcp) { +int uv_read_stop(uv_stream_t* stream) { + uv_tcp_t* tcp = (uv_tcp_t*)stream; + uv_flag_unset((uv_handle_t*)tcp, UV_READING); ev_io_stop(EV_DEFAULT_UC_ &tcp->read_watcher); @@ -965,7 +1097,7 @@ int uv_read_stop(uv_tcp_t* tcp) { } -void uv_req_init(uv_req_t* req, uv_handle_t* handle, void* cb) { +void uv_req_init(uv_req_t* req, uv_handle_t* handle, void *(*cb)(void *)) { uv_counters()->req_init++; req->type = UV_UNKNOWN_REQ; req->cb = cb; @@ -978,7 +1110,7 @@ static void uv__prepare(EV_P_ ev_prepare* w, int revents) { uv_prepare_t* prepare = w->data; if (prepare->prepare_cb) { - prepare->prepare_cb((uv_handle_t*)prepare, 0); + prepare->prepare_cb(prepare, 0); } } @@ -996,7 +1128,7 @@ int uv_prepare_init(uv_prepare_t* prepare) { } -int uv_prepare_start(uv_prepare_t* prepare, uv_loop_cb cb) { +int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) { int was_active = ev_is_active(&prepare->prepare_watcher); prepare->prepare_cb = cb; @@ -1028,7 +1160,7 @@ static void uv__check(EV_P_ ev_check* w, int revents) { uv_check_t* check = w->data; if (check->check_cb) { - check->check_cb((uv_handle_t*)check, 0); + check->check_cb(check, 0); } } @@ -1046,7 +1178,7 @@ int uv_check_init(uv_check_t* check) { } -int uv_check_start(uv_check_t* check, uv_loop_cb cb) { +int uv_check_start(uv_check_t* check, uv_check_cb cb) { int was_active = ev_is_active(&check->check_watcher); check->check_cb = cb; @@ -1078,7 +1210,7 @@ static void uv__idle(EV_P_ ev_idle* w, int revents) { uv_idle_t* idle = (uv_idle_t*)(w->data); if (idle->idle_cb) { - idle->idle_cb((uv_handle_t*)idle, 0); + idle->idle_cb(idle, 0); } } @@ -1097,7 +1229,7 @@ int uv_idle_init(uv_idle_t* idle) { } -int uv_idle_start(uv_idle_t* idle, uv_loop_cb cb) { +int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) { int was_active = ev_is_active(&idle->idle_watcher); idle->idle_cb = cb; @@ -1148,7 +1280,7 @@ static void uv__async(EV_P_ ev_async* w, int revents) { uv_async_t* async = w->data; if (async->async_cb) { - async->async_cb((uv_handle_t*)async, 0); + async->async_cb(async, 0); } } @@ -1183,7 +1315,7 @@ static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { } if (timer->timer_cb) { - timer->timer_cb((uv_handle_t*)timer, 0); + timer->timer_cb(timer, 0); } } @@ -1199,7 +1331,7 @@ int uv_timer_init(uv_timer_t* timer) { } -int uv_timer_start(uv_timer_t* timer, uv_loop_cb cb, int64_t timeout, +int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat) { if (ev_is_active(&timer->timer_watcher)) { return -1; @@ -1244,58 +1376,221 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer) { } -int uv_get_exepath(char* buffer, size_t* size) { - uint32_t usize; - int result; - char* path; - char* fullpath; - - if (!buffer || !size) { - return -1; - } - -#if defined(__APPLE__) - usize = *size; - result = _NSGetExecutablePath(buffer, &usize); - if (result) return result; - - path = (char*)malloc(2 * PATH_MAX); - fullpath = realpath(buffer, path); - - if (fullpath == NULL) { - free(path); - return -1; - } - - strncpy(buffer, fullpath, *size); - free(fullpath); - *size = strlen(buffer); - return 0; -#elif defined(__linux__) - *size = readlink("/proc/self/exe", buffer, *size - 1); - if (*size <= 0) return -1; - buffer[*size] = '\0'; - return 0; -#elif defined(__FreeBSD__) - int mib[4]; - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PATHNAME; - mib[3] = -1; - - size_t cb = *size; - if (sysctl(mib, 4, buffer, &cb, NULL, 0) < 0) { - *size = 0; - return -1; - } - *size = strlen(buffer); - - return 0; -#else - assert(0 && "implement me"); - /* Need to return argv[0] */ -#endif +/* + * This is called once per second by ares_data.timer. It is used to + * constantly callback into c-ares for possibly processing timeouts. + */ +static void uv__ares_timeout(EV_P_ struct ev_timer* watcher, int revents) { + assert(watcher == &ares_data.timer); + assert(revents == EV_TIMER); + assert(!uv_ares_handles_empty()); + ares_process_fd(ares_data.channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); } +static void uv__ares_io(EV_P_ struct ev_io* watcher, int revents) { + /* Reset the idle timer */ + ev_timer_again(EV_A_ &ares_data.timer); + + /* Process DNS responses */ + ares_process_fd(ares_data.channel, + revents & EV_READ ? watcher->fd : ARES_SOCKET_BAD, + revents & EV_WRITE ? watcher->fd : ARES_SOCKET_BAD); +} + + +/* Allocates and returns a new uv_ares_task_t */ +static uv_ares_task_t* uv__ares_task_create(int fd) { + uv_ares_task_t* h = malloc(sizeof(uv_ares_task_t)); + + if (h == NULL) { + uv_fatal_error(ENOMEM, "malloc"); + } + + h->sock = fd; + + ev_io_init(&h->read_watcher, uv__ares_io, fd, EV_READ); + ev_io_init(&h->write_watcher, uv__ares_io, fd, EV_WRITE); + + h->read_watcher.data = h; + h->write_watcher.data = h; +} + + +/* Callback from ares when socket operation is started */ +static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, + int read, int write) { + uv_ares_task_t* h = uv_find_ares_handle(sock); + + if (read || write) { + if (!h) { + /* New socket */ + + /* If this is the first socket then start the timer. */ + if (!ev_is_active(&ares_data.timer)) { + assert(uv_ares_handles_empty()); + ev_timer_again(EV_DEFAULT_UC_ &ares_data.timer); + } + + h = uv__ares_task_create(sock); + uv_add_ares_handle(h); + } + + if (read) { + ev_io_start(EV_DEFAULT_UC_ &h->read_watcher); + } else { + ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher); + } + + if (write) { + ev_io_start(EV_DEFAULT_UC_ &h->write_watcher); + } else { + ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher); + } + + } else { + /* + * read == 0 and write == 0 this is c-ares's way of notifying us that + * the socket is now closed. We must free the data associated with + * socket. + */ + assert(h && "When an ares socket is closed we should have a handle for it"); + + ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher); + ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher); + + uv_remove_ares_handle(h); + free(h); + + if (uv_ares_handles_empty()) { + ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer); + } + } +} + + +/* c-ares integration initialize and terminate */ +/* TODO: share this with windows? */ +int uv_ares_init_options(ares_channel *channelptr, + struct ares_options *options, + int optmask) { + int rc; + + /* only allow single init at a time */ + if (ares_data.channel != NULL) { + uv_err_new_artificial(NULL, UV_EALREADY); + return -1; + } + + /* set our callback as an option */ + options->sock_state_cb = uv__ares_sockstate_cb; + options->sock_state_cb_data = &ares_data; + optmask |= ARES_OPT_SOCK_STATE_CB; + + /* We do the call to ares_init_option for caller. */ + rc = ares_init_options(channelptr, options, optmask); + + /* if success, save channel */ + if (rc == ARES_SUCCESS) { + ares_data.channel = *channelptr; + } + + /* + * Initialize the timeout timer. The timer won't be started until the + * first socket is opened. + */ + ev_init(&ares_data.timer, uv__ares_timeout); + ares_data.timer.repeat = 1.0; + + return rc; +} + + +/* TODO share this with windows? */ +void uv_ares_destroy(ares_channel channel) { + /* only allow destroy if did init */ + if (ares_data.channel != NULL) { + ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer); + ares_destroy(channel); + ares_data.channel = NULL; + } +} + + +static int uv_getaddrinfo_done(eio_req* req) { + uv_getaddrinfo_t* handle = req->data; + + uv_unref(); + + free(handle->hints); + free(handle->service); + free(handle->hostname); + + if (handle->retcode != 0) { + /* TODO how to display gai error strings? */ + uv_err_new(NULL, handle->retcode); + } + + handle->cb(handle, handle->retcode, handle->res); + + freeaddrinfo(handle->res); + handle->res = NULL; + + return 0; +} + + +static int getaddrinfo_thread_proc(eio_req *req) { + uv_getaddrinfo_t* handle = req->data; + + handle->retcode = getaddrinfo(handle->hostname, + handle->service, + handle->hints, + &handle->res); + return 0; +} + + +/* stub implementation of uv_getaddrinfo */ +int uv_getaddrinfo(uv_getaddrinfo_t* handle, + uv_getaddrinfo_cb cb, + const char* hostname, + const char* service, + const struct addrinfo* hints) { + eio_req* req; + uv_eio_init(); + + if (handle == NULL || cb == NULL || + (hostname == NULL && service == NULL)) { + uv_err_new_artificial(NULL, UV_EINVAL); + return -1; + } + + memset(handle, 0, sizeof(uv_getaddrinfo_t)); + + /* TODO don't alloc so much. */ + + if (hints) { + handle->hints = malloc(sizeof(struct addrinfo)); + memcpy(&handle->hints, hints, sizeof(struct addrinfo)); + } + + /* TODO security! check lengths, check return values. */ + + handle->cb = cb; + handle->hostname = hostname ? strdup(hostname) : NULL; + handle->service = service ? strdup(service) : NULL; + + /* TODO check handle->hostname == NULL */ + /* TODO check handle->service == NULL */ + + uv_ref(); + + req = eio_custom(getaddrinfo_thread_proc, EIO_PRI_DEFAULT, + uv_getaddrinfo_done, handle); + assert(req); + assert(req->data == handle); + + return 0; +} + diff --git a/src/rt/libuv/uv-win.c b/src/rt/libuv/src/uv-win.c similarity index 50% rename from src/rt/libuv/uv-win.c rename to src/rt/libuv/src/uv-win.c index 6a42b4d4772..93bf64d193c 100644 --- a/src/rt/libuv/uv-win.c +++ b/src/rt/libuv/src/uv-win.c @@ -26,6 +26,7 @@ #include #include "uv.h" +#include "uv-common.h" #include "tree.h" /* @@ -53,49 +54,49 @@ {0xb5367df0, 0xcbac, 0x11cf, \ {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} - typedef BOOL(*LPFN_ACCEPTEX) - (SOCKET sListenSocket, - SOCKET sAcceptSocket, - PVOID lpOutputBuffer, - DWORD dwReceiveDataLength, - DWORD dwLocalAddressLength, - DWORD dwRemoteAddressLength, - LPDWORD lpdwBytesReceived, - LPOVERLAPPED lpOverlapped); + typedef BOOL PASCAL (*LPFN_ACCEPTEX) + (SOCKET sListenSocket, + SOCKET sAcceptSocket, + PVOID lpOutputBuffer, + DWORD dwReceiveDataLength, + DWORD dwLocalAddressLength, + DWORD dwRemoteAddressLength, + LPDWORD lpdwBytesReceived, + LPOVERLAPPED lpOverlapped); - typedef BOOL(*LPFN_CONNECTEX) - (SOCKET s, - const struct sockaddr* name, - int namelen, - PVOID lpSendBuffer, - DWORD dwSendDataLength, - LPDWORD lpdwBytesSent, - LPOVERLAPPED lpOverlapped); + typedef BOOL PASCAL (*LPFN_CONNECTEX) + (SOCKET s, + const struct sockaddr* name, + int namelen, + PVOID lpSendBuffer, + DWORD dwSendDataLength, + LPDWORD lpdwBytesSent, + LPOVERLAPPED lpOverlapped); - typedef void(*LPFN_GETACCEPTEXSOCKADDRS) - (PVOID lpOutputBuffer, - DWORD dwReceiveDataLength, - DWORD dwLocalAddressLength, - DWORD dwRemoteAddressLength, - LPSOCKADDR* LocalSockaddr, - LPINT LocalSockaddrLength, - LPSOCKADDR* RemoteSockaddr, - LPINT RemoteSockaddrLength); + typedef void PASCAL (*LPFN_GETACCEPTEXSOCKADDRS) + (PVOID lpOutputBuffer, + DWORD dwReceiveDataLength, + DWORD dwLocalAddressLength, + DWORD dwRemoteAddressLength, + LPSOCKADDR* LocalSockaddr, + LPINT LocalSockaddrLength, + LPSOCKADDR* RemoteSockaddr, + LPINT RemoteSockaddrLength); - typedef BOOL(*LPFN_DISCONNECTEX) - (SOCKET hSocket, - LPOVERLAPPED lpOverlapped, - DWORD dwFlags, - DWORD reserved); + typedef BOOL PASCAL (*LPFN_DISCONNECTEX) + (SOCKET hSocket, + LPOVERLAPPED lpOverlapped, + DWORD dwFlags, + DWORD reserved); - typedef BOOL(*LPFN_TRANSMITFILE) - (SOCKET hSocket, - HANDLE hFile, - DWORD nNumberOfBytesToWrite, - DWORD nNumberOfBytesPerSend, - LPOVERLAPPED lpOverlapped, - LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, - DWORD dwFlags); + typedef BOOL PASCAL (*LPFN_TRANSMITFILE) + (SOCKET hSocket, + HANDLE hFile, + DWORD nNumberOfBytesToWrite, + DWORD nNumberOfBytesPerSend, + LPOVERLAPPED lpOverlapped, + LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, + DWORD dwFlags); #endif /* @@ -106,6 +107,30 @@ #endif +/* + * MinGW is missing this too + */ +#ifndef _MSC_VER + typedef struct addrinfoW { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + wchar_t* ai_canonname; + struct sockaddr* ai_addr; + struct addrinfoW* ai_next; + } ADDRINFOW, *PADDRINFOW; + + DECLSPEC_IMPORT int WSAAPI GetAddrInfoW(const wchar_t* node, + const wchar_t* service, + const ADDRINFOW* hints, + PADDRINFOW* result); + + DECLSPEC_IMPORT void WSAAPI FreeAddrInfoW(PADDRINFOW pAddrInfo); +#endif + + /* * Pointers to winsock extension functions to be retrieved dynamically */ @@ -114,6 +139,12 @@ static LPFN_ACCEPTEX pAcceptEx; static LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs; static LPFN_DISCONNECTEX pDisconnectEx; static LPFN_TRANSMITFILE pTransmitFile; +/* need IPv6 versions of winsock extension functions */ +static LPFN_CONNECTEX pConnectEx6; +static LPFN_ACCEPTEX pAcceptEx6; +static LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs6; +static LPFN_DISCONNECTEX pDisconnectEx6; +static LPFN_TRANSMITFILE pTransmitFile6; /* @@ -132,6 +163,7 @@ static LPFN_TRANSMITFILE pTransmitFile; #define UV_HANDLE_SHUT 0x0200 #define UV_HANDLE_ENDGAME_QUEUED 0x0400 #define UV_HANDLE_BIND_ERROR 0x1000 +#define UV_HANDLE_IPV6 0x2000 /* * Private uv_req flags. @@ -149,17 +181,6 @@ RB_PROTOTYPE_STATIC(uv_timer_tree_s, uv_timer_s, tree_entry, uv_timer_compare) static struct uv_timer_tree_s uv_timers_ = RB_INITIALIZER(uv_timers_); -/* Lists of active uv_prepare / uv_check / uv_idle watchers */ -static uv_handle_t* uv_prepare_handles_ = NULL; -static uv_handle_t* uv_check_handles_ = NULL; -static uv_handle_t* uv_idle_handles_ = NULL; - -/* This pointer will refer to the prepare/check/idle handle whose callback */ -/* is scheduled to be called next. This is needed to allow safe removal */ -/* from one of the lists above while that list being iterated. */ -static uv_handle_t* uv_next_loop_handle_ = NULL; - - /* Head of a single-linked list of closed handles */ static uv_handle_t* uv_endgame_handles_ = NULL; @@ -194,12 +215,57 @@ static int uv_refs_ = 0; /* Ip address used to bind to any port at any interface */ static struct sockaddr_in uv_addr_ip4_any_; +static struct sockaddr_in6 uv_addr_ip6_any_; /* A zero-size buffer for use by uv_read */ static char uv_zero_[] = ""; +/* mark if IPv6 sockets are supported */ +static BOOL uv_allow_ipv6 = FALSE; + +/* + * Subclass of uv_handle_t. Used for integration of c-ares. + */ +typedef struct uv_ares_action_s uv_ares_action_t; + +struct uv_ares_action_s { + UV_HANDLE_FIELDS + struct uv_req_s ares_req; + SOCKET sock; + int read; + int write; +}; + +void uv_ares_process(uv_ares_action_t* handle, uv_req_t* req); +void uv_ares_task_cleanup(uv_ares_task_t* handle, uv_req_t* req); +void uv_ares_poll(uv_timer_t* handle, int status); + +/* memory used per ares_channel */ +struct uv_ares_channel_s { + ares_channel channel; + int activesockets; + uv_timer_t pollingtimer; +}; + +typedef struct uv_ares_channel_s uv_ares_channel_t; + +/* static data to hold single ares_channel */ +static uv_ares_channel_t uv_ares_data = { NULL, 0 }; + +/* default timeout per socket request if ares does not specify value */ +/* use 20 sec */ +#define ARES_TIMEOUT_MS 20000 + + +/* getaddrinfo integration */ +static void uv_getaddrinfo_done(uv_getaddrinfo_t* handle, uv_req_t* req); +/* adjust size value to be multiple of 4. Use to keep pointer aligned */ +/* Do we need different versions of this for different architectures? */ +#define ALIGNED_SIZE(X) ((((X) + 3) >> 2) << 2) + + /* Atomic set operation on char */ #ifdef _MSC_VER /* MSVC */ @@ -303,6 +369,10 @@ static uv_err_code uv_translate_sys_error(int sys_errno) { case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE; case WSAEMFILE: return UV_EMFILE; case ERROR_OUTOFMEMORY: return UV_ENOMEM; + case ERROR_INSUFFICIENT_BUFFER: return UV_EINVAL; + case ERROR_INVALID_FLAGS: return UV_EBADF; + case ERROR_INVALID_PARAMETER: return UV_EINVAL; + case ERROR_NO_UNICODE_TRANSLATION: return UV_ECHARSET; default: return UV_UNKNOWN; } } @@ -325,7 +395,7 @@ static void uv_set_sys_error(int sys_errno) { /* * Retrieves the pointer to a winsock extension function. */ -static void uv_get_extension_function(SOCKET socket, GUID guid, +static BOOL uv_get_extension_function(SOCKET socket, GUID guid, void **target) { DWORD result, bytes; @@ -341,8 +411,9 @@ static void uv_get_extension_function(SOCKET socket, GUID guid, if (result == SOCKET_ERROR) { *target = NULL; - uv_fatal_error(WSAGetLastError(), - "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER)"); + return FALSE; + } else { + return TRUE; } } @@ -358,6 +429,7 @@ void uv_init() { int errorno; LARGE_INTEGER timer_frequency; SOCKET dummy; + SOCKET dummy6; /* Initialize winsock */ errorno = WSAStartup(MAKEWORD(2, 2), &wsa_data); @@ -367,6 +439,7 @@ void uv_init() { /* Set implicit binding address used by connectEx */ uv_addr_ip4_any_ = uv_ip4_addr("0.0.0.0", 0); + uv_addr_ip6_any_ = uv_ip6_addr("::1", 0); /* Retrieve the needed winsock extension function pointers. */ dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); @@ -374,26 +447,57 @@ void uv_init() { uv_fatal_error(WSAGetLastError(), "socket"); } - uv_get_extension_function(dummy, + if (!uv_get_extension_function(dummy, wsaid_connectex, - (void**)&pConnectEx); - uv_get_extension_function(dummy, + (void**)&pConnectEx) || + !uv_get_extension_function(dummy, wsaid_acceptex, - (void**)&pAcceptEx); - uv_get_extension_function(dummy, + (void**)&pAcceptEx) || + !uv_get_extension_function(dummy, wsaid_getacceptexsockaddrs, - (void**)&pGetAcceptExSockAddrs); - uv_get_extension_function(dummy, + (void**)&pGetAcceptExSockAddrs) || + !uv_get_extension_function(dummy, wsaid_disconnectex, - (void**)&pDisconnectEx); - uv_get_extension_function(dummy, + (void**)&pDisconnectEx) || + !uv_get_extension_function(dummy, wsaid_transmitfile, - (void**)&pTransmitFile); + (void**)&pTransmitFile)) { + uv_fatal_error(WSAGetLastError(), + "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER)"); + } if (closesocket(dummy) == SOCKET_ERROR) { uv_fatal_error(WSAGetLastError(), "closesocket"); } +/* optional IPv6 versions of winsock extension functions */ + dummy6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_IP); + if (dummy6 != INVALID_SOCKET) { + uv_allow_ipv6 = TRUE; + + if (!uv_get_extension_function(dummy6, + wsaid_connectex, + (void**)&pConnectEx6) || + !uv_get_extension_function(dummy6, + wsaid_acceptex, + (void**)&pAcceptEx6) || + !uv_get_extension_function(dummy6, + wsaid_getacceptexsockaddrs, + (void**)&pGetAcceptExSockAddrs6) || + !uv_get_extension_function(dummy6, + wsaid_disconnectex, + (void**)&pDisconnectEx6) || + !uv_get_extension_function(dummy6, + wsaid_transmitfile, + (void**)&pTransmitFile6)) { + uv_allow_ipv6 = FALSE; + } + + if (closesocket(dummy6) == SOCKET_ERROR) { + uv_fatal_error(WSAGetLastError(), "closesocket"); + } + } + /* Create an I/O completion port */ uv_iocp_ = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1); if (uv_iocp_ == NULL) { @@ -409,7 +513,7 @@ void uv_init() { } -void uv_req_init(uv_req_t* req, uv_handle_t* handle, void* cb) { +void uv_req_init(uv_req_t* req, uv_handle_t* handle, void *(*cb)(void *)) { uv_counters()->req_init++; req->type = UV_UNKNOWN_REQ; req->flags = 0; @@ -497,8 +601,6 @@ static void uv_tcp_init_connection(uv_tcp_t* handle) { int uv_tcp_init(uv_tcp_t* handle) { - SOCKET sock; - handle->socket = INVALID_SOCKET; handle->write_queue_size = 0; handle->type = UV_TCP; @@ -569,7 +671,7 @@ static void uv_timer_endgame(uv_timer_t* handle) { } -static void uv_loop_endgame(uv_handle_t* handle) { +static void uv_loop_watcher_endgame(uv_handle_t* handle) { if (handle->flags & UV_HANDLE_CLOSING) { assert(!(handle->flags & UV_HANDLE_CLOSED)); handle->flags |= UV_HANDLE_CLOSED; @@ -619,7 +721,7 @@ static void uv_process_endgames() { case UV_PREPARE: case UV_CHECK: case UV_IDLE: - uv_loop_endgame(handle); + uv_loop_watcher_endgame(handle); break; case UV_ASYNC: @@ -705,30 +807,13 @@ int uv_close(uv_handle_t* handle, uv_close_cb close_cb) { } -struct sockaddr_in uv_ip4_addr(char* ip, int port) { - struct sockaddr_in addr; - - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(ip); - - return addr; -} - - -int uv_bind(uv_tcp_t* handle, struct sockaddr_in addr) { +int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int addrsize) { DWORD err; int r; SOCKET sock; - int addrsize = sizeof(struct sockaddr_in); - - if (addr.sin_family != AF_INET) { - uv_set_sys_error(WSAEFAULT); - return -1; - } if (handle->socket == INVALID_SOCKET) { - sock = socket(AF_INET, SOCK_STREAM, 0); + sock = socket(domain, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { uv_set_sys_error(WSAGetLastError()); return -1; @@ -740,7 +825,7 @@ int uv_bind(uv_tcp_t* handle, struct sockaddr_in addr) { } } - r = bind(handle->socket, (struct sockaddr*) &addr, addrsize); + r = bind(handle->socket, addr, addrsize); if (r == SOCKET_ERROR) { err = WSAGetLastError(); @@ -760,11 +845,38 @@ int uv_bind(uv_tcp_t* handle, struct sockaddr_in addr) { } +int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { + if (addr.sin_family != AF_INET) { + uv_set_sys_error(WSAEFAULT); + return -1; + } + + return uv__bind(handle, AF_INET, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)); +} + + +int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { + if (addr.sin6_family != AF_INET6) { + uv_set_sys_error(WSAEFAULT); + return -1; + } + if (uv_allow_ipv6) { + handle->flags |= UV_HANDLE_IPV6; + return uv__bind(handle, AF_INET6, (struct sockaddr*)&addr, sizeof(struct sockaddr_in6)); + } else { + uv_new_sys_error(UV_EAFNOSUPPORT); + return -1; + } +} + + static void uv_queue_accept(uv_tcp_t* handle) { uv_req_t* req; BOOL success; DWORD bytes; SOCKET accept_socket; + short family; + LPFN_ACCEPTEX pAcceptExFamily; assert(handle->flags & UV_HANDLE_LISTENING); assert(handle->accept_socket == INVALID_SOCKET); @@ -775,8 +887,17 @@ static void uv_queue_accept(uv_tcp_t* handle) { req->type = UV_ACCEPT; req->flags |= UV_REQ_PENDING; + /* choose family and extension function */ + if ((handle->flags & UV_HANDLE_IPV6) != 0) { + family = AF_INET6; + pAcceptExFamily = pAcceptEx6; + } else { + family = AF_INET; + pAcceptExFamily = pAcceptEx; + } + /* Open a socket for the accepted connection. */ - accept_socket = socket(AF_INET, SOCK_STREAM, 0); + accept_socket = socket(family, SOCK_STREAM, 0); if (accept_socket == INVALID_SOCKET) { req->error = uv_new_sys_error(WSAGetLastError()); uv_insert_pending_req(req); @@ -786,14 +907,14 @@ static void uv_queue_accept(uv_tcp_t* handle) { /* Prepare the overlapped structure. */ memset(&(req->overlapped), 0, sizeof(req->overlapped)); - success = pAcceptEx(handle->socket, - accept_socket, - (void*)&handle->accept_buffer, - 0, - sizeof(struct sockaddr_storage), - sizeof(struct sockaddr_storage), - &bytes, - &req->overlapped); + success = pAcceptExFamily(handle->socket, + accept_socket, + (void*)&handle->accept_buffer, + 0, + sizeof(struct sockaddr_storage), + sizeof(struct sockaddr_storage), + &bytes, + &req->overlapped); if (!success && WSAGetLastError() != ERROR_IO_PENDING) { /* Make this req pending reporting an error. */ @@ -847,7 +968,7 @@ static void uv_queue_read(uv_tcp_t* handle) { } -int uv_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { +int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { assert(backlog > 0); if (handle->flags & UV_HANDLE_BIND_ERROR) { @@ -877,32 +998,34 @@ int uv_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { } -int uv_accept(uv_tcp_t* server, uv_tcp_t* client) { +int uv_accept(uv_handle_t* server, uv_stream_t* client) { int rv = 0; - - if (server->accept_socket == INVALID_SOCKET) { + uv_tcp_t* tcpServer = (uv_tcp_t*)server; + uv_tcp_t* tcpClient = (uv_tcp_t*)client; + + if (tcpServer->accept_socket == INVALID_SOCKET) { uv_set_sys_error(WSAENOTCONN); return -1; } - if (uv_tcp_set_socket(client, server->accept_socket) == -1) { - closesocket(server->accept_socket); + if (uv_tcp_set_socket(tcpClient, tcpServer->accept_socket) == -1) { + closesocket(tcpServer->accept_socket); rv = -1; } else { - uv_tcp_init_connection(client); + uv_tcp_init_connection(tcpClient); } - server->accept_socket = INVALID_SOCKET; + tcpServer->accept_socket = INVALID_SOCKET; - if (!(server->flags & UV_HANDLE_CLOSING)) { - uv_queue_accept(server); + if (!(tcpServer->flags & UV_HANDLE_CLOSING)) { + uv_queue_accept(tcpServer); } return rv; } -int uv_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { +int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { if (!(handle->flags & UV_HANDLE_CONNECTION)) { uv_set_sys_error(WSAEINVAL); return -1; @@ -925,20 +1048,20 @@ int uv_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { /* If reading was stopped and then started again, there could stell be a */ /* read request pending. */ if (!(handle->read_req.flags & UV_REQ_PENDING)) - uv_queue_read(handle); + uv_queue_read((uv_tcp_t*)handle); return 0; } -int uv_read_stop(uv_tcp_t* handle) { +int uv_read_stop(uv_stream_t* handle) { handle->flags &= ~UV_HANDLE_READING; return 0; } -int uv_connect(uv_req_t* req, struct sockaddr_in addr) { +int uv_tcp_connect(uv_req_t* req, struct sockaddr_in addr) { int addrsize = sizeof(struct sockaddr_in); BOOL success; DWORD bytes; @@ -957,7 +1080,7 @@ int uv_connect(uv_req_t* req, struct sockaddr_in addr) { } if (!(handle->flags & UV_HANDLE_BOUND) && - uv_bind(handle, uv_addr_ip4_any_) < 0) + uv_tcp_bind(handle, uv_addr_ip4_any_) < 0) return -1; memset(&req->overlapped, 0, sizeof(req->overlapped)); @@ -983,6 +1106,56 @@ int uv_connect(uv_req_t* req, struct sockaddr_in addr) { } +int uv_tcp_connect6(uv_req_t* req, struct sockaddr_in6 addr) { + int addrsize = sizeof(struct sockaddr_in6); + BOOL success; + DWORD bytes; + uv_tcp_t* handle = (uv_tcp_t*)req->handle; + + if (!uv_allow_ipv6) { + uv_new_sys_error(UV_EAFNOSUPPORT); + return -1; + } + + assert(!(req->flags & UV_REQ_PENDING)); + + if (handle->flags & UV_HANDLE_BIND_ERROR) { + uv_last_error_ = handle->error; + return -1; + } + + if (addr.sin6_family != AF_INET6) { + uv_set_sys_error(WSAEFAULT); + return -1; + } + + if (!(handle->flags & UV_HANDLE_BOUND) && + uv_tcp_bind6(handle, uv_addr_ip6_any_) < 0) + return -1; + + memset(&req->overlapped, 0, sizeof(req->overlapped)); + req->type = UV_CONNECT; + + success = pConnectEx6(handle->socket, + (struct sockaddr*)&addr, + addrsize, + NULL, + 0, + &bytes, + &req->overlapped); + + if (!success && WSAGetLastError() != ERROR_IO_PENDING) { + uv_set_sys_error(WSAGetLastError()); + return -1; + } + + req->flags |= UV_REQ_PENDING; + handle->reqs_pending++; + + return 0; +} + + static size_t uv_count_bufs(uv_buf_t bufs[], int count) { size_t bytes = 0; int i; @@ -1110,13 +1283,13 @@ static void uv_tcp_return_req(uv_tcp_t* handle, uv_req_t* req) { uv_last_error_ = req->error; buf.base = 0; buf.len = 0; - handle->read_cb(handle, -1, buf); + handle->read_cb((uv_stream_t*)handle, -1, buf); break; } /* Do nonblocking reads until the buffer is empty */ while (handle->flags & UV_HANDLE_READING) { - buf = handle->alloc_cb(handle, 65536); + buf = handle->alloc_cb((uv_stream_t*)handle, 65536); assert(buf.len > 0); flags = 0; if (WSARecv(handle->socket, @@ -1128,7 +1301,7 @@ static void uv_tcp_return_req(uv_tcp_t* handle, uv_req_t* req) { NULL) != SOCKET_ERROR) { if (bytes > 0) { /* Successful read */ - handle->read_cb(handle, bytes, buf); + handle->read_cb((uv_stream_t*)handle, bytes, buf); /* Read again only if bytes == buf.len */ if (bytes < buf.len) { break; @@ -1139,7 +1312,7 @@ static void uv_tcp_return_req(uv_tcp_t* handle, uv_req_t* req) { handle->flags |= UV_HANDLE_EOF; uv_last_error_.code = UV_EOF; uv_last_error_.sys_errno_ = ERROR_SUCCESS; - handle->read_cb(handle, -1, buf); + handle->read_cb((uv_stream_t*)handle, -1, buf); break; } } else { @@ -1147,11 +1320,11 @@ static void uv_tcp_return_req(uv_tcp_t* handle, uv_req_t* req) { if (err == WSAEWOULDBLOCK) { /* Read buffer was completely empty, report a 0-byte read. */ uv_set_sys_error(WSAEWOULDBLOCK); - handle->read_cb(handle, 0, buf); + handle->read_cb((uv_stream_t*)handle, 0, buf); } else { /* Ouch! serious error. */ uv_set_sys_error(err); - handle->read_cb(handle, -1, buf); + handle->read_cb((uv_stream_t*)handle, -1, buf); } break; } @@ -1174,7 +1347,7 @@ static void uv_tcp_return_req(uv_tcp_t* handle, uv_req_t* req) { handle->flags &= ~UV_HANDLE_LISTENING; if (handle->connection_cb) { uv_last_error_ = req->error; - handle->connection_cb(handle, -1); + handle->connection_cb((uv_handle_t*)handle, -1); } break; } @@ -1187,7 +1360,7 @@ static void uv_tcp_return_req(uv_tcp_t* handle, uv_req_t* req) { sizeof(handle->socket)) == 0) { /* Accept and SO_UPDATE_ACCEPT_CONTEXT were successful. */ if (handle->connection_cb) { - handle->connection_cb(handle, 0); + handle->connection_cb((uv_handle_t*)handle, 0); } } else { /* Error related to accepted socket is ignored because the server */ @@ -1269,7 +1442,7 @@ int uv_timer_init(uv_timer_t* handle) { } -int uv_timer_start(uv_timer_t* handle, uv_loop_cb timer_cb, int64_t timeout, int64_t repeat) { +int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, int64_t timeout, int64_t repeat) { if (handle->flags & UV_HANDLE_ACTIVE) { RB_REMOVE(uv_timer_tree_s, &uv_timers_, handle); } @@ -1352,140 +1525,103 @@ int64_t uv_now() { } -int uv_loop_init(uv_handle_t* handle) { - handle->flags = 0; - handle->error = uv_ok_; - - uv_refs_++; - - return 0; -} - - -static int uv_loop_start(uv_handle_t* handle, uv_loop_cb loop_cb, - uv_handle_t** list) { - uv_handle_t* old_head; - - if (handle->flags & UV_HANDLE_ACTIVE) - return 0; - - old_head = *list; - - handle->loop_next = old_head; - handle->loop_prev = NULL; - - if (old_head) { - old_head->loop_prev = handle; +#define UV_LOOP_WATCHER_DEFINE(name, NAME) \ + /* Lists of active loop (prepare / check / idle) watchers */ \ + static uv_##name##_t* uv_##name##_handles_ = NULL; \ + \ + /* This pointer will refer to the prepare/check/idle handle whose */ \ + /* callback is scheduled to be called next. This is needed to allow */ \ + /* safe removal from one of the lists above while that list being */ \ + /* iterated over. */ \ + static uv_##name##_t* uv_next_##name##_handle_ = NULL; \ + \ + \ + int uv_##name##_init(uv_##name##_t* handle) { \ + handle->type = UV_##NAME; \ + handle->flags = 0; \ + handle->error = uv_ok_; \ + \ + uv_refs_++; \ + \ + uv_counters()->handle_init++; \ + uv_counters()->prepare_init++; \ + \ + return 0; \ + } \ + \ + \ + int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \ + uv_##name##_t* old_head; \ + \ + assert(handle->type == UV_##NAME); \ + \ + if (handle->flags & UV_HANDLE_ACTIVE) \ + return 0; \ + \ + old_head = uv_##name##_handles_; \ + \ + handle->name##_next = old_head; \ + handle->name##_prev = NULL; \ + \ + if (old_head) { \ + old_head->name##_prev = handle; \ + } \ + \ + uv_##name##_handles_ = handle; \ + \ + handle->name##_cb = cb; \ + handle->flags |= UV_HANDLE_ACTIVE; \ + \ + return 0; \ + } \ + \ + \ + int uv_##name##_stop(uv_##name##_t* handle) { \ + assert(handle->type == UV_##NAME); \ + \ + if (!(handle->flags & UV_HANDLE_ACTIVE)) \ + return 0; \ + \ + /* Update loop head if needed */ \ + if (uv_##name##_handles_ == handle) { \ + uv_##name##_handles_ = handle->name##_next; \ + } \ + \ + /* Update the iterator-next pointer of needed */ \ + if (uv_next_##name##_handle_ == handle) { \ + uv_next_##name##_handle_ = handle->name##_next; \ + } \ + \ + if (handle->name##_prev) { \ + handle->name##_prev->name##_next = handle->name##_next; \ + } \ + if (handle->name##_next) { \ + handle->name##_next->name##_prev = handle->name##_prev; \ + } \ + \ + handle->flags &= ~UV_HANDLE_ACTIVE; \ + \ + return 0; \ + } \ + \ + \ + static void uv_##name##_invoke() { \ + uv_##name##_t* handle; \ + \ + uv_next_##name##_handle_ = uv_##name##_handles_; \ + \ + while (uv_next_##name##_handle_ != NULL) { \ + handle = uv_next_##name##_handle_; \ + uv_next_##name##_handle_ = handle->name##_next; \ + \ + handle->name##_cb(handle, 0); \ + } \ } - *list = handle; - handle->loop_cb = loop_cb; - handle->flags |= UV_HANDLE_ACTIVE; - - return 0; -} - - -static int uv_loop_stop(uv_handle_t* handle, uv_handle_t** list) { - if (!(handle->flags & UV_HANDLE_ACTIVE)) - return 0; - - /* Update loop head if needed */ - if (*list == handle) { - *list = handle->loop_next; - } - - /* Update the iterator-next pointer of needed */ - if (uv_next_loop_handle_ == handle) { - uv_next_loop_handle_ = handle->loop_next; - } - - if (handle->loop_prev) { - handle->loop_prev->loop_next = handle->loop_next; - } - if (handle->loop_next) { - handle->loop_next->loop_prev = handle->loop_prev; - } - - handle->flags &= ~UV_HANDLE_ACTIVE; - - return 0; -} - - -static void uv_loop_invoke(uv_handle_t* list) { - uv_handle_t *handle; - - uv_next_loop_handle_ = list; - - while (uv_next_loop_handle_ != NULL) { - handle = uv_next_loop_handle_; - uv_next_loop_handle_ = handle->loop_next; - - handle->loop_cb(handle, 0); - } -} - - -int uv_prepare_init(uv_prepare_t* handle) { - uv_counters()->handle_init++; - uv_counters()->prepare_init++; - handle->type = UV_PREPARE; - return uv_loop_init((uv_handle_t*)handle); -} - - -int uv_check_init(uv_check_t* handle) { - uv_counters()->handle_init++; - uv_counters()->check_init++; - handle->type = UV_CHECK; - return uv_loop_init((uv_handle_t*)handle); -} - - -int uv_idle_init(uv_idle_t* handle) { - uv_counters()->handle_init++; - uv_counters()->idle_init++; - handle->type = UV_IDLE; - return uv_loop_init((uv_handle_t*)handle); -} - - -int uv_prepare_start(uv_prepare_t* handle, uv_loop_cb loop_cb) { - assert(handle->type == UV_PREPARE); - return uv_loop_start((uv_handle_t*)handle, loop_cb, &uv_prepare_handles_); -} - - -int uv_check_start(uv_check_t* handle, uv_loop_cb loop_cb) { - assert(handle->type == UV_CHECK); - return uv_loop_start((uv_handle_t*)handle, loop_cb, &uv_check_handles_); -} - - -int uv_idle_start(uv_idle_t* handle, uv_loop_cb loop_cb) { - assert(handle->type == UV_IDLE); - return uv_loop_start((uv_handle_t*)handle, loop_cb, &uv_idle_handles_); -} - - -int uv_prepare_stop(uv_prepare_t* handle) { - assert(handle->type == UV_PREPARE); - return uv_loop_stop((uv_handle_t*)handle, &uv_prepare_handles_); -} - - -int uv_check_stop(uv_check_t* handle) { - assert(handle->type == UV_CHECK); - return uv_loop_stop((uv_handle_t*)handle, &uv_check_handles_); -} - - -int uv_idle_stop(uv_idle_t* handle) { - assert(handle->type == UV_IDLE); - return uv_loop_stop((uv_handle_t*)handle, &uv_idle_handles_); -} +UV_LOOP_WATCHER_DEFINE(prepare, PREPARE) +UV_LOOP_WATCHER_DEFINE(check, CHECK) +UV_LOOP_WATCHER_DEFINE(idle, IDLE) int uv_is_active(uv_handle_t* handle) { @@ -1552,7 +1688,7 @@ static void uv_async_return_req(uv_async_t* handle, uv_req_t* req) { handle->async_sent = 0; if (req->cb) { - ((uv_async_cb)req->cb)((uv_handle_t*)handle, 0); + ((uv_async_cb)req->cb)((uv_async_t*) handle, 0); } if (handle->flags & UV_HANDLE_CLOSING) { uv_want_endgame((uv_handle_t*)handle); @@ -1576,6 +1712,18 @@ static void uv_process_reqs() { uv_async_return_req((uv_async_t*)handle, req); break; + case UV_ARES: + uv_ares_process((uv_ares_action_t*)handle, req); + break; + + case UV_ARES_TASK: + uv_ares_task_cleanup((uv_ares_task_t*)handle, req); + break; + + case UV_GETADDRINFO: + uv_getaddrinfo_done((uv_getaddrinfo_t*)handle, req); + break; + default: assert(0); } @@ -1606,7 +1754,7 @@ static void uv_process_timers() { timer->flags &= ~UV_HANDLE_ACTIVE; } - timer->timer_cb((uv_handle_t*) timer, 0); + timer->timer_cb((uv_timer_t*) timer, 0); } } @@ -1687,18 +1835,18 @@ int uv_run() { } /* Call idle callbacks */ - uv_loop_invoke(uv_idle_handles_); + uv_idle_invoke(); } if (uv_refs_ <= 0) { break; } - uv_loop_invoke(uv_prepare_handles_); + uv_prepare_invoke(); uv_poll(); - uv_loop_invoke(uv_check_handles_); + uv_check_invoke(); } assert(uv_refs_ == 0); @@ -1720,8 +1868,12 @@ int uv_utf16_to_utf8(wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, s return WideCharToMultiByte(CP_UTF8, 0, utf16Buffer, utf16Size, utf8Buffer, utf8Size, NULL, NULL); } +int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size) { + return MultiByteToWideChar(CP_UTF8, 0, utf8Buffer, -1, utf16Buffer, utf16Size); +} -int uv_get_exepath(char* buffer, size_t* size) { + +int uv_exepath(char* buffer, size_t* size) { int retVal; size_t utf16Size; wchar_t* utf16Buffer; @@ -1764,3 +1916,540 @@ done: return retVal; } + + +uint64_t uv_hrtime(void) { + assert(0 && "implement me"); +} + + +/* thread pool callback when socket is signalled */ +VOID CALLBACK uv_ares_socksignal_tp(void* parameter, BOOLEAN timerfired) { + WSANETWORKEVENTS network_events; + uv_ares_task_t* sockhandle; + uv_ares_action_t* selhandle; + uv_req_t* uv_ares_req; + + assert(parameter != NULL); + + if (parameter != NULL) { + sockhandle = (uv_ares_task_t*)parameter; + + /* clear socket status for this event */ + /* do not fail if error, thread may run after socket close */ + /* The code assumes that c-ares will write all pending data in the callback, + unless the socket would block. We can clear the state here to avoid unecessary + signals. */ + WSAEnumNetworkEvents(sockhandle->sock, sockhandle->h_event, &network_events); + + /* setup new handle */ + selhandle = (uv_ares_action_t*)malloc(sizeof(uv_ares_action_t)); + if (selhandle == NULL) { + uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); + } + selhandle->type = UV_ARES; + selhandle->close_cb = NULL; + selhandle->data = sockhandle->data; + selhandle->sock = sockhandle->sock; + selhandle->read = (network_events.lNetworkEvents & (FD_READ | FD_CONNECT)) ? 1 : 0; + selhandle->write = (network_events.lNetworkEvents & (FD_WRITE | FD_CONNECT)) ? 1 : 0; + + uv_ares_req = &selhandle->ares_req; + uv_req_init(uv_ares_req, (uv_handle_t*)selhandle, NULL); + uv_ares_req->type = UV_WAKEUP; + + /* post ares needs to called */ + if (!PostQueuedCompletionStatus(uv_iocp_, + 0, + 0, + &uv_ares_req->overlapped)) { + uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); + } + } +} + +/* callback from ares when socket operation is started */ +void uv_ares_sockstate_cb(void *data, ares_socket_t sock, int read, int write) { + /* look to see if we have a handle for this socket in our list */ + uv_ares_task_t* uv_handle_ares = uv_find_ares_handle(sock); + uv_ares_channel_t* uv_ares_data_ptr = (uv_ares_channel_t*)data; + + struct timeval tv; + struct timeval* tvptr; + int timeoutms = 0; + + if (read == 0 && write == 0) { + /* if read and write are 0, cleanup existing data */ + /* The code assumes that c-ares does a callback with read = 0 and write = 0 + when the socket is closed. After we recieve this we stop monitoring the socket. */ + if (uv_handle_ares != NULL) { + uv_req_t* uv_ares_req; + + uv_handle_ares->h_close_event = CreateEvent(NULL, FALSE, FALSE, NULL); + /* remove Wait */ + if (uv_handle_ares->h_wait) { + UnregisterWaitEx(uv_handle_ares->h_wait, uv_handle_ares->h_close_event); + uv_handle_ares->h_wait = NULL; + } + + /* detach socket from the event */ + WSAEventSelect(sock, NULL, 0); + if (uv_handle_ares->h_event != WSA_INVALID_EVENT) { + WSACloseEvent(uv_handle_ares->h_event); + uv_handle_ares->h_event = WSA_INVALID_EVENT; + } + /* remove handle from list */ + uv_remove_ares_handle(uv_handle_ares); + + /* Post request to cleanup the Task */ + uv_ares_req = &uv_handle_ares->ares_req; + uv_req_init(uv_ares_req, (uv_handle_t*)uv_handle_ares, NULL); + uv_ares_req->type = UV_WAKEUP; + + /* post ares done with socket - finish cleanup when all threads done. */ + if (!PostQueuedCompletionStatus(uv_iocp_, + 0, + 0, + &uv_ares_req->overlapped)) { + uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); + } + } else { + assert(0); + uv_fatal_error(ERROR_INVALID_DATA, "ares_SockStateCB"); + } + } else { + if (uv_handle_ares == NULL) { + /* setup new handle */ + /* The code assumes that c-ares will call us when it has an open socket. + We need to call into c-ares when there is something to read, + or when it becomes writable. */ + uv_handle_ares = (uv_ares_task_t*)malloc(sizeof(uv_ares_task_t)); + if (uv_handle_ares == NULL) { + uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); + } + uv_handle_ares->type = UV_ARES_TASK; + uv_handle_ares->close_cb = NULL; + uv_handle_ares->data = uv_ares_data_ptr; + uv_handle_ares->sock = sock; + uv_handle_ares->h_wait = NULL; + uv_handle_ares->flags = 0; + + /* create an event to wait on socket signal */ + uv_handle_ares->h_event = WSACreateEvent(); + if (uv_handle_ares->h_event == WSA_INVALID_EVENT) { + uv_fatal_error(WSAGetLastError(), "WSACreateEvent"); + } + + /* tie event to socket */ + if (SOCKET_ERROR == WSAEventSelect(sock, uv_handle_ares->h_event, FD_READ | FD_WRITE | FD_CONNECT)) { + uv_fatal_error(WSAGetLastError(), "WSAEventSelect"); + } + + /* add handle to list */ + uv_add_ares_handle(uv_handle_ares); + uv_refs_++; + + /* + * we have a single polling timer for all ares sockets. + * This is preferred to using ares_timeout. See ares_timeout.c warning. + * if timer is not running start it, and keep socket count + */ + if (uv_ares_data_ptr->activesockets == 0) { + uv_timer_init(&uv_ares_data_ptr->pollingtimer); + uv_timer_start(&uv_ares_data_ptr->pollingtimer, uv_ares_poll, 1000L, 1000L); + } + uv_ares_data_ptr->activesockets++; + + /* specify thread pool function to call when event is signaled */ + if (RegisterWaitForSingleObject(&uv_handle_ares->h_wait, + uv_handle_ares->h_event, + uv_ares_socksignal_tp, + (void*)uv_handle_ares, + INFINITE, + WT_EXECUTEINWAITTHREAD) == 0) { + uv_fatal_error(GetLastError(), "RegisterWaitForSingleObject"); + } + } else { + /* found existing handle. */ + assert(uv_handle_ares->type == UV_ARES_TASK); + assert(uv_handle_ares->data != NULL); + assert(uv_handle_ares->h_event != WSA_INVALID_EVENT); + } + } +} + +/* called via uv_poll when ares completion port signaled */ +void uv_ares_process(uv_ares_action_t* handle, uv_req_t* req) { + uv_ares_channel_t* uv_ares_data_ptr = (uv_ares_channel_t*)handle->data; + + ares_process_fd(uv_ares_data_ptr->channel, + handle->read ? handle->sock : INVALID_SOCKET, + handle->write ? handle->sock : INVALID_SOCKET); + + /* release handle for select here */ + free(handle); +} + +/* called via uv_poll when ares is finished with socket */ +void uv_ares_task_cleanup(uv_ares_task_t* handle, uv_req_t* req) { + /* check for event complete without waiting */ + unsigned int signaled = WaitForSingleObject(handle->h_close_event, 0); + + if (signaled != WAIT_TIMEOUT) { + uv_ares_channel_t* uv_ares_data_ptr = (uv_ares_channel_t*)handle->data; + + uv_refs_--; + + /* close event handle and free uv handle memory */ + CloseHandle(handle->h_close_event); + free(handle); + + /* decrement active count. if it becomes 0 stop polling */ + if (uv_ares_data_ptr->activesockets > 0) { + uv_ares_data_ptr->activesockets--; + if (uv_ares_data_ptr->activesockets == 0) { + uv_close((uv_handle_t*)&uv_ares_data_ptr->pollingtimer, NULL); + } + } + } else { + /* stil busy - repost and try again */ + if (!PostQueuedCompletionStatus(uv_iocp_, + 0, + 0, + &req->overlapped)) { + uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); + } + } +} + +/* periodically call ares to check for timeouts */ +void uv_ares_poll(uv_timer_t* handle, int status) { + if (uv_ares_data.channel != NULL && uv_ares_data.activesockets > 0) { + ares_process_fd(uv_ares_data.channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + } +} + + +/* set ares SOCK_STATE callback to our handler */ +int uv_ares_init_options(ares_channel *channelptr, + struct ares_options *options, + int optmask) { + int rc; + + /* only allow single init at a time */ + if (uv_ares_data.channel != NULL) { + return UV_EALREADY; + } + + /* set our callback as an option */ + options->sock_state_cb = uv_ares_sockstate_cb; + options->sock_state_cb_data = &uv_ares_data; + optmask |= ARES_OPT_SOCK_STATE_CB; + + /* We do the call to ares_init_option for caller. */ + rc = ares_init_options(channelptr, options, optmask); + + /* if success, save channel */ + if (rc == ARES_SUCCESS) { + uv_ares_data.channel = *channelptr; + } + + return rc; +} + + +/* release memory */ +void uv_ares_destroy(ares_channel channel) { + /* only allow destroy if did init */ + if (uv_ares_data.channel != NULL) { + ares_destroy(channel); + uv_ares_data.channel = NULL; + } +} + + +/* + * getaddrinfo error code mapping + * Falls back to uv_translate_sys_error if no match + */ + +static uv_err_code uv_translate_eai_error(int eai_errno) { + switch (eai_errno) { + case ERROR_SUCCESS: return UV_OK; + case EAI_BADFLAGS: return UV_EBADF; + case EAI_FAIL: return UV_EFAULT; + case EAI_FAMILY: return UV_EAIFAMNOSUPPORT; + case EAI_MEMORY: return UV_ENOMEM; + case EAI_NONAME: return UV_EAINONAME; + case EAI_AGAIN: return UV_EAGAIN; + case EAI_SERVICE: return UV_EAISERVICE; + case EAI_SOCKTYPE: return UV_EAISOCKTYPE; + default: return uv_translate_sys_error(eai_errno); + } +} + + +/* getaddrinfo worker thread implementation */ +static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) { + uv_getaddrinfo_t* handle = (uv_getaddrinfo_t*)parameter; + int ret; + + assert(handle != NULL); + + if (handle != NULL) { + /* call OS function on this thread */ + ret = GetAddrInfoW(handle->node, handle->service, handle->hints, &handle->res); + handle->retcode = ret; + + /* post getaddrinfo completed */ + if (!PostQueuedCompletionStatus(uv_iocp_, + 0, + 0, + &handle->getadddrinfo_req.overlapped)) { + uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); + } + } + + return 0; +} + + +/* + * Called from uv_run when complete. Call user specified callback + * then free returned addrinfo + * Returned addrinfo strings are converted from UTF-16 to UTF-8. + * + * To minimize allocation we calculate total size required, + * and copy all structs and referenced strings into the one block. + * Each size calculation is adjusted to avoid unaligned pointers. + */ +static void uv_getaddrinfo_done(uv_getaddrinfo_t* handle, uv_req_t* req) { + int addrinfo_len = 0; + int name_len = 0; + size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo)); + struct addrinfoW* addrinfow_ptr; + struct addrinfo* addrinfo_ptr; + char* alloc_ptr = NULL; + char* cur_ptr = NULL; + uv_err_code uv_ret; + + /* release input parameter memory */ + if (handle->alloc != NULL) { + free(handle->alloc); + handle->alloc = NULL; + } + + uv_ret = uv_translate_eai_error(handle->retcode); + if (handle->retcode == 0) { + /* convert addrinfoW to addrinfo */ + /* first calculate required length */ + addrinfow_ptr = handle->res; + while (addrinfow_ptr != NULL) { + addrinfo_len += addrinfo_struct_len + ALIGNED_SIZE(addrinfow_ptr->ai_addrlen); + if (addrinfow_ptr->ai_canonname != NULL) { + name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0); + if (name_len == 0) { + uv_ret = uv_translate_sys_error(GetLastError()); + goto complete; + } + addrinfo_len += ALIGNED_SIZE(name_len); + } + addrinfow_ptr = addrinfow_ptr->ai_next; + } + + /* allocate memory for addrinfo results */ + alloc_ptr = (char*)malloc(addrinfo_len); + + /* do conversions */ + if (alloc_ptr != NULL) { + cur_ptr = alloc_ptr; + addrinfow_ptr = handle->res; + + while (addrinfow_ptr != NULL) { + /* copy addrinfo struct data */ + assert(cur_ptr + addrinfo_struct_len <= alloc_ptr + addrinfo_len); + addrinfo_ptr = (struct addrinfo*)cur_ptr; + addrinfo_ptr->ai_family = addrinfow_ptr->ai_family; + addrinfo_ptr->ai_socktype = addrinfow_ptr->ai_socktype; + addrinfo_ptr->ai_protocol = addrinfow_ptr->ai_protocol; + addrinfo_ptr->ai_flags = addrinfow_ptr->ai_flags; + addrinfo_ptr->ai_addrlen = addrinfow_ptr->ai_addrlen; + addrinfo_ptr->ai_canonname = NULL; + addrinfo_ptr->ai_addr = NULL; + addrinfo_ptr->ai_next = NULL; + + cur_ptr += addrinfo_struct_len; + + /* copy sockaddr */ + if (addrinfo_ptr->ai_addrlen > 0) { + assert(cur_ptr + addrinfo_ptr->ai_addrlen <= alloc_ptr + addrinfo_len); + memcpy(cur_ptr, addrinfow_ptr->ai_addr, addrinfo_ptr->ai_addrlen); + addrinfo_ptr->ai_addr = (struct sockaddr*)cur_ptr; + cur_ptr += ALIGNED_SIZE(addrinfo_ptr->ai_addrlen); + } + + /* convert canonical name to UTF-8 */ + if (addrinfow_ptr->ai_canonname != NULL) { + name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0); + assert(name_len > 0); + assert(cur_ptr + name_len <= alloc_ptr + addrinfo_len); + name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, cur_ptr, name_len); + assert(name_len > 0); + addrinfo_ptr->ai_canonname = cur_ptr; + cur_ptr += ALIGNED_SIZE(name_len); + } + assert(cur_ptr <= alloc_ptr + addrinfo_len); + + /* set next ptr */ + addrinfow_ptr = addrinfow_ptr->ai_next; + if (addrinfow_ptr != NULL) { + addrinfo_ptr->ai_next = (struct addrinfo*)cur_ptr; + } + } + } else { + uv_ret = UV_ENOMEM; + } + + } + + /* return memory to system */ + if (handle->res != NULL) { + FreeAddrInfoW(handle->res); + handle->res = NULL; + } + +complete: + /* finally do callback with converted result */ + handle->getaddrinfo_cb(handle, uv_ret, (struct addrinfo*)alloc_ptr); + + /* release copied result memory */ + if (alloc_ptr != NULL) { + free(alloc_ptr); + } + + uv_refs_--; +} + + +/* + * Entry point for getaddrinfo + * we convert the UTF-8 strings to UNICODE + * and save the UNICODE string pointers in the handle + * We also copy hints so that caller does not need to keep memory until the callback. + * return UV_OK if a callback will be made + * return error code if validation fails + * + * To minimize allocation we calculate total size required, + * and copy all structs and referenced strings into the one block. + * Each size calculation is adjusted to avoid unaligned pointers. + */ +int uv_getaddrinfo(uv_getaddrinfo_t* handle, + uv_getaddrinfo_cb getaddrinfo_cb, + const char* node, + const char* service, + const struct addrinfo* hints) { + int nodesize = 0; + int servicesize = 0; + int hintssize = 0; + char* alloc_ptr = NULL; + + if (handle == NULL || getaddrinfo_cb == NULL || + (node == NULL && service == NULL)) { + uv_set_sys_error(WSAEINVAL); + goto error; + } + + handle->getaddrinfo_cb = getaddrinfo_cb; + handle->res = NULL; + handle->type = UV_GETADDRINFO; + + /* calculate required memory size for all input values */ + if (node != NULL) { + nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(wchar_t)); + if (nodesize == 0) { + uv_set_sys_error(GetLastError()); + goto error; + } + } + + if (service != NULL) { + servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) * sizeof(wchar_t)); + if (servicesize == 0) { + uv_set_sys_error(GetLastError()); + goto error; + } + } + if (hints != NULL) { + hintssize = ALIGNED_SIZE(sizeof(struct addrinfoW)); + } + + /* allocate memory for inputs, and partition it as needed */ + alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize); + if (!alloc_ptr) { + uv_set_sys_error(WSAENOBUFS); + goto error; + } + + /* save alloc_ptr now so we can free if error */ + handle->alloc = (void*)alloc_ptr; + + /* convert node string to UTF16 into allocated memory and save pointer in handle */ + if (node != NULL) { + handle->node = (wchar_t*)alloc_ptr; + if (uv_utf8_to_utf16(node, (wchar_t*)alloc_ptr, nodesize / sizeof(wchar_t)) == 0) { + uv_set_sys_error(GetLastError()); + goto error; + } + alloc_ptr += nodesize; + } else { + handle->node = NULL; + } + + /* convert service string to UTF16 into allocated memory and save pointer in handle */ + if (service != NULL) { + handle->service = (wchar_t*)alloc_ptr; + if (uv_utf8_to_utf16(service, (wchar_t*)alloc_ptr, servicesize / sizeof(wchar_t)) == 0) { + uv_set_sys_error(GetLastError()); + goto error; + } + alloc_ptr += servicesize; + } else { + handle->service = NULL; + } + + /* copy hints to allocated memory and save pointer in handle */ + if (hints != NULL) { + handle->hints = (struct addrinfoW*)alloc_ptr; + handle->hints->ai_family = hints->ai_family; + handle->hints->ai_socktype = hints->ai_socktype; + handle->hints->ai_protocol = hints->ai_protocol; + handle->hints->ai_flags = hints->ai_flags; + handle->hints->ai_addrlen = 0; + handle->hints->ai_canonname = NULL; + handle->hints->ai_addr = NULL; + handle->hints->ai_next = NULL; + } else { + handle->hints = NULL; + } + + /* init request for Post handling */ + uv_req_init(&handle->getadddrinfo_req, (uv_handle_t*)handle, NULL); + handle->getadddrinfo_req.type = UV_WAKEUP; + + /* Ask thread to run. Treat this as a long operation */ + if (QueueUserWorkItem(&getaddrinfo_thread_proc, handle, WT_EXECUTELONGFUNCTION) == 0) { + uv_set_sys_error(GetLastError()); + goto error; + } + + uv_refs_++; + + return 0; + +error: + if (handle != NULL && handle->alloc != NULL) { + free(handle->alloc); + } + return -1; +} + diff --git a/src/rt/libuv/test/benchmark-ares.c b/src/rt/libuv/test/benchmark-ares.c new file mode 100644 index 00000000000..c3f538bff95 --- /dev/null +++ b/src/rt/libuv/test/benchmark-ares.c @@ -0,0 +1,116 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + +#include +#include +#include /* strlen */ + +ares_channel channel; +struct ares_options options; +int optmask; + +struct in_addr testsrv; + +int ares_callbacks; +int ares_errors; +int argument; + +#define NUM_CALLS_TO_START 1000 + +static int64_t start_time; +static int64_t end_time; + +/* callback method. may issue another call */ +static void aresbynamecallback( void *arg, + int status, + int timeouts, + struct hostent *hostent) { + ares_callbacks++; + if (status != 0) { + ares_errors++; + } + +} + + +static void prep_tcploopback() +{ + /* for test, use echo server - TCP port TEST_PORT on loopback */ + struct sockaddr_in test_server = uv_ip4_addr("127.0.0.1", 0); + int rc = 0; + optmask = 0; + + optmask = ARES_OPT_SERVERS | ARES_OPT_TCP_PORT | ARES_OPT_FLAGS; + options.servers = &test_server.sin_addr; + options.nservers = 1; + options.tcp_port = htons(TEST_PORT_2); + options.flags = ARES_FLAG_USEVC; + + rc = uv_ares_init_options(&channel, &options, optmask); + + ASSERT(rc == ARES_SUCCESS); +} + + +BENCHMARK_IMPL(gethostbyname) { + + int rc = 0; + int ares_start;; + + rc = ares_library_init(ARES_LIB_INIT_ALL); + if (rc != 0) { + printf("ares library init fails %d\n", rc); + return 1; + } + + uv_init(); + ares_callbacks = 0; + ares_errors = 0; + + uv_update_time(); + start_time = uv_now(); + + prep_tcploopback(); + + for (ares_start = 0; ares_start < NUM_CALLS_TO_START; ares_start++) { + ares_gethostbyname(channel, + "echos.srv", + AF_INET, + &aresbynamecallback, + &argument); + } + + uv_run(); + + uv_ares_destroy(channel); + + end_time = uv_now(); + + if (ares_errors > 0) { + printf("There were %d failures\n", ares_errors); + } + LOGF("ares_gethostbyname: %d calls in %d ms \n", ares_callbacks, (int) (end_time - start_time)); + + return 0; +} diff --git a/src/rt/libuv/test/benchmark-getaddrinfo.c b/src/rt/libuv/test/benchmark-getaddrinfo.c new file mode 100644 index 00000000000..ba859c3c82e --- /dev/null +++ b/src/rt/libuv/test/benchmark-getaddrinfo.c @@ -0,0 +1,92 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + +#include +#include +#include /* strlen */ + + +#define CONCURRENT_CALLS 10 +#define TOTAL_CALLS 10000 + +const char* name = "localhost"; + +static uv_getaddrinfo_t handles[CONCURRENT_CALLS]; + +static int calls_initiated = 0; +static int calls_completed = 0; +static int64_t start_time; +static int64_t end_time; + + +static void getaddrinfo_initiate(uv_getaddrinfo_t* handle); + + +static void getaddrinfo_cb(uv_getaddrinfo_t* handle, int status, + struct addrinfo* res) { + ASSERT(status == 0); + calls_completed++; + if (calls_initiated < TOTAL_CALLS) { + getaddrinfo_initiate(handle); + } +} + + +static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) { + int r; + + calls_initiated++; + + r = uv_getaddrinfo(handle, &getaddrinfo_cb, name, NULL, NULL); + ASSERT(r == 0); +} + + +BENCHMARK_IMPL(getaddrinfo) { + int i; + + uv_init(); + + uv_update_time(); + start_time = uv_now(); + + for (i = 0; i < CONCURRENT_CALLS; i++) { + getaddrinfo_initiate(&handles[i]); + } + + uv_run(); + + uv_update_time(); + end_time = uv_now(); + + ASSERT(calls_initiated == TOTAL_CALLS); + ASSERT(calls_completed == TOTAL_CALLS); + + LOGF("getaddrinfo: %d calls in %d ms (%.0f requests/second)\n", + calls_completed, + (int) (end_time - start_time), + (double) calls_completed / (double) (end_time - start_time) * 1000.0); + + return 0; +} diff --git a/src/rt/libuv/test/benchmark-list.h b/src/rt/libuv/test/benchmark-list.h index 33ef97e260e..6040e90a326 100644 --- a/src/rt/libuv/test/benchmark-list.h +++ b/src/rt/libuv/test/benchmark-list.h @@ -23,8 +23,11 @@ BENCHMARK_DECLARE (sizes) BENCHMARK_DECLARE (ping_pongs) BENCHMARK_DECLARE (pump100_client) BENCHMARK_DECLARE (pump1_client) +BENCHMARK_DECLARE (gethostbyname) +BENCHMARK_DECLARE (getaddrinfo) HELPER_DECLARE (pump_server) HELPER_DECLARE (echo_server) +HELPER_DECLARE (dns_server) TASK_LIST_START BENCHMARK_ENTRY (sizes) @@ -37,4 +40,9 @@ TASK_LIST_START BENCHMARK_ENTRY (pump1_client) BENCHMARK_HELPER (pump1_client, pump_server) + + BENCHMARK_ENTRY (gethostbyname) + BENCHMARK_HELPER (gethostbyname, dns_server) + + BENCHMARK_ENTRY (getaddrinfo) TASK_LIST_END diff --git a/src/rt/libuv/test/benchmark-ping-pongs.c b/src/rt/libuv/test/benchmark-ping-pongs.c index 9b5543251cb..7124a3614a4 100644 --- a/src/rt/libuv/test/benchmark-ping-pongs.c +++ b/src/rt/libuv/test/benchmark-ping-pongs.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include @@ -52,7 +52,7 @@ static int completed_pingers = 0; static int64_t start_time; -static uv_buf_t buf_alloc(uv_tcp_t* tcp, size_t size) { +static uv_buf_t buf_alloc(uv_stream_t* tcp, size_t size) { buf_t* ab; ab = buf_freelist; @@ -125,7 +125,7 @@ static void pinger_shutdown_cb(uv_handle_t* handle, int status) { } -static void pinger_read_cb(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf) { +static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { unsigned int i; pinger_t* pinger; @@ -171,7 +171,7 @@ static void pinger_connect_cb(uv_req_t *req, int status) { pinger_write_ping(pinger); - if (uv_read_start((uv_tcp_t*)(req->handle), buf_alloc, pinger_read_cb)) { + if (uv_read_start((uv_stream_t*)(req->handle), buf_alloc, pinger_read_cb)) { FATAL("uv_read_start failed"); } } @@ -198,8 +198,8 @@ static void pinger_new() { uv_req_init(&pinger->connect_req, (uv_handle_t*)&pinger->tcp, pinger_connect_cb); - uv_bind(&pinger->tcp, client_addr); - r = uv_connect(&pinger->connect_req, server_addr); + uv_tcp_bind(&pinger->tcp, client_addr); + r = uv_tcp_connect(&pinger->connect_req, server_addr); ASSERT(!r); } diff --git a/src/rt/libuv/test/benchmark-pump.c b/src/rt/libuv/test/benchmark-pump.c index 8a8f52a79d0..cd9c7d99679 100644 --- a/src/rt/libuv/test/benchmark-pump.c +++ b/src/rt/libuv/test/benchmark-pump.c @@ -20,7 +20,7 @@ */ #include "task.h" -#include "../uv.h" +#include "uv.h" #include #include @@ -35,13 +35,13 @@ static int TARGET_CONNECTIONS; #define STATS_COUNT 5 -static void do_write(uv_tcp_t*); +static void do_write(uv_stream_t*); static void maybe_connect_some(); static uv_req_t* req_alloc(); static void req_free(uv_req_t* uv_req); -static uv_buf_t buf_alloc(uv_tcp_t*, size_t size); +static uv_buf_t buf_alloc(uv_stream_t*, size_t size); static void buf_free(uv_buf_t uv_buf_t); @@ -79,7 +79,7 @@ static double gbit(int64_t bytes, int64_t passed_ms) { } -static void show_stats(uv_handle_t *handle, int status) { +static void show_stats(uv_timer_t* handle, int status) { int64_t diff; #if PRINT_STATS @@ -154,7 +154,7 @@ static void start_stats_collection() { } -static void read_cb(uv_tcp_t* tcp, ssize_t bytes, uv_buf_t buf) { +static void read_cb(uv_stream_t* tcp, ssize_t bytes, uv_buf_t buf) { if (nrecv_total == 0) { ASSERT(start_time == 0); uv_update_time(); @@ -183,11 +183,11 @@ static void write_cb(uv_req_t *req, int status) { nsent += sizeof write_buffer; nsent_total += sizeof write_buffer; - do_write((uv_tcp_t*)req->handle); + do_write((uv_stream_t*)req->handle); } -static void do_write(uv_tcp_t* tcp) { +static void do_write(uv_stream_t* tcp) { uv_req_t* req; uv_buf_t buf; int r; @@ -221,7 +221,7 @@ static void connect_cb(uv_req_t* req, int status) { /* Yay! start writing */ for (i = 0; i < write_sockets; i++) { - do_write(&write_handles[i]); + do_write((uv_stream_t*)&write_handles[i]); } } } @@ -241,27 +241,27 @@ static void maybe_connect_some() { req = req_alloc(); uv_req_init(req, (uv_handle_t*)tcp, connect_cb); - r = uv_connect(req, connect_addr); + r = uv_tcp_connect(req, connect_addr); ASSERT(r == 0); } } -static void connection_cb(uv_tcp_t* s, int status) { +static void connection_cb(uv_handle_t* s, int status) { uv_tcp_t* tcp; int r; - ASSERT(&server == s); + ASSERT(&server == (uv_tcp_t*)s); ASSERT(status == 0); tcp = malloc(sizeof(uv_tcp_t)); uv_tcp_init(tcp); - r = uv_accept(s, tcp); + r = uv_accept(s, (uv_stream_t*)tcp); ASSERT(r == 0); - r = uv_read_start(tcp, buf_alloc, read_cb); + r = uv_read_start((uv_stream_t*)tcp, buf_alloc, read_cb); ASSERT(r == 0); read_sockets++; @@ -317,7 +317,7 @@ typedef struct buf_list_s { static buf_list_t* buf_freelist = NULL; -static uv_buf_t buf_alloc(uv_tcp_t* tcp, size_t size) { +static uv_buf_t buf_alloc(uv_stream_t* tcp, size_t size) { buf_list_t* buf; buf = buf_freelist; @@ -351,9 +351,9 @@ HELPER_IMPL(pump_server) { /* Server */ r = uv_tcp_init(&server); ASSERT(r == 0); - r = uv_bind(&server, listen_addr); + r = uv_tcp_bind(&server, listen_addr); ASSERT(r == 0); - r = uv_listen(&server, MAX_WRITE_HANDLES, connection_cb); + r = uv_tcp_listen(&server, MAX_WRITE_HANDLES, connection_cb); ASSERT(r == 0); uv_run(); diff --git a/src/rt/libuv/test/benchmark-sizes.c b/src/rt/libuv/test/benchmark-sizes.c index a5f573feec6..830de3a007c 100644 --- a/src/rt/libuv/test/benchmark-sizes.c +++ b/src/rt/libuv/test/benchmark-sizes.c @@ -20,16 +20,16 @@ */ #include "task.h" -#include "../uv.h" +#include "uv.h" BENCHMARK_IMPL(sizes) { - LOGF("uv_req_t: %lu bytes\n", sizeof(uv_req_t)); - LOGF("uv_tcp_t: %lu bytes\n", sizeof(uv_tcp_t)); - LOGF("uv_prepare_t: %lu bytes\n", sizeof(uv_prepare_t)); - LOGF("uv_check_t: %lu bytes\n", sizeof(uv_check_t)); - LOGF("uv_idle_t: %lu bytes\n", sizeof(uv_idle_t)); - LOGF("uv_async_t: %lu bytes\n", sizeof(uv_async_t)); - LOGF("uv_timer_t: %lu bytes\n", sizeof(uv_timer_t)); + LOGF("uv_req_t: %u bytes\n", (unsigned int) sizeof(uv_req_t)); + LOGF("uv_tcp_t: %u bytes\n", (unsigned int) sizeof(uv_tcp_t)); + LOGF("uv_prepare_t: %u bytes\n", (unsigned int) sizeof(uv_prepare_t)); + LOGF("uv_check_t: %u bytes\n", (unsigned int) sizeof(uv_check_t)); + LOGF("uv_idle_t: %u bytes\n", (unsigned int) sizeof(uv_idle_t)); + LOGF("uv_async_t: %u bytes\n", (unsigned int) sizeof(uv_async_t)); + LOGF("uv_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t)); return 0; } diff --git a/src/rt/libuv/test/dns-server.c b/src/rt/libuv/test/dns-server.c new file mode 100644 index 00000000000..361c9d080ba --- /dev/null +++ b/src/rt/libuv/test/dns-server.c @@ -0,0 +1,325 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" +#include +#include +#include + + +typedef struct { + uv_req_t req; + uv_buf_t buf; +} write_req_t; + + +/* used to track multiple DNS requests received */ +typedef struct { + char* prevbuf_ptr; + int prevbuf_pos; + int prevbuf_rem; +} dnsstate; + + +/* modify handle to append dnsstate */ +typedef struct { + uv_tcp_t handle; + dnsstate state; +} dnshandle; + + +static int server_closed; +static uv_tcp_t server; + + +static void after_write(uv_req_t* req, int status); +static void after_read(uv_stream_t*, ssize_t nread, uv_buf_t buf); +static void on_close(uv_handle_t* peer); +static void on_server_close(uv_handle_t* handle); +static void on_connection(uv_handle_t*, int status); + +#define WRITE_BUF_LEN (64*1024) +#define DNSREC_LEN (4) + +#define LEN_OFFSET 0 +#define QUERYID_OFFSET 2 +unsigned char DNSRsp[] = {0, 43, 0, 0, 0x81, 0x80, 0, 1, 0, 1, 0, 0, 0, 0 }; +unsigned char qrecord[] = {5, 'e', 'c', 'h', 'o', 's', 3, 's', 'r', 'v', 0, 0, 1, 0, 1}; +unsigned char arecord[] = {0xc0, 0x0c, 0, 1, 0, 1, 0, 0, 5, 0xbd, 0, 4, 10, 0, 1, 1 }; + + +static void after_write(uv_req_t* req, int status) { + write_req_t* wr; + + if (status) { + uv_err_t err = uv_last_error(); + fprintf(stderr, "uv_write error: %s\n", uv_strerror(err)); + ASSERT(0); + } + + wr = (write_req_t*) req; + + /* Free the read/write buffer and the request */ + free(wr->buf.base); + free(wr); +} + + +static void after_shutdown(uv_req_t* req, int status) { + uv_close(req->handle, on_close); + free(req); +} + + +static void addrsp(write_req_t* wr, char* hdr) { + char * dnsrsp; + short int rsplen; + short int* reclen; + + rsplen = sizeof(DNSRsp) + sizeof(qrecord) + sizeof(arecord); + + ASSERT (rsplen + wr->buf.len < WRITE_BUF_LEN); + + dnsrsp = wr->buf.base + wr->buf.len; + + /* copy stock response */ + memcpy(dnsrsp, DNSRsp, sizeof(DNSRsp)); + memcpy(dnsrsp + sizeof(DNSRsp), qrecord, sizeof(qrecord)); + memcpy(dnsrsp + sizeof(DNSRsp) + sizeof(qrecord), arecord, sizeof(arecord)); + + /* overwrite with network order length and id from request header */ + reclen = (short int*)dnsrsp; + *reclen = htons(rsplen-2); + dnsrsp[QUERYID_OFFSET] = hdr[QUERYID_OFFSET]; + dnsrsp[QUERYID_OFFSET+1] = hdr[QUERYID_OFFSET+1]; + + wr->buf.len += rsplen; +} + +static void process_req(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { + write_req_t *wr; + dnshandle* dns = (dnshandle*)handle; + char hdrbuf[DNSREC_LEN]; + int hdrbuf_remaining = DNSREC_LEN; + int rec_remaining = 0; + int readbuf_remaining; + char* dnsreq; + char* hdrstart; + int usingprev = 0; + + wr = (write_req_t*) malloc(sizeof *wr); + uv_req_init(&wr->req, (uv_handle_t*)handle, after_write); + wr->buf.base = (char*)malloc(WRITE_BUF_LEN); + wr->buf.len = 0; + + if (dns->state.prevbuf_ptr != NULL) { + dnsreq = dns->state.prevbuf_ptr + dns->state.prevbuf_pos; + readbuf_remaining = dns->state.prevbuf_rem; + usingprev = 1; + } else { + dnsreq = buf.base; + readbuf_remaining = nread; + } + hdrstart = dnsreq; + + while (dnsreq != NULL) { + /* something to process */ + while (readbuf_remaining > 0) { + /* something to process in current buffer */ + if (hdrbuf_remaining > 0) { + /* process len and id */ + if (readbuf_remaining < hdrbuf_remaining) { + /* too little to get request header. save for next buffer */ + memcpy(&hdrbuf[DNSREC_LEN - hdrbuf_remaining], dnsreq, readbuf_remaining); + hdrbuf_remaining = DNSREC_LEN - readbuf_remaining; + break; + } else { + short int reclen_n; + /* save header */ + memcpy(&hdrbuf[DNSREC_LEN - hdrbuf_remaining], dnsreq, hdrbuf_remaining); + dnsreq += hdrbuf_remaining; + readbuf_remaining -= hdrbuf_remaining; + hdrbuf_remaining = 0; + + /* get record length */ + reclen_n = *((short int*)hdrbuf); + rec_remaining = ntohs(reclen_n) - (DNSREC_LEN - 2); + } + } + + if (rec_remaining <= readbuf_remaining) { + /* prepare reply */ + addrsp(wr, hdrbuf); + + /* move to next record */ + dnsreq += rec_remaining; + hdrstart = dnsreq; + readbuf_remaining -= rec_remaining; + rec_remaining = 0; + hdrbuf_remaining = DNSREC_LEN; + } else { + /* otherwise this buffer is done. */ + rec_remaining -= readbuf_remaining; + break; + } + } + + /* if we had to use bytes from prev buffer, start processing the current one */ + if (usingprev == 1) { + /* free previous buffer */ + free(dns->state.prevbuf_ptr); + dnsreq = buf.base; + readbuf_remaining = nread; + usingprev = 0; + } else { + dnsreq = NULL; + } + } + + /* send write buffer */ + if (wr->buf.len > 0) { + if (uv_write(&wr->req, &wr->buf, 1)) { + FATAL("uv_write failed"); + } + } + + if (readbuf_remaining > 0) { + /* save start of record position, so we can continue on next read */ + dns->state.prevbuf_ptr = buf.base; + dns->state.prevbuf_pos = hdrstart - buf.base; + dns->state.prevbuf_rem = nread - dns->state.prevbuf_pos; + } else { + /* nothing left in this buffer */ + dns->state.prevbuf_ptr = NULL; + dns->state.prevbuf_pos = 0; + dns->state.prevbuf_rem = 0; + free(buf.base); + } +} + +static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { + uv_req_t* req; + + if (nread < 0) { + /* Error or EOF */ + ASSERT (uv_last_error().code == UV_EOF); + + if (buf.base) { + free(buf.base); + } + + req = (uv_req_t*) malloc(sizeof *req); + uv_req_init(req, (uv_handle_t*)handle, after_shutdown); + uv_shutdown(req); + + return; + } + + if (nread == 0) { + /* Everything OK, but nothing read. */ + free(buf.base); + return; + } + /* process requests and send responses */ + process_req(handle, nread, buf); +} + + +static void on_close(uv_handle_t* peer) { + free(peer); +} + + +static uv_buf_t buf_alloc(uv_stream_t* handle, size_t suggested_size) { + uv_buf_t buf; + buf.base = (char*) malloc(suggested_size); + buf.len = suggested_size; + return buf; +} + + +static void on_connection(uv_handle_t* server, int status) { + dnshandle* handle; + int r; + + ASSERT(status == 0); + + handle = (dnshandle*) malloc(sizeof *handle); + ASSERT(handle != NULL); + + /* initialize read buffer state */ + handle->state.prevbuf_ptr = 0; + handle->state.prevbuf_pos = 0; + handle->state.prevbuf_rem = 0; + + uv_tcp_init((uv_tcp_t*)handle); + + r = uv_accept(server, (uv_stream_t*)handle); + ASSERT(r == 0); + + r = uv_read_start((uv_stream_t*)handle, buf_alloc, after_read); + ASSERT(r == 0); +} + + +static void on_server_close(uv_handle_t* handle) { + ASSERT(handle == (uv_handle_t*)&server); +} + + +static int dns_start(int port) { + struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", port); + int r; + + r = uv_tcp_init(&server); + if (r) { + /* TODO: Error codes */ + fprintf(stderr, "Socket creation error\n"); + return 1; + } + + r = uv_tcp_bind(&server, addr); + if (r) { + /* TODO: Error codes */ + fprintf(stderr, "Bind error\n"); + return 1; + } + + r = uv_tcp_listen(&server, 128, on_connection); + if (r) { + /* TODO: Error codes */ + fprintf(stderr, "Listen error\n"); + return 1; + } + + return 0; +} + + +HELPER_IMPL(dns_server) { + uv_init(); + if (dns_start(TEST_PORT_2)) + return 1; + + uv_run(); + return 0; +} diff --git a/src/rt/libuv/test/echo-server.c b/src/rt/libuv/test/echo-server.c index a3f8f29ed10..9addc546c1e 100644 --- a/src/rt/libuv/test/echo-server.c +++ b/src/rt/libuv/test/echo-server.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include #include @@ -34,12 +34,15 @@ typedef struct { static int server_closed; static uv_tcp_t server; +static int server6_closed; +static uv_tcp_t server6; + static void after_write(uv_req_t* req, int status); -static void after_read(uv_tcp_t*, ssize_t nread, uv_buf_t buf); +static void after_read(uv_stream_t*, ssize_t nread, uv_buf_t buf); static void on_close(uv_handle_t* peer); static void on_server_close(uv_handle_t* handle); -static void on_connection(uv_tcp_t*, int status); +static void on_connection(uv_handle_t*, int status); static void after_write(uv_req_t* req, int status) { @@ -65,7 +68,7 @@ static void after_shutdown(uv_req_t* req, int status) { } -static void after_read(uv_tcp_t* handle, ssize_t nread, uv_buf_t buf) { +static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { int i; write_req_t *wr; uv_req_t* req; @@ -79,7 +82,7 @@ static void after_read(uv_tcp_t* handle, ssize_t nread, uv_buf_t buf) { } req = (uv_req_t*) malloc(sizeof *req); - uv_req_init(req, (uv_handle_t*)handle, after_shutdown); + uv_req_init(req, (uv_handle_t*)handle, (void *(*)(void *))after_shutdown); uv_shutdown(req); return; @@ -97,13 +100,15 @@ static void after_read(uv_tcp_t* handle, ssize_t nread, uv_buf_t buf) { if (buf.base[i] == 'Q') { uv_close((uv_handle_t*)&server, on_server_close); server_closed = 1; + uv_close((uv_handle_t*)&server6, on_server_close); + server6_closed = 1; } } } wr = (write_req_t*) malloc(sizeof *wr); - uv_req_init(&wr->req, (uv_handle_t*)handle, after_write); + uv_req_init(&wr->req, (uv_handle_t*)handle, (void *(*)(void *))after_write); wr->buf.base = buf.base; wr->buf.len = nread; if (uv_write(&wr->req, &wr->buf, 1)) { @@ -117,7 +122,7 @@ static void on_close(uv_handle_t* peer) { } -static uv_buf_t echo_alloc(uv_tcp_t* handle, size_t suggested_size) { +static uv_buf_t echo_alloc(uv_stream_t* handle, size_t suggested_size) { uv_buf_t buf; buf.base = (char*) malloc(suggested_size); buf.len = suggested_size; @@ -125,10 +130,13 @@ static uv_buf_t echo_alloc(uv_tcp_t* handle, size_t suggested_size) { } -static void on_connection(uv_tcp_t* server, int status) { +static void on_connection(uv_handle_t* server, int status) { uv_tcp_t* handle; int r; + if (status != 0) { + fprintf(stderr, "Connect error %d\n", uv_last_error().code); + } ASSERT(status == 0); handle = (uv_tcp_t*) malloc(sizeof *handle); @@ -136,21 +144,25 @@ static void on_connection(uv_tcp_t* server, int status) { uv_tcp_init(handle); - r = uv_accept(server, handle); + /* associate server with stream */ + handle->data = server; + + r = uv_accept(server, (uv_stream_t*)handle); ASSERT(r == 0); - r = uv_read_start(handle, echo_alloc, after_read); + r = uv_read_start((uv_stream_t*)handle, echo_alloc, after_read); ASSERT(r == 0); } static void on_server_close(uv_handle_t* handle) { - ASSERT(handle == (uv_handle_t*)&server); + ASSERT(handle == (uv_handle_t*)&server || handle == (uv_handle_t*)&server6); } static int echo_start(int port) { struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", port); + struct sockaddr_in6 addr6 = uv_ip6_addr("::1", port); int r; r = uv_tcp_init(&server); @@ -160,20 +172,42 @@ static int echo_start(int port) { return 1; } - r = uv_bind(&server, addr); + r = uv_tcp_bind(&server, addr); if (r) { /* TODO: Error codes */ fprintf(stderr, "Bind error\n"); return 1; } - r = uv_listen(&server, 128, on_connection); + r = uv_tcp_listen(&server, 128, on_connection); if (r) { /* TODO: Error codes */ fprintf(stderr, "Listen error\n"); return 1; } + r = uv_tcp_init(&server6); + if (r) { + /* TODO: Error codes */ + fprintf(stderr, "Socket creation error\n"); + return 1; + } + + /* IPv6 is optional as not all platforms support it */ + r = uv_tcp_bind6(&server6, addr6); + if (r) { + /* show message but return OK */ + fprintf(stderr, "IPv6 not supported\n"); + return 0; + } + + r = uv_tcp_listen(&server6, 128, on_connection); + if (r) { + /* TODO: Error codes */ + fprintf(stderr, "Listen error on IPv6\n"); + return 1; + } + return 0; } diff --git a/src/rt/libuv/test/runner-unix.c b/src/rt/libuv/test/runner-unix.c index 139b671942f..fa4c63bb208 100644 --- a/src/rt/libuv/test/runner-unix.c +++ b/src/rt/libuv/test/runner-unix.c @@ -248,7 +248,7 @@ int process_copy_output(process_info_t *p, int fd) { return -1; } - size_t nread, nwritten; + ssize_t nread, nwritten; char buf[1024]; while ((nread = read(fileno(p->stdout_file), buf, 1024)) > 0) { @@ -331,5 +331,5 @@ int uv_wait_thread(uintptr_t thread_id) { /* Pause the calling thread for a number of milliseconds. */ void uv_sleep(int msec) { - usleep(msec); + usleep(msec * 1000); } diff --git a/src/rt/libuv/test/test-async.c b/src/rt/libuv/test/test-async.c index d820bf26f60..a9933fdcb14 100644 --- a/src/rt/libuv/test/test-async.c +++ b/src/rt/libuv/test/test-async.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include #include @@ -118,8 +118,8 @@ static void close_cb(uv_handle_t* handle) { } -static void async1_cb(uv_handle_t* handle, int status) { - ASSERT(handle == (uv_handle_t*)&async1_handle); +static void async1_cb(uv_async_t* handle, int status) { + ASSERT(handle == &async1_handle); ASSERT(status == 0); async1_cb_called++; @@ -127,7 +127,7 @@ static void async1_cb(uv_handle_t* handle, int status) { if (async1_cb_called > 2 && !async1_closed) { async1_closed = 1; - uv_close(handle, close_cb); + uv_close((uv_handle_t*)handle, close_cb); } } @@ -147,10 +147,10 @@ static void async2_cb(uv_handle_t* handle, int status) { #endif -static void prepare_cb(uv_handle_t* handle, int status) { +static void prepare_cb(uv_prepare_t* handle, int status) { int r; - ASSERT(handle == (uv_handle_t*)&prepare_handle); + ASSERT(handle == &prepare_handle); ASSERT(status == 0); switch (prepare_cb_called) { @@ -172,7 +172,7 @@ static void prepare_cb(uv_handle_t* handle, int status) { #endif case 1: - r = uv_close(handle, close_cb); + r = uv_close((uv_handle_t*)handle, close_cb); ASSERT(r == 0); break; diff --git a/src/rt/libuv/test/test-bind-error.c b/src/rt/libuv/test/test-bind-error.c index 587224acb92..4ac60654f6d 100644 --- a/src/rt/libuv/test/test-bind-error.c +++ b/src/rt/libuv/test/test-bind-error.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include #include @@ -43,17 +43,17 @@ TEST_IMPL(bind_error_addrinuse) { r = uv_tcp_init(&server1); ASSERT(r == 0); - r = uv_bind(&server1, addr); + r = uv_tcp_bind(&server1, addr); ASSERT(r == 0); r = uv_tcp_init(&server2); ASSERT(r == 0); - r = uv_bind(&server2, addr); + r = uv_tcp_bind(&server2, addr); ASSERT(r == 0); - r = uv_listen(&server1, 128, NULL); + r = uv_tcp_listen(&server1, 128, NULL); ASSERT(r == 0); - r = uv_listen(&server2, 128, NULL); + r = uv_tcp_listen(&server2, 128, NULL); ASSERT(r == -1); ASSERT(uv_last_error().code == UV_EADDRINUSE); @@ -78,7 +78,7 @@ TEST_IMPL(bind_error_addrnotavail_1) { r = uv_tcp_init(&server); ASSERT(r == 0); - r = uv_bind(&server, addr); + r = uv_tcp_bind(&server, addr); /* It seems that Linux is broken here - bind succeeds. */ if (r == -1) { @@ -104,7 +104,7 @@ TEST_IMPL(bind_error_addrnotavail_2) { r = uv_tcp_init(&server); ASSERT(r == 0); - r = uv_bind(&server, addr); + r = uv_tcp_bind(&server, addr); ASSERT(r == -1); ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL); @@ -130,7 +130,7 @@ TEST_IMPL(bind_error_fault) { r = uv_tcp_init(&server); ASSERT(r == 0); - r = uv_bind(&server, *garbage_addr); + r = uv_tcp_bind(&server, *garbage_addr); ASSERT(r == -1); ASSERT(uv_last_error().code == UV_EFAULT); @@ -156,9 +156,9 @@ TEST_IMPL(bind_error_inval) { r = uv_tcp_init(&server); ASSERT(r == 0); - r = uv_bind(&server, addr1); + r = uv_tcp_bind(&server, addr1); ASSERT(r == 0); - r = uv_bind(&server, addr2); + r = uv_tcp_bind(&server, addr2); ASSERT(r == -1); ASSERT(uv_last_error().code == UV_EINVAL); @@ -171,3 +171,20 @@ TEST_IMPL(bind_error_inval) { return 0; } + + +TEST_IMPL(bind_localhost_ok) { + struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); + + uv_tcp_t server; + int r; + + uv_init(); + + r = uv_tcp_init(&server); + ASSERT(r == 0); + r = uv_tcp_bind(&server, addr); + ASSERT(r == 0); + + return 0; +} diff --git a/src/rt/libuv/test/test-bind6-error.c b/src/rt/libuv/test/test-bind6-error.c new file mode 100644 index 00000000000..6072dcdc090 --- /dev/null +++ b/src/rt/libuv/test/test-bind6-error.c @@ -0,0 +1,164 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" +#include +#include + + +static int close_cb_called = 0; + + +static void close_cb(uv_handle_t* handle) { + ASSERT(handle != NULL); + close_cb_called++; +} + + +TEST_IMPL(bind6_error_addrinuse) { + struct sockaddr_in6 addr = uv_ip6_addr("::", TEST_PORT); + uv_tcp_t server1, server2; + int r; + + uv_init(); + + r = uv_tcp_init(&server1); + ASSERT(r == 0); + r = uv_tcp_bind6(&server1, addr); + ASSERT(r == 0); + + r = uv_tcp_init(&server2); + ASSERT(r == 0); + r = uv_tcp_bind6(&server2, addr); + ASSERT(r == 0); + + r = uv_tcp_listen(&server1, 128, NULL); + ASSERT(r == 0); + r = uv_tcp_listen(&server2, 128, NULL); + ASSERT(r == -1); + + ASSERT(uv_last_error().code == UV_EADDRINUSE); + + uv_close((uv_handle_t*)&server1, close_cb); + uv_close((uv_handle_t*)&server2, close_cb); + + uv_run(); + + ASSERT(close_cb_called == 2); + + return 0; +} + + +TEST_IMPL(bind6_error_addrnotavail) { + struct sockaddr_in6 addr = uv_ip6_addr("4:4:4:4:4:4:4:4", TEST_PORT); + uv_tcp_t server; + int r; + + uv_init(); + + r = uv_tcp_init(&server); + ASSERT(r == 0); + r = uv_tcp_bind6(&server, addr); + ASSERT(r == -1); + ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL); + + uv_close((uv_handle_t*)&server, close_cb); + + uv_run(); + + ASSERT(close_cb_called == 1); + + return 0; +} + + +TEST_IMPL(bind6_error_fault) { + char garbage[] = "blah blah blah blah blah blah blah blah blah blah blah blah"; + struct sockaddr_in6* garbage_addr; + uv_tcp_t server; + int r; + + garbage_addr = (struct sockaddr_in6*) &garbage; + + uv_init(); + + r = uv_tcp_init(&server); + ASSERT(r == 0); + r = uv_tcp_bind6(&server, *garbage_addr); + ASSERT(r == -1); + + ASSERT(uv_last_error().code == UV_EFAULT); + + uv_close((uv_handle_t*)&server, close_cb); + + uv_run(); + + ASSERT(close_cb_called == 1); + + return 0; +} + +/* Notes: On Linux uv_bind6(server, NULL) will segfault the program. */ + +TEST_IMPL(bind6_error_inval) { + struct sockaddr_in6 addr1 = uv_ip6_addr("::", TEST_PORT); + struct sockaddr_in6 addr2 = uv_ip6_addr("::", TEST_PORT_2); + uv_tcp_t server; + int r; + + uv_init(); + + r = uv_tcp_init(&server); + ASSERT(r == 0); + r = uv_tcp_bind6(&server, addr1); + ASSERT(r == 0); + r = uv_tcp_bind6(&server, addr2); + ASSERT(r == -1); + + ASSERT(uv_last_error().code == UV_EINVAL); + + uv_close((uv_handle_t*)&server, close_cb); + + uv_run(); + + ASSERT(close_cb_called == 1); + + return 0; +} + + +TEST_IMPL(bind6_localhost_ok) { + struct sockaddr_in6 addr = uv_ip6_addr("::1", TEST_PORT); + + uv_tcp_t server; + int r; + + uv_init(); + + r = uv_tcp_init(&server); + ASSERT(r == 0); + r = uv_tcp_bind6(&server, addr); + ASSERT(r == 0); + + return 0; +} diff --git a/src/rt/libuv/test/test-callback-stack.c b/src/rt/libuv/test/test-callback-stack.c index 5de5265be68..5b12c8b9b42 100644 --- a/src/rt/libuv/test/test-callback-stack.c +++ b/src/rt/libuv/test/test-callback-stack.c @@ -24,7 +24,7 @@ * stack. */ -#include "../uv.h" +#include "uv.h" #include "task.h" @@ -43,7 +43,7 @@ static int bytes_received = 0; static int shutdown_cb_called = 0; -static uv_buf_t alloc_cb(uv_tcp_t* tcp, size_t size) { +static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) { uv_buf_t buf; buf.len = size; buf.base = (char*) malloc(size); @@ -67,10 +67,10 @@ static void shutdown_cb(uv_req_t* req, int status) { } -static void read_cb(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf) { +static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { ASSERT(nested == 0 && "read_cb must be called from a fresh stack"); - printf("Read. nread == %d\n", nread); + printf("Read. nread == %d\n", (int)nread); free(buf.base); if (nread == 0) { @@ -97,7 +97,7 @@ static void read_cb(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf) { /* from a fresh stack. */ if (bytes_received == sizeof MESSAGE) { nested++; - uv_req_init(&shutdown_req, (uv_handle_t*)tcp, shutdown_cb); + uv_req_init(&shutdown_req, (uv_handle_t*)tcp, (void *(*)(void *))shutdown_cb); puts("Shutdown"); @@ -109,24 +109,24 @@ static void read_cb(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf) { } -static void timer_cb(uv_handle_t* handle, int status) { +static void timer_cb(uv_timer_t* handle, int status) { int r; - ASSERT(handle == (uv_handle_t*)&timer); + ASSERT(handle == &timer); ASSERT(status == 0); ASSERT(nested == 0 && "timer_cb must be called from a fresh stack"); puts("Timeout complete. Now read data..."); nested++; - if (uv_read_start(&client, alloc_cb, read_cb)) { + if (uv_read_start((uv_stream_t*)&client, alloc_cb, read_cb)) { FATAL("uv_read_start failed"); } nested--; timer_cb_called++; - r = uv_close(handle, close_cb); + r = uv_close((uv_handle_t*)handle, close_cb); ASSERT(r == 0); } @@ -167,7 +167,7 @@ static void connect_cb(uv_req_t* req, int status) { buf.base = (char*) &MESSAGE; buf.len = sizeof MESSAGE; - uv_req_init(&write_req, req->handle, write_cb); + uv_req_init(&write_req, req->handle, (void *(*)(void *))write_cb); if (uv_write(&write_req, &buf, 1)) { FATAL("uv_write failed"); @@ -191,9 +191,11 @@ TEST_IMPL(callback_stack) { puts("Connecting..."); nested++; - uv_req_init(&connect_req, (uv_handle_t*)&client, connect_cb); - if (uv_connect(&connect_req, addr)) { - FATAL("uv_connect failed"); + uv_req_init(&connect_req, (uv_handle_t*)&client, + (void *(*)(void *))connect_cb); + + if (uv_tcp_connect(&connect_req, addr)) { + FATAL("uv_tcp_connect failed"); } nested--; diff --git a/src/rt/libuv/test/test-connection-fail.c b/src/rt/libuv/test/test-connection-fail.c index fe765197488..9fc3f0ba6eb 100644 --- a/src/rt/libuv/test/test-connection-fail.c +++ b/src/rt/libuv/test/test-connection-fail.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include @@ -46,7 +46,7 @@ static void timer_close_cb(uv_handle_t* handle) { } -static void timer_cb(uv_handle_t* handle, int status) { +static void timer_cb(uv_timer_t* handle, int status) { ASSERT(status == 0); timer_cb_calls++; @@ -62,7 +62,7 @@ static void timer_cb(uv_handle_t* handle, int status) { uv_close((uv_handle_t*)&tcp, on_close); /* Close the timer. */ - uv_close(handle, timer_close_cb); + uv_close((uv_handle_t*)handle, timer_close_cb); } @@ -103,10 +103,10 @@ void connection_fail(uv_connect_cb connect_cb) { /* We are never doing multiple reads/connects at a time anyway. */ /* so these handles can be pre-initialized. */ - uv_req_init(&req, (uv_handle_t*)&tcp, connect_cb); + uv_req_init(&req, (uv_handle_t*)&tcp, (void *(*)(void *))connect_cb); - uv_bind(&tcp, client_addr); - r = uv_connect(&req, server_addr); + uv_tcp_bind(&tcp, client_addr); + r = uv_tcp_connect(&req, server_addr); ASSERT(!r); uv_run(); diff --git a/src/rt/libuv/test/test-delayed-accept.c b/src/rt/libuv/test/test-delayed-accept.c index f903f9907a5..eabf4818959 100644 --- a/src/rt/libuv/test/test-delayed-accept.c +++ b/src/rt/libuv/test/test-delayed-accept.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include #include @@ -32,7 +32,7 @@ static int close_cb_called = 0; static int connect_cb_called = 0; -static uv_buf_t alloc_cb(uv_tcp_t* tcp, size_t size) { +static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) { uv_buf_t buf; buf.base = (char*)malloc(size); buf.len = size; @@ -49,7 +49,7 @@ static void close_cb(uv_handle_t* handle) { } -static void do_accept(uv_handle_t* timer_handle, int status) { +static void do_accept(uv_timer_t* timer_handle, int status) { uv_tcp_t* server; uv_tcp_t* accepted_handle = (uv_tcp_t*)malloc(sizeof *accepted_handle); int r; @@ -65,7 +65,7 @@ static void do_accept(uv_handle_t* timer_handle, int status) { tcpcnt = uv_counters()->tcp_init; server = (uv_tcp_t*)timer_handle->data; - r = uv_accept(server, accepted_handle); + r = uv_accept((uv_handle_t*)server, (uv_stream_t*)accepted_handle); ASSERT(r == 0); ASSERT(uv_counters()->tcp_init == tcpcnt); @@ -83,12 +83,12 @@ static void do_accept(uv_handle_t* timer_handle, int status) { } /* Dispose the timer. */ - r = uv_close(timer_handle, close_cb); + r = uv_close((uv_handle_t*)timer_handle, close_cb); ASSERT(r == 0); } -static void connection_cb(uv_tcp_t* tcp, int status) { +static void connection_cb(uv_handle_t* tcp, int status) { int r; uv_timer_t* timer_handle; @@ -122,25 +122,30 @@ static void start_server() { ASSERT(uv_counters()->tcp_init == 1); ASSERT(uv_counters()->handle_init == 1); - r = uv_bind(server, addr); + r = uv_tcp_bind(server, addr); ASSERT(r == 0); - r = uv_listen(server, 128, connection_cb); + r = uv_tcp_listen(server, 128, connection_cb); ASSERT(r == 0); } -static void read_cb(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf) { +static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { /* The server will not send anything, it should close gracefully. */ - ASSERT(tcp != NULL); - ASSERT(nread == -1); - ASSERT(uv_last_error().code == UV_EOF); if (buf.base) { free(buf.base); } - uv_close((uv_handle_t*)tcp, close_cb); + if (nread != -1) { + ASSERT(nread == 0); + ASSERT(uv_last_error().code == UV_EAGAIN); + } else { + ASSERT(tcp != NULL); + ASSERT(nread == -1); + ASSERT(uv_last_error().code == UV_EOF); + uv_close((uv_handle_t*)tcp, close_cb); + } } @@ -152,7 +157,7 @@ static void connect_cb(uv_req_t* req, int status) { /* Not that the server will send anything, but otherwise we'll never know */ /* when te server closes the connection. */ - r = uv_read_start((uv_tcp_t*)(req->handle), alloc_cb, read_cb); + r = uv_read_start((uv_stream_t*)(req->handle), alloc_cb, read_cb); ASSERT(r == 0); connect_cb_called++; @@ -173,8 +178,8 @@ static void client_connect() { r = uv_tcp_init(client); ASSERT(r == 0); - uv_req_init(connect_req, (uv_handle_t*)client, connect_cb); - r = uv_connect(connect_req, addr); + uv_req_init(connect_req, (uv_handle_t*)client, (void *(*)(void *))connect_cb); + r = uv_tcp_connect(connect_req, addr); ASSERT(r == 0); } diff --git a/src/rt/libuv/test/test-get-currentexe.c b/src/rt/libuv/test/test-get-currentexe.c index 880d9cd6d0f..1dc85565590 100644 --- a/src/rt/libuv/test/test-get-currentexe.c +++ b/src/rt/libuv/test/test-get-currentexe.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include @@ -33,20 +33,20 @@ TEST_IMPL(get_currentexe) { int r; size = sizeof(buffer) / sizeof(buffer[0]); - r = uv_get_exepath(buffer, &size); + r = uv_exepath(buffer, &size); ASSERT(!r); match = strstr(buffer, executable_path); - /* Verify that the path returned from uv_get_exepath is a subdirectory of executable_path */ + /* Verify that the path returned from uv_exepath is a subdirectory of executable_path */ ASSERT(match && !strcmp(match, executable_path)); ASSERT(size == strlen(buffer)); /* Negative tests */ size = sizeof(buffer) / sizeof(buffer[0]); - r = uv_get_exepath(NULL, &size); + r = uv_exepath(NULL, &size); ASSERT(r == -1); - r = uv_get_exepath(buffer, NULL); + r = uv_exepath(buffer, NULL); ASSERT(r == -1); return 0; diff --git a/src/rt/libuv/test/test-getaddrinfo.c b/src/rt/libuv/test/test-getaddrinfo.c new file mode 100644 index 00000000000..a33e3d075cc --- /dev/null +++ b/src/rt/libuv/test/test-getaddrinfo.c @@ -0,0 +1,110 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + +#include +#include +#include /* strlen */ + + +#define CONCURRENT_COUNT 10 + +static const char* name = "localhost"; + +static uv_getaddrinfo_t getaddrinfo_handle; +static int getaddrinfo_cbs = 0; + +/* data used for running multiple calls concurrently */ +static uv_getaddrinfo_t getaddrinfo_handles[CONCURRENT_COUNT]; +static int callback_counts[CONCURRENT_COUNT]; + + +static void getaddrinfo_basic_cb(uv_getaddrinfo_t* handle, + int status, + struct addrinfo* res) { + ASSERT(handle == &getaddrinfo_handle); + getaddrinfo_cbs++; +} + + +static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle, + int status, + struct addrinfo* res) { + int i; + + for (i = 0; i < CONCURRENT_COUNT; i++) { + if (&getaddrinfo_handles[i] == handle) { + callback_counts[i]++; + break; + } + } + ASSERT (i < CONCURRENT_COUNT); + + getaddrinfo_cbs++; +} + + +TEST_IMPL(getaddrinfo_basic) { + int r; + + uv_init(); + + r = uv_getaddrinfo(&getaddrinfo_handle, + &getaddrinfo_basic_cb, + name, + NULL, + NULL); + ASSERT(r == 0); + + uv_run(); + + ASSERT(getaddrinfo_cbs == 1); + + return 0; +} + + +TEST_IMPL(getaddrinfo_concurrent) { + int i, r; + + uv_init(); + + for (i = 0; i < CONCURRENT_COUNT; i++) { + callback_counts[i] = 0; + + r = uv_getaddrinfo(&getaddrinfo_handles[i], + &getaddrinfo_cuncurrent_cb, + name, + NULL, + NULL); + ASSERT(r == 0); + } + + uv_run(); + + for (i = 0; i < CONCURRENT_COUNT; i++) { + ASSERT(callback_counts[i] == 1); + } + + return 0; +} diff --git a/src/rt/libuv/test/test-gethostbyname.c b/src/rt/libuv/test/test-gethostbyname.c new file mode 100644 index 00000000000..cbd25343bbb --- /dev/null +++ b/src/rt/libuv/test/test-gethostbyname.c @@ -0,0 +1,192 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + +#include +#include +#include /* strlen */ + +ares_channel channel; +struct ares_options options; +int optmask; + +int ares_bynamecallbacks; +int bynamecallbacksig; +int ares_byaddrcallbacks; +int byaddrcallbacksig; + +static void aresbynamecallback( void *arg, + int status, + int timeouts, + struct hostent *hostent) { + int * iargs; + ASSERT(arg != NULL); + iargs = (int*)arg; + ASSERT(*iargs == bynamecallbacksig); + ASSERT(timeouts == 0); + + printf("aresbynamecallback %d\n", ares_bynamecallbacks++); +} + + +static void aresbyaddrcallback( void *arg, + int status, + int timeouts, + struct hostent *hostent) { + int * iargs; + ASSERT(arg != NULL); + iargs = (int*)arg; + ASSERT(*iargs == byaddrcallbacksig); + ASSERT(timeouts == 0); + + printf("aresbyaddrcallback %d\n", ares_byaddrcallbacks++); +} + + +static void prep_tcploopback() { + /* for test, use echo server - TCP port TEST_PORT on loopback */ + struct sockaddr_in test_server = uv_ip4_addr("127.0.0.1", 0); + int rc; + + optmask = ARES_OPT_SERVERS | ARES_OPT_TCP_PORT | ARES_OPT_FLAGS; + options.servers = &test_server.sin_addr; + options.nservers = 1; + options.tcp_port = htons(TEST_PORT); + options.flags = ARES_FLAG_USEVC; + + rc = uv_ares_init_options(&channel, &options, optmask); + + ASSERT(rc == ARES_SUCCESS); +} + + +TEST_IMPL(gethostbyname) { + + int rc = 0; + char addr[4]; + + rc = ares_library_init(ARES_LIB_INIT_ALL); + if (rc != 0) { + printf("ares library init fails %d\n", rc); + return 1; + } + + uv_init(); + + printf("Start basic gethostbyname test\n"); + prep_tcploopback(); + + ares_bynamecallbacks = 0; + bynamecallbacksig = 7; + + ares_gethostbyname(channel, + "microsoft.com", + AF_INET, + &aresbynamecallback, + &bynamecallbacksig); + uv_run(); + + ASSERT(ares_bynamecallbacks == 1); + + uv_ares_destroy(channel); + printf("Done basic gethostbyname test\n"); + + + /* two sequential call on new channel */ + + printf("Start gethostbyname and gethostbyaddr sequential test\n"); + prep_tcploopback(); + + ares_bynamecallbacks = 0; + bynamecallbacksig = 7; + + ares_gethostbyname(channel, + "microsoft.com", + AF_INET, + &aresbynamecallback, + &bynamecallbacksig); + uv_run(); + + ASSERT(ares_bynamecallbacks == 1); + + ares_byaddrcallbacks = 0; + byaddrcallbacksig = 8; + addr[0] = 10; + addr[1] = 0; + addr[2] = 1; + addr[3] = 99; + + ares_gethostbyaddr(channel, + addr, + 4, + AF_INET, + &aresbyaddrcallback, + &byaddrcallbacksig); + + uv_run(); + + ASSERT(ares_byaddrcallbacks == 1); + + uv_ares_destroy(channel); + printf("Done gethostbyname and gethostbyaddr sequential test\n"); + + + /* two simultaneous calls on new channel */ + + printf("Start gethostbyname and gethostbyaddr concurrent test\n"); + prep_tcploopback(); + + ares_bynamecallbacks = 0; + bynamecallbacksig = 7; + + ares_gethostbyname(channel, + "microsoft.com", + AF_INET, + &aresbynamecallback, + &bynamecallbacksig); + + ares_byaddrcallbacks = 0; + byaddrcallbacksig = 8; + addr[0] = 10; + addr[1] = 0; + addr[2] = 1; + addr[3] = 99; + + ares_gethostbyaddr(channel, + addr, + 4, + AF_INET, + &aresbyaddrcallback, + &byaddrcallbacksig); + + uv_run(); + + ASSERT(ares_bynamecallbacks == 1); + ASSERT(ares_byaddrcallbacks == 1); + + + uv_ares_destroy(channel); + printf("Done gethostbyname and gethostbyaddr concurrent test\n"); + + return 0; +} diff --git a/src/rt/libuv/test/test-hrtime.c b/src/rt/libuv/test/test-hrtime.c new file mode 100644 index 00000000000..4d96e3331ec --- /dev/null +++ b/src/rt/libuv/test/test-hrtime.c @@ -0,0 +1,54 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + + +#ifndef MICROSEC +# define MICROSEC 1000000 +#endif + +#ifndef NANOSEC +# define NANOSEC 1000000000 +#endif + + + +/* + * We expect the amount of time passed to be at least one us plus two system + * calls. Therefore checking that at least a microsecond has elapsed is safe. + */ +TEST_IMPL(hrtime) { + uint64_t a, b, diff; + + a = uv_hrtime(); + uv_sleep(100); + b = uv_hrtime(); + + diff = b - a; + + printf("diff = %llu\n", diff); + + ASSERT(diff >= NANOSEC / MICROSEC); + ASSERT(diff > MICROSEC); + return 0; +} diff --git a/src/rt/libuv/test/test-list.h b/src/rt/libuv/test/test-list.h index c3cb2522468..190574acaa8 100644 --- a/src/rt/libuv/test/test-list.h +++ b/src/rt/libuv/test/test-list.h @@ -20,6 +20,7 @@ */ TEST_DECLARE (ping_pong) +TEST_DECLARE (ping_pong_v6) TEST_DECLARE (delayed_accept) TEST_DECLARE (tcp_writealot) TEST_DECLARE (bind_error_addrinuse) @@ -27,6 +28,12 @@ TEST_DECLARE (bind_error_addrnotavail_1) TEST_DECLARE (bind_error_addrnotavail_2) TEST_DECLARE (bind_error_fault) TEST_DECLARE (bind_error_inval) +TEST_DECLARE (bind_localhost_ok) +TEST_DECLARE (bind6_error_addrinuse) +TEST_DECLARE (bind6_error_addrnotavail) +TEST_DECLARE (bind6_error_fault) +TEST_DECLARE (bind6_error_inval) +TEST_DECLARE (bind6_localhost_ok) TEST_DECLARE (connection_fail) TEST_DECLARE (connection_fail_doesnt_auto_close) TEST_DECLARE (shutdown_eof) @@ -41,28 +48,39 @@ TEST_DECLARE (prepare_ref) TEST_DECLARE (check_ref) TEST_DECLARE (async) TEST_DECLARE (get_currentexe) +TEST_DECLARE (hrtime) +TEST_DECLARE (getaddrinfo_basic) +TEST_DECLARE (getaddrinfo_concurrent) +TEST_DECLARE (gethostbyname) TEST_DECLARE (fail_always) TEST_DECLARE (pass_always) HELPER_DECLARE (echo_server) + TASK_LIST_START TEST_ENTRY (ping_pong) TEST_HELPER (ping_pong, echo_server) + TEST_ENTRY (ping_pong_v6) + TEST_HELPER (ping_pong_v6, echo_server) + TEST_ENTRY (delayed_accept) TEST_ENTRY (tcp_writealot) TEST_HELPER (tcp_writealot, echo_server) TEST_ENTRY (bind_error_addrinuse) - TEST_ENTRY (bind_error_addrnotavail_1) - TEST_ENTRY (bind_error_addrnotavail_2) - TEST_ENTRY (bind_error_fault) - TEST_ENTRY (bind_error_inval) + TEST_ENTRY (bind_localhost_ok) + + TEST_ENTRY (bind6_error_addrinuse) + TEST_ENTRY (bind6_error_addrnotavail) + TEST_ENTRY (bind6_error_fault) + TEST_ENTRY (bind6_error_inval) + TEST_ENTRY (bind6_localhost_ok) TEST_ENTRY (connection_fail) TEST_ENTRY (connection_fail_doesnt_auto_close) @@ -89,6 +107,14 @@ TASK_LIST_START TEST_ENTRY (get_currentexe) + TEST_ENTRY (hrtime) + + TEST_ENTRY (getaddrinfo_basic) + TEST_ENTRY (getaddrinfo_concurrent) + + TEST_ENTRY (gethostbyname) + TEST_HELPER (gethostbyname, echo_server) + #if 0 /* These are for testing the test runner. */ TEST_ENTRY (fail_always) diff --git a/src/rt/libuv/test/test-loop-handles.c b/src/rt/libuv/test/test-loop-handles.c index fa9cc18cc55..7979a74b4ae 100644 --- a/src/rt/libuv/test/test-loop-handles.c +++ b/src/rt/libuv/test/test-loop-handles.c @@ -64,7 +64,7 @@ */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include @@ -109,8 +109,8 @@ static int idle_2_is_active = 0; static int timer_cb_called = 0; -static void timer_cb(uv_handle_t* handle, int status) { - ASSERT(handle == (uv_handle_t*)&timer_handle); +static void timer_cb(uv_timer_t* handle, int status) { + ASSERT(handle == &timer_handle); ASSERT(status == 0); timer_cb_called++; @@ -129,22 +129,22 @@ static void idle_2_close_cb(uv_handle_t* handle) { } -static void idle_2_cb(uv_handle_t* handle, int status) { +static void idle_2_cb(uv_idle_t* handle, int status) { int r; LOG("IDLE_2_CB\n"); - ASSERT(handle == (uv_handle_t*)&idle_2_handle); + ASSERT(handle == &idle_2_handle); ASSERT(status == 0); idle_2_cb_called++; - r = uv_close(handle, idle_2_close_cb); + r = uv_close((uv_handle_t*)handle, idle_2_close_cb); ASSERT(r == 0); } -static void idle_1_cb(uv_handle_t* handle, int status) { +static void idle_1_cb(uv_idle_t* handle, int status) { int r; LOG("IDLE_1_CB\n"); @@ -207,12 +207,12 @@ static void prepare_2_close_cb(uv_handle_t* handle) { } -static void check_cb(uv_handle_t* handle, int status) { +static void check_cb(uv_check_t* handle, int status) { int i, r; LOG("CHECK_CB\n"); - ASSERT(handle == (uv_handle_t*)&check_handle); + ASSERT(handle == &check_handle); ASSERT(status == 0); /* XXX @@ -254,12 +254,12 @@ static void check_cb(uv_handle_t* handle, int status) { } -static void prepare_2_cb(uv_handle_t* handle, int status) { +static void prepare_2_cb(uv_prepare_t* handle, int status) { int r; LOG("PREPARE_2_CB\n"); - ASSERT(handle == (uv_handle_t*)&prepare_2_handle); + ASSERT(handle == &prepare_2_handle); ASSERT(status == 0); /* XXX ASSERT(idles_1_active == 0); */ @@ -278,12 +278,12 @@ static void prepare_2_cb(uv_handle_t* handle, int status) { } -static void prepare_1_cb(uv_handle_t* handle, int status) { +static void prepare_1_cb(uv_prepare_t* handle, int status) { int r; LOG("PREPARE_1_CB\n"); - ASSERT(handle == (uv_handle_t*)&prepare_1_handle); + ASSERT(handle == &prepare_1_handle); ASSERT(status == 0); /* XXX diff --git a/src/rt/libuv/test/test-ping-pong.c b/src/rt/libuv/test/test-ping-pong.c index d8bf13d1f0e..34de78b5b6c 100644 --- a/src/rt/libuv/test/test-ping-pong.c +++ b/src/rt/libuv/test/test-ping-pong.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include @@ -48,7 +48,7 @@ typedef struct { void pinger_try_read(pinger_t* pinger); -static uv_buf_t alloc_cb(uv_tcp_t* tcp, size_t size) { +static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) { uv_buf_t buf; buf.base = (char*)malloc(size); buf.len = size; @@ -82,7 +82,8 @@ static void pinger_write_ping(pinger_t* pinger) { buf.len = strlen(PING); req = (uv_req_t*)malloc(sizeof(*req)); - uv_req_init(req, (uv_handle_t*)(&pinger->tcp), pinger_after_write); + uv_req_init(req, (uv_handle_t*)(&pinger->tcp), + (void *(*)(void *))pinger_after_write); if (uv_write(req, &buf, 1)) { FATAL("uv_write failed"); @@ -92,7 +93,7 @@ static void pinger_write_ping(pinger_t* pinger) { } -static void pinger_read_cb(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf) { +static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { unsigned int i; pinger_t* pinger; @@ -137,7 +138,7 @@ static void pinger_on_connect(uv_req_t *req, int status) { pinger_write_ping(pinger); - uv_read_start((uv_tcp_t*)(req->handle), alloc_cb, pinger_read_cb); + uv_read_start((uv_stream_t*)(req->handle), alloc_cb, pinger_read_cb); } @@ -158,9 +159,9 @@ static void pinger_new() { /* We are never doing multiple reads/connects at a time anyway. */ /* so these handles can be pre-initialized. */ uv_req_init(&pinger->connect_req, (uv_handle_t*)(&pinger->tcp), - pinger_on_connect); + (void *(*)(void *))pinger_on_connect); - r = uv_connect(&pinger->connect_req, server_addr); + r = uv_tcp_connect(&pinger->connect_req, server_addr); ASSERT(!r); } @@ -175,3 +176,40 @@ TEST_IMPL(ping_pong) { return 0; } + + +/* same ping-pong test, but using IPv6 connection */ +static void pinger_v6_new() { + int r; + struct sockaddr_in6 server_addr = uv_ip6_addr("::1", TEST_PORT); + pinger_t *pinger; + + pinger = (pinger_t*)malloc(sizeof(*pinger)); + pinger->state = 0; + pinger->pongs = 0; + + /* Try to connec to the server and do NUM_PINGS ping-pongs. */ + r = uv_tcp_init(&pinger->tcp); + pinger->tcp.data = pinger; + ASSERT(!r); + + /* We are never doing multiple reads/connects at a time anyway. */ + /* so these handles can be pre-initialized. */ + uv_req_init(&pinger->connect_req, (uv_handle_t*)(&pinger->tcp), + (void *(*)(void *))pinger_on_connect); + + r = uv_tcp_connect6(&pinger->connect_req, server_addr); + ASSERT(!r); +} + + +TEST_IMPL(ping_pong_v6) { + uv_init(); + + pinger_v6_new(); + uv_run(); + + ASSERT(completed_pingers == 1); + + return 0; +} diff --git a/src/rt/libuv/test/test-shutdown-eof.c b/src/rt/libuv/test/test-shutdown-eof.c index 1ce81f71be7..8a960c9ea6a 100644 --- a/src/rt/libuv/test/test-shutdown-eof.c +++ b/src/rt/libuv/test/test-shutdown-eof.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include #include @@ -37,7 +37,7 @@ static int called_timer_close_cb; static int called_timer_cb; -static uv_buf_t alloc_cb(uv_tcp_t* tcp, size_t size) { +static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) { uv_buf_t buf; buf.base = (char*)malloc(size); buf.len = size; @@ -45,8 +45,16 @@ static uv_buf_t alloc_cb(uv_tcp_t* tcp, size_t size) { } -static void read_cb(uv_tcp_t* t, ssize_t nread, uv_buf_t buf) { - ASSERT(t == &tcp); +static void read_cb(uv_stream_t* t, ssize_t nread, uv_buf_t buf) { + uv_err_t err = uv_last_error(); + + ASSERT((uv_tcp_t*)t == &tcp); + + if (nread == 0) { + ASSERT(err.code == UV_EAGAIN); + free(buf.base); + return; + } if (!got_q) { ASSERT(nread == 1); @@ -56,7 +64,7 @@ static void read_cb(uv_tcp_t* t, ssize_t nread, uv_buf_t buf) { got_q = 1; puts("got Q"); } else { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(err.code == UV_EOF); if (buf.base) { free(buf.base); } @@ -84,7 +92,7 @@ static void connect_cb(uv_req_t *req, int status) { ASSERT(req == &connect_req); /* Start reading from our connection so we can receive the EOF. */ - uv_read_start(&tcp, alloc_cb, read_cb); + uv_read_start((uv_stream_t*)&tcp, alloc_cb, read_cb); /* * Write the letter 'Q' to gracefully kill the echo-server. This will not @@ -94,7 +102,7 @@ static void connect_cb(uv_req_t *req, int status) { uv_write(&write_req, &qbuf, 1); /* Shutdown our end of the connection. */ - uv_req_init(&shutdown_req, (uv_handle_t*)&tcp, shutdown_cb); + uv_req_init(&shutdown_req, (uv_handle_t*)&tcp, (void *(*)(void *))shutdown_cb); uv_shutdown(&shutdown_req); called_connect_cb++; @@ -120,9 +128,9 @@ void timer_close_cb(uv_handle_t* handle) { } -void timer_cb(uv_handle_t* handle, int status) { - ASSERT(handle == (uv_handle_t*) &timer); - uv_close(handle, timer_close_cb); +void timer_cb(uv_timer_t* handle, int status) { + ASSERT(handle == &timer); + uv_close((uv_handle_t*) handle, timer_close_cb); /* * The most important assert of the test: we have not received @@ -157,8 +165,8 @@ TEST_IMPL(shutdown_eof) { r = uv_tcp_init(&tcp); ASSERT(!r); - uv_req_init(&connect_req, (uv_handle_t*) &tcp, connect_cb); - r = uv_connect(&connect_req, server_addr); + uv_req_init(&connect_req, (uv_handle_t*) &tcp, (void *(*)(void *))connect_cb); + r = uv_tcp_connect(&connect_req, server_addr); ASSERT(!r); uv_run(); diff --git a/src/rt/libuv/test/test-tcp-writealot.c b/src/rt/libuv/test/test-tcp-writealot.c index 5105a0477aa..4e305a9f33d 100644 --- a/src/rt/libuv/test/test-tcp-writealot.c +++ b/src/rt/libuv/test/test-tcp-writealot.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" #include #include @@ -45,7 +45,7 @@ static int bytes_received = 0; static int bytes_received_done = 0; -static uv_buf_t alloc_cb(uv_tcp_t* tcp, size_t size) { +static uv_buf_t alloc_cb(uv_stream_t* tcp, size_t size) { uv_buf_t buf; buf.base = (char*)malloc(size); buf.len = size; @@ -83,7 +83,7 @@ static void shutdown_cb(uv_req_t* req, int status) { } -static void read_cb(uv_tcp_t* tcp, ssize_t nread, uv_buf_t buf) { +static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { ASSERT(tcp != NULL); if (nread < 0) { @@ -144,7 +144,7 @@ static void connect_cb(uv_req_t* req, int status) { req = (uv_req_t*)malloc(sizeof *req); ASSERT(req != NULL); - uv_req_init(req, (uv_handle_t*)tcp, write_cb); + uv_req_init(req, (uv_handle_t*)tcp, (void *(*)(void *))write_cb); r = uv_write(req, (uv_buf_t*)&send_bufs, CHUNKS_PER_WRITE); ASSERT(r == 0); } @@ -152,7 +152,7 @@ static void connect_cb(uv_req_t* req, int status) { /* Shutdown on drain. FIXME: dealloc req? */ req = (uv_req_t*) malloc(sizeof(uv_req_t)); ASSERT(req != NULL); - uv_req_init(req, (uv_handle_t*)tcp, shutdown_cb); + uv_req_init(req, (uv_handle_t*)tcp, (void *(*)(void *))shutdown_cb); r = uv_shutdown(req); ASSERT(r == 0); @@ -160,8 +160,8 @@ static void connect_cb(uv_req_t* req, int status) { req = (uv_req_t*)malloc(sizeof *req); ASSERT(req != NULL); - uv_req_init(req, (uv_handle_t*)tcp, read_cb); - r = uv_read_start(tcp, alloc_cb, read_cb); + uv_req_init(req, (uv_handle_t*)tcp, (void *(*)(void *))read_cb); + r = uv_read_start((uv_stream_t*)tcp, alloc_cb, read_cb); ASSERT(r == 0); } @@ -184,8 +184,8 @@ TEST_IMPL(tcp_writealot) { r = uv_tcp_init(client); ASSERT(r == 0); - uv_req_init(connect_req, (uv_handle_t*)client, connect_cb); - r = uv_connect(connect_req, addr); + uv_req_init(connect_req, (uv_handle_t*)client, (void *(*)(void *))connect_cb); + r = uv_tcp_connect(connect_req, addr); ASSERT(r == 0); uv_run(); diff --git a/src/rt/libuv/test/test-timer-again.c b/src/rt/libuv/test/test-timer-again.c index 77482083491..e083b01ced1 100644 --- a/src/rt/libuv/test/test-timer-again.c +++ b/src/rt/libuv/test/test-timer-again.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" @@ -41,10 +41,10 @@ static void close_cb(uv_handle_t* handle) { } -static void repeat_1_cb(uv_handle_t* handle, int status) { +static void repeat_1_cb(uv_timer_t* handle, int status) { int r; - ASSERT(handle == (uv_handle_t*)&repeat_1); + ASSERT(handle == &repeat_1); ASSERT(status == 0); ASSERT(uv_timer_get_repeat((uv_timer_t*)handle) == 50); @@ -57,7 +57,7 @@ static void repeat_1_cb(uv_handle_t* handle, int status) { ASSERT(r == 0); if (uv_now() >= start_time + 500) { - uv_close(handle, close_cb); + uv_close((uv_handle_t*)handle, close_cb); /* We're not calling uv_timer_again on repeat_2 any more, so after this */ /* timer_2_cb is expected. */ repeat_2_cb_allowed = 1; @@ -66,8 +66,8 @@ static void repeat_1_cb(uv_handle_t* handle, int status) { } -static void repeat_2_cb(uv_handle_t* handle, int status) { - ASSERT(handle == (uv_handle_t*) &repeat_2); +static void repeat_2_cb(uv_timer_t* handle, int status) { + ASSERT(handle == &repeat_2); ASSERT(status == 0); ASSERT(repeat_2_cb_allowed); @@ -76,8 +76,8 @@ static void repeat_2_cb(uv_handle_t* handle, int status) { repeat_2_cb_called++; if (uv_timer_get_repeat(&repeat_2) == 0) { - ASSERT(!uv_is_active(handle)); - uv_close(handle, close_cb); + ASSERT(!uv_is_active((uv_handle_t*)handle)); + uv_close((uv_handle_t*)handle, close_cb); return; } diff --git a/src/rt/libuv/test/test-timer.c b/src/rt/libuv/test/test-timer.c index 5d39ad717c2..c62a8c68dbc 100644 --- a/src/rt/libuv/test/test-timer.c +++ b/src/rt/libuv/test/test-timer.c @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -#include "../uv.h" +#include "uv.h" #include "task.h" @@ -42,7 +42,7 @@ static void once_close_cb(uv_handle_t* handle) { } -static void once_cb(uv_handle_t* handle, int status) { +static void once_cb(uv_timer_t* handle, int status) { printf("ONCE_CB %d\n", once_cb_called); ASSERT(handle != NULL); @@ -50,7 +50,7 @@ static void once_cb(uv_handle_t* handle, int status) { once_cb_called++; - uv_close(handle, once_close_cb); + uv_close((uv_handle_t*)handle, once_close_cb); /* Just call this randomly for the code coverage. */ uv_update_time(); @@ -66,7 +66,7 @@ static void repeat_close_cb(uv_handle_t* handle) { } -static void repeat_cb(uv_handle_t* handle, int status) { +static void repeat_cb(uv_timer_t* handle, int status) { printf("REPEAT_CB\n"); ASSERT(handle != NULL); @@ -75,12 +75,12 @@ static void repeat_cb(uv_handle_t* handle, int status) { repeat_cb_called++; if (repeat_cb_called == 5) { - uv_close(handle, repeat_close_cb); + uv_close((uv_handle_t*)handle, repeat_close_cb); } } -static void never_cb(uv_handle_t* handle, int status) { +static void never_cb(uv_timer_t* handle, int status) { FATAL("never_cb should never be called"); } diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp index 9e4e15b61aa..d0d98aa5090 100644 --- a/src/rt/rust_uv.cpp +++ b/src/rt/rust_uv.cpp @@ -3,7 +3,7 @@ // Disable libev prototypes - they will make inline compatability functions // which are unused and so trigger a warning in gcc since -Wall is on. #define EV_PROTOTYPES 0 -#include "libuv/uv.h" +#include "uv.h" #ifdef __GNUC__ #define LOG_CALLBACK_ENTRY(p) \ @@ -45,7 +45,7 @@ struct request : public uv_req_t, public task_owned { rust_chan *chan; request(socket_data *data, rust_chan *chan, void (*cb)(request *req, int status)) { - uv_req_init(this, (uv_handle_t*)&data->socket, (void*)cb); + uv_req_init(this, (uv_handle_t*)&data->socket, (void*(*)(void*))cb); this->data = data; this->task = data->task; this->chan = chan->clone(iotask); @@ -64,7 +64,7 @@ extern "C" CDECL void aio_close_socket(rust_task *task, socket_data *); static uv_idle_s idle_handler; -static void idle_callback(uv_handle_t* handle, int status) { +static void idle_callback(uv_idle_t* handle, int status) { rust_task *task = reinterpret_cast(handle->data); task->yield(); } @@ -110,7 +110,7 @@ static socket_data *make_socket(rust_task *task, rust_chan *chan) { // We allocate the requested space + rust_vec but return a pointer at a // +rust_vec offset so that it writes the bytes to the correct location. -static uv_buf_t alloc_buffer(uv_tcp_t *socket, size_t suggested_size) { +static uv_buf_t alloc_buffer(uv_stream_t *socket, size_t suggested_size) { LOG_CALLBACK_ENTRY(socket); uv_buf_t buf; size_t actual_size = suggested_size + sizeof (rust_ivec_heap); @@ -123,7 +123,7 @@ static uv_buf_t alloc_buffer(uv_tcp_t *socket, size_t suggested_size) { return buf; } -static void read_progress(uv_tcp_t *socket, ssize_t nread, uv_buf_t buf) { +static void read_progress(uv_stream_t *socket, ssize_t nread, uv_buf_t buf) { LOG_CALLBACK_ENTRY(socket); socket_data *data = (socket_data*)socket->data; I(data->task->sched, data->reader != NULL); @@ -151,17 +151,17 @@ static void read_progress(uv_tcp_t *socket, ssize_t nread, uv_buf_t buf) { data->reader->send(&v); } -static void new_connection(uv_tcp_t *socket, int status) { +static void new_connection(uv_handle_t *socket, int status) { LOG_CALLBACK_ENTRY(socket); socket_data *server = (socket_data*)socket->data; - I(server->task->sched, socket == &server->socket); + I(server->task->sched, (uv_tcp_t*)socket == &server->socket); // Connections from servers don't have a channel socket_data *client = make_socket(server->task, NULL); if (!client) { server->task->fail(); return; } - if (uv_accept(socket, &client->socket)) { + if (uv_accept(socket, (uv_stream_t*)&client->socket)) { aio_close_socket(client->task, client); server->task->fail(); return; @@ -176,8 +176,8 @@ extern "C" CDECL socket_data *aio_serve(rust_task *task, const char *ip, socket_data *server = make_socket(iotask, chan); if (!server) goto oom; - if (uv_bind(&server->socket, addr) || - uv_listen(&server->socket, 128, new_connection)) { + if (uv_tcp_bind(&server->socket, addr) || + uv_tcp_listen(&server->socket, 128, new_connection)) { aio_close_socket(task, server); return NULL; } @@ -196,9 +196,9 @@ static void free_socket(uv_handle_t *handle) { // reading and should send the close notification. if (data->reader) { if (data->reader->is_associated()) { - uv_buf_t buf = alloc_buffer(socket, 0); - read_progress(socket, -1, buf); - uv_read_stop(socket); + uv_buf_t buf = alloc_buffer((uv_stream_t*)socket, 0); + read_progress((uv_stream_t*)socket, -1, buf); + uv_read_stop((uv_stream_t*)socket); } } else { // This is a server socket @@ -256,7 +256,7 @@ extern "C" CDECL void aio_connect(rust_task *task, const char *host, if (!req) { goto oom_req; } - if (0 == uv_connect(req, addr)) { + if (0 == uv_tcp_connect(req, addr)) { return; } oom_req: @@ -296,5 +296,5 @@ extern "C" CDECL void aio_read(rust_task *task, socket_data *data, LOG_UPCALL_ENTRY(task); I(task->sched, data->reader == NULL); data->reader = reader->clone(iotask); - uv_read_start(&data->socket, alloc_buffer, read_progress); + uv_read_start((uv_stream_t*)&data->socket, alloc_buffer, read_progress); }