You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by aa...@apache.org on 2002/01/23 00:56:23 UTC
cvs commit: apr/test testshm.c testshmconsumer.c testshmproducer.c
aaron 02/01/22 15:56:23
Modified: test testshm.c testshmconsumer.c testshmproducer.c
Log:
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.
Revision Changes Path
1.4 +16 -0 apr/test/testshm.c
Index: testshm.c
===================================================================
RCS file: /home/cvs/apr/test/testshm.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- testshm.c 17 Jan 2002 00:30:47 -0000 1.3
+++ testshm.c 22 Jan 2002 23:56:23 -0000 1.4
@@ -170,6 +170,14 @@
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;
@@ -261,6 +269,14 @@
printf("Consumer was unsuccessful.\n");
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);
1.3 +12 -6 apr/test/testshmconsumer.c
Index: testshmconsumer.c
===================================================================
RCS file: /home/cvs/apr/test/testshmconsumer.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- testshmconsumer.c 16 Jan 2002 20:52:59 -0000 1.2
+++ testshmconsumer.c 22 Jan 2002 23:56:23 -0000 1.3
@@ -84,14 +84,14 @@
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 @@
}
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;
}
1.3 +11 -5 apr/test/testshmproducer.c
Index: testshmproducer.c
===================================================================
RCS file: /home/cvs/apr/test/testshmproducer.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- testshmproducer.c 16 Jan 2002 20:53:00 -0000 1.2
+++ testshmproducer.c 22 Jan 2002 23:56:23 -0000 1.3
@@ -79,7 +79,7 @@
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 @@
}
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 @@
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;
}