summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>2013-02-25 00:20:27 +0000
committerrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>2013-02-25 00:20:27 +0000
commit3a5fbe774b1ad135d4f4db1150fee64c1b42b69c (patch)
treec288a08bed6b0e438246d26c993f86f05a961a5c
parent6a75b294b538c1f8aa45041288c8ab404dd1427b (diff)
downloadlibapr-3a5fbe774b1ad135d4f4db1150fee64c1b42b69c.tar.gz
Fix detection of O_NONBLOCK inheritance.
The original test failed occasionally on a busy FreeBSD server when accept() returned EAGAIN. Backport of r1449568 from trunk resp. r1449569 from 1.5.x resp. r1449570 from 1.4.x resp. r1449571 from 1.3.x. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/0.9.x@1449572 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES6
-rw-r--r--build/apr_network.m431
2 files changed, 36 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 11ac2fce9..729b0e9ca 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
- -*- coding: utf-8 -*-
+
+-*- coding: utf-8 -*-
Changes with APR 0.9.21
+ *) configure: Fix detection of O_NONBLOCK inheritance on busy
+ systems. [Rainer Jung]
+
*) apr_time_exp_*() on Windows: Fix error in the tm_yday field of
apr_time_exp_t for times within leap years. PR 53175.
[Jeff Trawick]
diff --git a/build/apr_network.m4 b/build/apr_network.m4
index 16eb92b8c..e01f0b1ac 100644
--- a/build/apr_network.m4
+++ b/build/apr_network.m4
@@ -354,13 +354,24 @@ dnl
AC_DEFUN(APR_CHECK_O_NONBLOCK_INHERITED,[
AC_CACHE_CHECK(if O_NONBLOCK setting is inherited from listening sockets, ac_cv_o_nonblock_inherited,[
AC_TRY_RUN( [
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STDIO_H
#include <stdio.h>
+#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -431,6 +442,26 @@ int main(void) {
exit(1);
}
sa_len = sizeof sa;
+ /* 1 second select timeout */
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ /* Set up fd set */
+ FD_ZERO(&fds);
+ FD_SET(listen_s, &fds);
+ /* Wait for socket to become readable */
+ rc = select(listen_s + 1, &fds, NULL, NULL, &tv);
+ if (rc < 0) {
+ perror("select");
+ exit(1);
+ }
+ if (rc == 0) {
+ fprintf(stderr, "Socket failed to become readable (timeout)\n");
+ exit(1);
+ }
+ if (!FD_ISSET(listen_s, &fds)) {
+ fprintf(stderr, "Socket failed to become readable (selected another fd)\n");
+ exit(1);
+ }
connected_s = accept(listen_s, (struct sockaddr *)&sa, &sa_len);
if (connected_s < 0) {
perror("accept");