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

« back to all changes in this revision

Viewing changes to srclib/apr/test/testshmconsumer.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 "apr_shm.h"
 
18
#include "apr_errno.h"
 
19
#include "apr_general.h"
 
20
#include "apr_lib.h"
 
21
#include "apr_strings.h"
 
22
#include "apr_time.h"
 
23
#include "testshm.h"
 
24
#include "apr.h"
 
25
 
 
26
#if APR_HAVE_STDLIB_H
 
27
#include <stdlib.h>
 
28
#endif
 
29
 
 
30
 
 
31
#if APR_HAS_SHARED_MEMORY
 
32
 
 
33
static int msgwait(int sleep_sec, int first_box, int last_box)
 
34
{
 
35
    int i;
 
36
    int recvd = 0;
 
37
    apr_time_t start = apr_time_now();
 
38
    apr_interval_time_t sleep_duration = apr_time_from_sec(sleep_sec);
 
39
    while (apr_time_now() - start < sleep_duration) {
 
40
        for (i = first_box; i < last_box; i++) {
 
41
            if (boxes[i].msgavail && !strcmp(boxes[i].msg, MSG)) {
 
42
                recvd++;
 
43
                boxes[i].msgavail = 0; /* reset back to 0 */
 
44
                memset(boxes[i].msg, 0, 1024);
 
45
            }
 
46
        }
 
47
        apr_sleep(apr_time_from_sec(1));
 
48
    }
 
49
    return recvd;
 
50
}
 
51
 
 
52
int main(void)
 
53
{
 
54
    apr_status_t rv;
 
55
    apr_pool_t *pool;
 
56
    apr_shm_t *shm;
 
57
    int recvd;
 
58
 
 
59
    apr_initialize();
 
60
    
 
61
    if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
 
62
        exit(-1);
 
63
    }
 
64
 
 
65
    rv = apr_shm_attach(&shm, SHARED_FILENAME, pool);
 
66
    if (rv != APR_SUCCESS) {
 
67
        exit(-2);
 
68
    }
 
69
 
 
70
    boxes = apr_shm_baseaddr_get(shm);
 
71
 
 
72
    /* consume messages on all of the boxes */
 
73
    recvd = msgwait(30, 0, N_BOXES); /* wait for 30 seconds for messages */
 
74
 
 
75
    rv = apr_shm_detach(shm);
 
76
    if (rv != APR_SUCCESS) {
 
77
        exit(-3);
 
78
    }
 
79
 
 
80
    return recvd;
 
81
}
 
82
 
 
83
#else /* APR_HAS_SHARED_MEMORY */
 
84
 
 
85
int main(void)
 
86
{
 
87
    /* Just return, this program will never be called, so we don't need
 
88
     * to print a message 
 
89
     */
 
90
    return 0;
 
91
}
 
92
 
 
93
#endif /* APR_HAS_SHARED_MEMORY */
 
94