Apache HTTPD
framework
httpd-2.4.62
srclib
apr
test
testshmproducer.c
Go to the documentation of this file.
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
* contributor license agreements. See the NOTICE file distributed with
3
* this work for additional information regarding copyright ownership.
4
* The ASF licenses this file to You under the Apache License, Version 2.0
5
* (the "License"); you may not use this file except in compliance with
6
* the License. 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
int
main
(
void
)
34
{
35
apr_status_t
rv;
36
apr_pool_t
*
pool
;
37
apr_shm_t
*
shm
;
38
int
i
;
39
int
sent
= 0;
40
41
apr_initialize
();
42
43
if
(
apr_pool_create
(&
pool
,
NULL
) !=
APR_SUCCESS
) {
44
exit
(-1);
45
}
46
47
rv =
apr_shm_attach
(&
shm
,
SHARED_FILENAME
,
pool
);
48
if
(rv !=
APR_SUCCESS
) {
49
exit
(-2);
50
}
51
52
boxes
=
apr_shm_baseaddr_get
(
shm
);
53
54
/* produce messages on all of the boxes, in descending order,
55
* Yes, we could just return N_BOXES, but I want to have a double-check
56
* in this code. The original code actually sent N_BOXES - 1 messages,
57
* so rather than rely on possibly buggy code, this way we know that we
58
* are returning the right number.
59
*/
60
for
(
i
=
N_BOXES
- 1,
sent
= 0;
i
>= 0;
i
--,
sent
++) {
61
msgput
(
MSG
,
i
);
62
apr_sleep
(
apr_time_from_sec
(1));
63
}
64
65
rv =
apr_shm_detach
(
shm
);
66
if
(rv !=
APR_SUCCESS
) {
67
exit
(-3);
68
}
69
70
return
sent
;
71
}
72
73
#else
/* APR_HAS_SHARED_MEMORY */
74
75
int
main
(
void
)
76
{
77
/* Just return, this program will never be launched, so there is no
78
* reason to print a message.
79
*/
80
return
0;
81
}
82
83
#endif
/* APR_HAS_SHARED_MEMORY */
84
apr_errno.h
APR Error Codes.
apr_general.h
APR Miscellaneous library routines.
apr_lib.h
APR general purpose library routines.
apr_shm.h
APR Shared Memory Routines.
apr_strings.h
APR Strings library.
apr_time.h
APR Time Library.
size
apr_size_t size
Definition
apr_allocator.h:115
pool
const char int apr_pool_t * pool
Definition
apr_cstr.h:84
APR_SUCCESS
#define APR_SUCCESS
Definition
apr_errno.h:225
apr_status_t
int apr_status_t
Definition
apr_errno.h:44
apr_pool_create
#define apr_pool_create(newpool, parent)
Definition
apr_pools.h:322
shm
apr_shm_t * shm
Definition
apr_portable.h:293
apr_time_from_sec
#define apr_time_from_sec(sec)
Definition
apr_time.h:78
NULL
return NULL
Definition
mod_so.c:359
i
int i
Definition
mod_so.c:347
apr_pool_t
Definition
apr_pools.c:562
apr_shm_t
Definition
apr_arch_shm.h:61
testshm.h
MSG
#define MSG
Definition
testshm.h:37
boxes
mbox * boxes
Definition
testshm.h:31
SHARED_FILENAME
#define SHARED_FILENAME
Definition
testshm.h:36
N_BOXES
#define N_BOXES
Definition
testshm.h:33
main
int main(void)
Definition
testshmproducer.c:75
Generated by
1.9.8