summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuediger Pluem <rpluem@apache.org>2009-10-16 21:08:15 +0000
committerRuediger Pluem <rpluem@apache.org>2009-10-16 21:08:15 +0000
commitf7fe76503cdeab5885f9507945f8f8c390b47328 (patch)
tree44df2b64ee9ae0efd5635860dfb89fe4133c6c4c /test
parent3905d69eb5cf1068ff2ddeff2fbc499048c2945a (diff)
downloadapr-f7fe76503cdeab5885f9507945f8f8c390b47328.tar.gz
Merge r821524, r822431, r822892, r824500 from trunk:
* Add apr_socket_is_connected to detect whether the remote side of a socket is still open. The origin of apr_socket_is_connected is r473278 from http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c in httpd. * Improve the documentation Suggested by: jorton * Improve the documentation even further Reviewed by: jim * include/apr_network_io.h, * network_io/unix/socket_util.c (apr_socket_atreadeof): Renamed from apr_socket_is_connected; adjusted to return an apr_status_t error code, and pass an "at EOF" flag via an output parameter. * test/testsock.c (test_atreadeof): Renamed from test_is_connected, adjusted for new API. Reviewed by: jorton, rpluem git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@826089 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/sockchild.c4
-rw-r--r--test/testsock.c57
2 files changed, 61 insertions, 0 deletions
diff --git a/test/sockchild.c b/test/sockchild.c
index 3803d00af..ec7ffb85c 100644
--- a/test/sockchild.c
+++ b/test/sockchild.c
@@ -76,5 +76,9 @@ int main(int argc, char *argv[])
apr_socket_close(sock);
exit((int)length);
}
+ else if (!strcmp("close", argv[1])) {
+ apr_socket_close(sock);
+ exit(0);
+ }
exit(-1);
}
diff --git a/test/testsock.c b/test/testsock.c
index 50aef5c2b..1684ea655 100644
--- a/test/testsock.c
+++ b/test/testsock.c
@@ -198,6 +198,62 @@ static void test_recv(abts_case *tc, void *data)
APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv);
}
+static void test_atreadeof(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_socket_t *sock;
+ apr_socket_t *sock2;
+ apr_proc_t proc;
+ apr_size_t length = STRLEN;
+ char datastr[STRLEN];
+ int atreadeof = -1;
+
+ sock = setup_socket(tc);
+ if (!sock) return;
+
+ launch_child(tc, &proc, "write", p);
+
+ rv = apr_socket_accept(&sock2, sock, p);
+ APR_ASSERT_SUCCESS(tc, "Problem with receiving connection", rv);
+
+ /* Check that the remote socket is still open */
+ rv = apr_socket_atreadeof(sock2, &atreadeof);
+ APR_ASSERT_SUCCESS(tc, "Determine whether at EOF, #1", rv);
+ ABTS_INT_EQUAL(tc, 0, atreadeof);
+
+ memset(datastr, 0, STRLEN);
+ apr_socket_recv(sock2, datastr, &length);
+
+ /* Make sure that the server received the data we sent */
+ ABTS_STR_EQUAL(tc, DATASTR, datastr);
+ ABTS_SIZE_EQUAL(tc, strlen(datastr), wait_child(tc, &proc));
+
+ /* The child is dead, so should be the remote socket */
+ rv = apr_socket_atreadeof(sock2, &atreadeof);
+ APR_ASSERT_SUCCESS(tc, "Determine whether at EOF, #2", rv);
+ ABTS_INT_EQUAL(tc, 1, atreadeof);
+
+ rv = apr_socket_close(sock2);
+ APR_ASSERT_SUCCESS(tc, "Problem closing connected socket", rv);
+
+ launch_child(tc, &proc, "close", p);
+
+ rv = apr_socket_accept(&sock2, sock, p);
+ APR_ASSERT_SUCCESS(tc, "Problem with receiving connection", rv);
+
+ /* The child closed the socket instantly */
+ rv = apr_socket_atreadeof(sock2, &atreadeof);
+ APR_ASSERT_SUCCESS(tc, "Determine whether at EOF, #3", rv);
+ ABTS_INT_EQUAL(tc, 1, atreadeof);
+ 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);
+}
+
static void test_timeout(abts_case *tc, void *data)
{
apr_status_t rv;
@@ -345,6 +401,7 @@ abts_suite *testsock(abts_suite *suite)
abts_run_test(suite, test_create_bind_listen, NULL);
abts_run_test(suite, test_send, NULL);
abts_run_test(suite, test_recv, NULL);
+ abts_run_test(suite, test_atreadeof, NULL);
abts_run_test(suite, test_timeout, NULL);
abts_run_test(suite, test_print_addr, NULL);
abts_run_test(suite, test_get_addr, NULL);