apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1551667 - in /apr/apr/branches/1.5.x: ./ test/sockchild.c test/testsock.c
Date Tue, 17 Dec 2013 19:48:05 GMT
Author: trawick
Date: Tue Dec 17 19:48:05 2013
New Revision: 1551667

URL: http://svn.apache.org/r1551667
Log:
merge r1551650 from trunk:

Add testcase for broken handling of APR_O_NONBLOCK_INHERITED
(as seen on FreeBSD 10).

Modified:
    apr/apr/branches/1.5.x/   (props changed)
    apr/apr/branches/1.5.x/test/sockchild.c
    apr/apr/branches/1.5.x/test/testsock.c

Propchange: apr/apr/branches/1.5.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1551650

Modified: apr/apr/branches/1.5.x/test/sockchild.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/sockchild.c?rev=1551667&r1=1551666&r2=1551667&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/test/sockchild.c (original)
+++ apr/apr/branches/1.5.x/test/sockchild.c Tue Dec 17 19:48:05 2013
@@ -69,8 +69,14 @@ int main(int argc, char *argv[])
         
         exit((int)length);
     }
-    else if (!strcmp("write", argv[1])) {
+    else if (!strcmp("write", argv[1])
+             || !strcmp("write_after_delay", argv[1])) {
         apr_size_t length = strlen(DATASTR);
+
+        if (!strcmp("write_after_delay", argv[1])) {
+            apr_sleep(apr_time_from_sec(2));
+        }
+
         apr_socket_send(sock, DATASTR, &length);
 
         apr_socket_close(sock);

Modified: apr/apr/branches/1.5.x/test/testsock.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/testsock.c?rev=1551667&r1=1551666&r2=1551667&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/test/testsock.c (original)
+++ apr/apr/branches/1.5.x/test/testsock.c Tue Dec 17 19:48:05 2013
@@ -438,6 +438,54 @@ static void test_get_addr(abts_case *tc,
     apr_pool_destroy(subp);
 }
 
+/* Make sure that setting a connected socket non-blocking works
+ * when the listening socket was non-blocking.
+ * If APR thinks that non-blocking is inherited but it really
+ * isn't, this testcase will fail.
+ */
+static void test_nonblock_inheritance(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    apr_socket_t *sock;
+    apr_socket_t *sock2;
+    apr_proc_t proc;
+    char buffer[10];
+    apr_size_t length;
+    int tries;
+
+    sock = setup_socket(tc);
+    if (!sock) return;
+
+    rv = apr_socket_opt_set(sock, APR_SO_NONBLOCK, 1);
+    APR_ASSERT_SUCCESS(tc, "Could not make listening socket nonblocking", rv);
+
+    launch_child(tc, &proc, "write_after_delay", p);
+
+    tries = 10;
+    while (tries--) {
+        rv = apr_socket_accept(&sock2, sock, p);
+        if (!APR_STATUS_IS_EAGAIN(rv)) {
+            break;
+        }
+        apr_sleep(apr_time_from_msec(50));
+    }
+    APR_ASSERT_SUCCESS(tc, "Problem with receiving connection", rv);
+
+    rv = apr_socket_opt_set(sock2, APR_SO_NONBLOCK, 1);
+    APR_ASSERT_SUCCESS(tc, "Could not make connected socket nonblocking", rv);
+
+    length = sizeof buffer;
+    rv = apr_socket_recv(sock2, buffer, &length);
+    ABTS_ASSERT(tc, "should have gotten EAGAIN", APR_STATUS_IS_EAGAIN(rv));
+
+    wait_child(tc, &proc);
+
+    rv = apr_socket_close(sock2);
+    APR_ASSERT_SUCCESS(tc, "Problem closing connected socket", rv);
+    rv = apr_socket_close(sock);
+    APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv);
+}
+
 abts_suite *testsock(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -451,6 +499,7 @@ abts_suite *testsock(abts_suite *suite)
     abts_run_test(suite, test_timeout, NULL);
     abts_run_test(suite, test_print_addr, NULL);
     abts_run_test(suite, test_get_addr, NULL);
+    abts_run_test(suite, test_nonblock_inheritance, NULL);
 
     return suite;
 }



Mime
View raw message