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(CuTest *tc)
29
rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, p);
30
CuAssertIntEquals(tc, APR_SUCCESS, rv);
31
CuAssertPtrNotNull(tc, sock);
34
static void set_keepalive(CuTest *tc)
39
rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 1);
40
CuAssertIntEquals(tc, APR_SUCCESS, rv);
42
rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
43
CuAssertIntEquals(tc, APR_SUCCESS, rv);
44
CuAssertIntEquals(tc, 1, ck);
47
static void set_debug(CuTest *tc)
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 (APR_STATUS_IS_SUCCESS(rv1)) {
58
CuAssertIntEquals(tc, 1, ck);
60
CuAssertIntEquals(tc, 0, ck);
64
static void remove_keepalive(CuTest *tc)
69
rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
70
CuAssertIntEquals(tc, APR_SUCCESS, rv);
71
CuAssertIntEquals(tc, 1, ck);
73
rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 0);
74
CuAssertIntEquals(tc, APR_SUCCESS, rv);
76
rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck);
77
CuAssertIntEquals(tc, APR_SUCCESS, rv);
78
CuAssertIntEquals(tc, 0, ck);
81
static void corkable(CuTest *tc)
83
#if !APR_HAVE_CORKABLE_TCP
84
CuNotImpl(tc, "TCP isn't corkable");
89
rv = apr_socket_opt_set(sock, APR_TCP_NODELAY, 1);
90
CuAssertIntEquals(tc, APR_SUCCESS, rv);
92
rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
93
CuAssertIntEquals(tc, APR_SUCCESS, rv);
94
CuAssertIntEquals(tc, 1, ck);
96
rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1);
97
CuAssertIntEquals(tc, APR_SUCCESS, rv);
99
rv = apr_socket_opt_get(sock, APR_TCP_NOPUSH, &ck);
100
CuAssertIntEquals(tc, APR_SUCCESS, rv);
101
CuAssertIntEquals(tc, 1, ck);
103
rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
104
CuAssertIntEquals(tc, APR_SUCCESS, rv);
105
CuAssertIntEquals(tc, 0, ck);
107
rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
108
CuAssertIntEquals(tc, APR_SUCCESS, rv);
110
rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
111
CuAssertIntEquals(tc, APR_SUCCESS, rv);
112
CuAssertIntEquals(tc, 1, ck);
116
static void close_socket(CuTest *tc)
120
rv = apr_socket_close(sock);
121
CuAssertIntEquals(tc, APR_SUCCESS, rv);
124
CuSuite *testsockopt(void)
126
CuSuite *suite = CuSuiteNew("Socket Options");
128
SUITE_ADD_TEST(suite, create_socket);
129
SUITE_ADD_TEST(suite, set_keepalive);
130
SUITE_ADD_TEST(suite, set_debug);
131
SUITE_ADD_TEST(suite, remove_keepalive);
132
SUITE_ADD_TEST(suite, corkable);
133
SUITE_ADD_TEST(suite, close_socket);