summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bannert <aaron@apache.org>2002-01-22 23:56:23 +0000
committerAaron Bannert <aaron@apache.org>2002-01-22 23:56:23 +0000
commit62736066cd341b3fffd29543917af0d385ddf745 (patch)
tree6f4815f7d03ab3b9e8a45e7444e027bdd466c0e2
parent6d3db86d98c3c97876b3661abd644b899543277a (diff)
downloadapr-62736066cd341b3fffd29543917af0d385ddf745.tar.gz
Delete the apr_shm_t when we're done with it. (This didn't work before,
but I'm about to commit the implementation.) Add more verbose status/error messages -- most importantly making it obvious from which child (consumer or producer) the messages are comming from. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62815 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--test/testshm.c16
-rw-r--r--test/testshmconsumer.c18
-rw-r--r--test/testshmproducer.c16
3 files changed, 39 insertions, 11 deletions
diff --git a/test/testshm.c b/test/testshm.c
index 107ae390a..4592897c7 100644
--- a/test/testshm.c
+++ b/test/testshm.c
@@ -170,6 +170,14 @@ static apr_status_t test_anon(apr_pool_t *parpool)
return errno;
}
+ printf("Destroying shared memory segment...");
+ rv = apr_shm_destroy(shm);
+ if (rv != APR_SUCCESS) {
+ printf("FAILED\n");
+ return rv;
+ }
+ printf("OK\n");
+
apr_pool_destroy(pool);
return APR_SUCCESS;
@@ -262,6 +270,14 @@ static apr_status_t test_named(apr_pool_t *parpool)
return APR_EGENERAL;
}
+ printf("Destroying shared memory segment...");
+ rv = apr_shm_destroy(shm);
+ if (rv != APR_SUCCESS) {
+ printf("FAILED\n");
+ return rv;
+ }
+ printf("OK\n");
+
apr_pool_destroy(pool);
return APR_SUCCESS;
diff --git a/test/testshmconsumer.c b/test/testshmconsumer.c
index 045ce7e66..6fcf4b72f 100644
--- a/test/testshmconsumer.c
+++ b/test/testshmconsumer.c
@@ -84,14 +84,14 @@ static void msgwait(int sleep_sec, int first_box, int last_box)
while (apr_time_now() - start < sleep_sec * APR_USEC_PER_SEC) {
for (i = first_box; i < last_box; i++) {
if (boxes[i].msgavail) {
- fprintf(stdout, "received a message in box %d, message was: %s\n",
+ fprintf(stdout, "Consumer: received a message in box %d, message was: %s\n",
i, boxes[i].msg);
boxes[i].msgavail = 0; /* reset back to 0 */
}
}
apr_sleep(1*APR_USEC_PER_SEC);
}
- fprintf(stdout, "done waiting on mailboxes...\n");
+ fprintf(stdout, "Consumer: done waiting on mailboxes...\n");
}
int main(void)
@@ -112,24 +112,30 @@ int main(void)
}
printf("OK\n");
+ printf("Consumer attaching to name-based shared memory....");
rv = apr_shm_attach(&shm, SHARED_FILENAME, pool);
if (rv != APR_SUCCESS) {
- printf("Unable to attach to name-based shared memory segment: "
- "[%d] %s \n", rv, apr_strerror(rv, errmsg, sizeof(errmsg)));
+ printf("Consumer unable to attach to name-based shared memory "
+ "segment: [%d] %s \n", rv,
+ apr_strerror(rv, errmsg, sizeof(errmsg)));
exit(-2);
}
+ printf("OK\n");
boxes = apr_shm_baseaddr_get(shm);
/* consume messages on all of the boxes */
msgwait(30, 0, N_BOXES); /* wait for 30 seconds for messages */
+ printf("Consumer detaching from name-based shared memory....");
rv = apr_shm_detach(shm);
if (rv != APR_SUCCESS) {
- printf("Unable to detach from name-based shared memory segment: "
- "[%d] %s \n", rv, apr_strerror(rv, errmsg, sizeof(errmsg)));
+ printf("Consumer unable to detach from name-based shared memory "
+ "segment: [%d] %s \n", rv,
+ apr_strerror(rv, errmsg, sizeof(errmsg)));
exit(-3);
}
+ printf("OK\n");
return 0;
}
diff --git a/test/testshmproducer.c b/test/testshmproducer.c
index afb4f26ab..162eca19c 100644
--- a/test/testshmproducer.c
+++ b/test/testshmproducer.c
@@ -79,7 +79,7 @@ mbox *boxes;
static void msgput(int boxnum, char *msg)
{
- fprintf(stdout, "Sending message to box %d\n", boxnum);
+ fprintf(stdout, "Producer: Sending message to box %d\n", boxnum);
apr_cpystrn(boxes[boxnum].msg, msg, strlen(msg));
boxes[boxnum].msgavail = 1;
}
@@ -103,12 +103,15 @@ int main(void)
}
printf("OK\n");
+ printf("Producer attaching to name-based shared memory....");
rv = apr_shm_attach(&shm, SHARED_FILENAME, pool);
if (rv != APR_SUCCESS) {
- printf("Unable to attach to name-based shared memory segment: "
- "[%d] %s \n", rv, apr_strerror(rv, errmsg, sizeof(errmsg)));
+ printf("Producer unable to attach to name-based shared memory "
+ "segment: [%d] %s \n", rv,
+ apr_strerror(rv, errmsg, sizeof(errmsg)));
exit(-2);
}
+ printf("OK\n");
boxes = apr_shm_baseaddr_get(shm);
@@ -118,12 +121,15 @@ int main(void)
apr_sleep(1*APR_USEC_PER_SEC);
}
+ printf("Producer detaching from name-based shared memory....");
rv = apr_shm_detach(shm);
if (rv != APR_SUCCESS) {
- printf("Unable to detach from name-based shared memory segment: "
- "[%d] %s \n", rv, apr_strerror(rv, errmsg, sizeof(errmsg)));
+ printf("Producer unable to detach from name-based shared memory "
+ "segment: [%d] %s \n", rv,
+ apr_strerror(rv, errmsg, sizeof(errmsg)));
exit(-3);
}
+ printf("OK\n");
return 0;
}