~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/test/sockchild.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
 
 
17
#include <stdlib.h>
 
18
#include "testsock.h"
 
19
#include "apr_network_io.h"
 
20
#include "apr_pools.h"
 
21
 
 
22
int main(int argc, char *argv[])
 
23
{
 
24
    apr_pool_t *p;
 
25
    apr_socket_t *sock;
 
26
    apr_status_t rv;
 
27
    apr_sockaddr_t *remote_sa;
 
28
 
 
29
    apr_initialize();
 
30
    atexit(apr_terminate);
 
31
    apr_pool_create(&p, NULL);
 
32
 
 
33
    if (argc < 2) {
 
34
        exit(-1);
 
35
    }
 
36
 
 
37
    rv = apr_sockaddr_info_get(&remote_sa, "127.0.0.1", APR_UNSPEC, 8021, 0, p);
 
38
    if (rv != APR_SUCCESS) {
 
39
        exit(-1);
 
40
    }
 
41
 
 
42
    if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM, 0,
 
43
                p) != APR_SUCCESS) {
 
44
        exit(-1);
 
45
    }
 
46
 
 
47
    rv = apr_socket_timeout_set(sock, apr_time_from_sec(3));
 
48
    if (rv) {
 
49
        exit(-1);
 
50
    }
 
51
 
 
52
    apr_socket_connect(sock, remote_sa);
 
53
        
 
54
    if (!strcmp("read", argv[1])) {
 
55
        char datarecv[STRLEN];
 
56
        apr_size_t length = STRLEN;
 
57
        apr_status_t rv;
 
58
 
 
59
        memset(datarecv, 0, STRLEN);
 
60
        rv = apr_socket_recv(sock, datarecv, &length);
 
61
        apr_socket_close(sock);
 
62
        if (APR_STATUS_IS_TIMEUP(rv)) {
 
63
            exit(SOCKET_TIMEOUT); 
 
64
        }
 
65
 
 
66
        if (strcmp(datarecv, DATASTR)) {
 
67
            exit(-1);
 
68
        }
 
69
        
 
70
        exit(length);
 
71
    }
 
72
    else if (!strcmp("write", argv[1])) {
 
73
        apr_size_t length = strlen(DATASTR);
 
74
        apr_socket_send(sock, DATASTR, &length);
 
75
 
 
76
        apr_socket_close(sock);
 
77
        exit(length);
 
78
    }
 
79
    exit(-1);
 
80
}