1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#include "apr_network_io.h"
18
#include "apr_errno.h"
19
#include "apr_general.h"
23
static apr_socket_t *sock = NULL;
25
static void create_socket(abts_case *tc, void *data)
29
rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, 0, p);
30
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
31
ABTS_PTR_NOTNULL(tc, sock);
34
static void set_keepalive(abts_case *tc, void *data)
39
rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 1);
40
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
42
rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
43
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
44
ABTS_INT_EQUAL(tc, 1, ck);
47
static void set_debug(abts_case *tc, void *data)
49
apr_status_t rv1, rv2;
52
/* On some platforms APR_SO_DEBUG can only be set as root; just test
53
* for get/set consistency of this option. */
54
rv1 = apr_socket_opt_set(sock, APR_SO_DEBUG, 1);
55
rv2 = apr_socket_opt_get(sock, APR_SO_DEBUG, &ck);
56
APR_ASSERT_SUCCESS(tc, "get SO_DEBUG option", rv2);
57
if (rv1 == APR_SUCCESS) {
58
ABTS_INT_EQUAL(tc, 1, ck);
60
ABTS_INT_EQUAL(tc, 0, ck);
64
static void remove_keepalive(abts_case *tc, void *data)
69
rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
70
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
71
ABTS_INT_EQUAL(tc, 1, ck);
73
rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 0);
74
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
76
rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
77
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
78
ABTS_INT_EQUAL(tc, 0, ck);
81
static void corkable(abts_case *tc, void *data)
83
#if !APR_HAVE_CORKABLE_TCP
84
ABTS_NOT_IMPL(tc, "TCP isn't corkable");
89
rv = apr_socket_opt_set(sock, APR_TCP_NODELAY, 1);
90
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
92
rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
93
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
94
ABTS_INT_EQUAL(tc, 1, ck);
96
rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1);
97
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
99
rv = apr_socket_opt_get(sock, APR_TCP_NOPUSH, &ck);
100
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
101
ABTS_INT_EQUAL(tc, 1, ck);
103
rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
104
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
105
/* TCP_NODELAY is now in an unknown state; it may be zero if
106
* TCP_NOPUSH and TCP_NODELAY are mutually exclusive on this
107
* platform, e.g. Linux < 2.6. */
109
rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
110
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
112
rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
113
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
114
ABTS_INT_EQUAL(tc, 1, ck);
118
static void close_socket(abts_case *tc, void *data)
122
rv = apr_socket_close(sock);
123
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
126
abts_suite *testsockopt(abts_suite *suite)
128
suite = ADD_SUITE(suite)
130
abts_run_test(suite, create_socket, NULL);
131
abts_run_test(suite, set_keepalive, NULL);
132
abts_run_test(suite, set_debug, NULL);
133
abts_run_test(suite, remove_keepalive, NULL);
134
abts_run_test(suite, corkable, NULL);
135
abts_run_test(suite, close_socket, NULL);