diff options
author | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2016-03-03 12:00:20 +0000 |
---|---|---|
committer | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2016-03-03 12:00:20 +0000 |
commit | 564ec1f61faaaccb0c87f37ae4f997c216b7150d (patch) | |
tree | b91ac4cdf4e0722d097b656ca05c480623a76709 /test/testsock.c | |
parent | 7087cb8b4790a336dcf63486743abf76e157c080 (diff) | |
download | libapr-564ec1f61faaaccb0c87f37ae4f997c216b7150d.tar.gz |
* include/apr_network_io.h (APR_SO_FREEBIND): Add option.
* network_io/unix/sockopt.c (apr_socket_opt_set): Implement
APR_SO_FREEBIND on Linux with IP_FREEBIND
* test/testsock.c (test_freebind): Add test case.
Submitted by: Ashley GC, jkaluza, jorton
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@1733451 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testsock.c')
-rw-r--r-- | test/testsock.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/testsock.c b/test/testsock.c index 620c3f6a6..70f8235ee 100644 --- a/test/testsock.c +++ b/test/testsock.c @@ -607,6 +607,39 @@ static void test_nonblock_inheritance(abts_case *tc, void *data) APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv); } +static void test_freebind(abts_case *tc, void *data) +{ +#ifdef IP_FREEBIND + apr_status_t rv; + apr_socket_t *sock; + apr_sockaddr_t *sa; + apr_int32_t on; + + /* RFC 5737 address */ + rv = apr_sockaddr_info_get(&sa, "192.0.2.1", APR_INET, 8080, 0, p); + APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv); + + rv = apr_socket_create(&sock, sa->family, SOCK_STREAM, APR_PROTO_TCP, p); + APR_ASSERT_SUCCESS(tc, "Problem creating socket", rv); + + rv = apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1); + APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket", rv); + + rv = apr_socket_opt_set(sock, APR_SO_FREEBIND, 1); + APR_ASSERT_SUCCESS(tc, "Could not enable FREEBIND option", rv); + + rv = apr_socket_opt_get(sock, APR_SO_FREEBIND, &on); + APR_ASSERT_SUCCESS(tc, "Could not retrieve FREEBIND option", rv); + ABTS_INT_EQUAL(tc, 1, on); + + rv = apr_socket_bind(sock, sa); + APR_ASSERT_SUCCESS(tc, "Problem binding to port with FREEBIND", rv); + + rv = apr_socket_close(sock); + APR_ASSERT_SUCCESS(tc, "Problem closing socket", rv); +#endif +} + abts_suite *testsock(abts_suite *suite) { suite = ADD_SUITE(suite) @@ -623,6 +656,7 @@ abts_suite *testsock(abts_suite *suite) abts_run_test(suite, test_get_addr, NULL); abts_run_test(suite, test_wait, NULL); abts_run_test(suite, test_nonblock_inheritance, NULL); + abts_run_test(suite, test_freebind, NULL); #if APR_HAVE_SOCKADDR_UN socket_name = UNIX_SOCKET_NAME; socket_type = APR_UNIX; |