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.
18
#include "apr_errno.h"
19
#include "apr_general.h"
21
#include "apr_strings.h"
31
#if APR_HAS_SHARED_MEMORY
33
static int msgwait(int sleep_sec, int first_box, int last_box)
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)) {
43
boxes[i].msgavail = 0; /* reset back to 0 */
44
memset(boxes[i].msg, 0, 1024);
47
apr_sleep(apr_time_from_sec(1));
61
if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
65
rv = apr_shm_attach(&shm, SHARED_FILENAME, pool);
66
if (rv != APR_SUCCESS) {
70
boxes = apr_shm_baseaddr_get(shm);
72
/* consume messages on all of the boxes */
73
recvd = msgwait(30, 0, N_BOXES); /* wait for 30 seconds for messages */
75
rv = apr_shm_detach(shm);
76
if (rv != APR_SUCCESS) {
83
#else /* APR_HAS_SHARED_MEMORY */
87
/* Just return, this program will never be called, so we don't need
93
#endif /* APR_HAS_SHARED_MEMORY */