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

« back to all changes in this revision

Viewing changes to srclib/apr/test/testshmproducer.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
static void msgput(int boxnum, char *msg)
 
33
{
 
34
    apr_cpystrn(boxes[boxnum].msg, msg, strlen(msg) + 1);
 
35
    boxes[boxnum].msgavail = 1;
 
36
}
 
37
 
 
38
int main(void)
 
39
{
 
40
    apr_status_t rv;
 
41
    apr_pool_t *pool;
 
42
    apr_shm_t *shm;
 
43
    int i;
 
44
    int sent = 0;
 
45
 
 
46
    apr_initialize();
 
47
    
 
48
    if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
 
49
        exit(-1);
 
50
    }
 
51
 
 
52
    rv = apr_shm_attach(&shm, SHARED_FILENAME, pool);
 
53
    if (rv != APR_SUCCESS) {
 
54
        exit(-2);
 
55
    }
 
56
 
 
57
    boxes = apr_shm_baseaddr_get(shm);
 
58
 
 
59
    /* produce messages on all of the boxes, in descending order,
 
60
     * Yes, we could just return N_BOXES, but I want to have a double-check
 
61
     * in this code.  The original code actually sent N_BOXES - 1 messages,
 
62
     * so rather than rely on possibly buggy code, this way we know that we
 
63
     * are returning the right number.
 
64
     */
 
65
    for (i = N_BOXES - 1, sent = 0; i >= 0; i--, sent++) {
 
66
        msgput(i, MSG);
 
67
        apr_sleep(apr_time_from_sec(1));
 
68
    }
 
69
 
 
70
    rv = apr_shm_detach(shm);
 
71
    if (rv != APR_SUCCESS) {
 
72
        exit(-3);
 
73
    }
 
74
 
 
75
    return sent;
 
76
}
 
77
 
 
78
#else /* APR_HAS_SHARED_MEMORY */
 
79
 
 
80
int main(void)
 
81
{
 
82
    /* Just return, this program will never be launched, so there is no
 
83
     * reason to print a message.
 
84
     */
 
85
    return 0;
 
86
}
 
87
 
 
88
#endif /* APR_HAS_SHARED_MEMORY */
 
89