From 79e236268127012abf6530b7eae8f4e82b30548e Mon Sep 17 00:00:00 2001 From: jcej Date: Sun, 1 Aug 1999 22:19:49 +0000 Subject: *** empty log message *** --- ChangeLog-99b | 14 +++++ docs/tutorials/Chap_3/Makefile | 29 ++++++++++ docs/tutorials/Chap_3/README | 14 +++++ docs/tutorials/Chap_3/ex03.html | 115 ++++++++++++++++++++++++++++++++++++++++ docs/tutorials/Chap_3/mm.cpp | 113 +++++++++++++++++++++++++++++++++++++++ docs/tutorials/colorize | 2 + 6 files changed, 287 insertions(+) create mode 100644 docs/tutorials/Chap_3/Makefile create mode 100644 docs/tutorials/Chap_3/README create mode 100644 docs/tutorials/Chap_3/ex03.html create mode 100644 docs/tutorials/Chap_3/mm.cpp diff --git a/ChangeLog-99b b/ChangeLog-99b index 32cab706aff..2d1c7df64b3 100644 --- a/ChangeLog-99b +++ b/ChangeLog-99b @@ -1,3 +1,17 @@ +Sun Aug 1 15:58:39 1999 James CE Johnson + + * docs/tutorials/colorize: Added
 wrapper around generated
+    output.
+
+  * docs/tutorials/Chap_03/Makefile:
+  * docs/tutorials/Chap_03/README:
+  * docs/tutorials/Chap_03/mm.cpp:
+  * docs/tutorials/Chap_03/ex03.html:
+    mm.cpp (and ex03.html) are a slightly modified version of ex02.html
+    that uses a memory mapped file instead of SYSV SHMEM.  To work around
+    the lack of fork() in Win32, the app must be executed once in server
+    mode (argv[1] == 's') and again in client mode.
+
 Sun Aug  1 15:58:39 1999  Douglas C. Schmidt  
 
 	* ace/Memory_Pool.cpp: If the base_addr is 0 for the
diff --git a/docs/tutorials/Chap_3/Makefile b/docs/tutorials/Chap_3/Makefile
new file mode 100644
index 00000000000..e3f1f3ae1c8
--- /dev/null
+++ b/docs/tutorials/Chap_3/Makefile
@@ -0,0 +1,29 @@
+#----------------------------------------------------------------------------
+#
+# $Id$
+#
+#       Makefile for all the ACE ``one-button' tests
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+#       Local macros
+#----------------------------------------------------------------------------
+
+BIN =   mm
+
+PSRC=$(addsuffix .cpp,$(BIN))
+
+#----------------------------------------------------------------------------
+#       Include macros and targets
+#----------------------------------------------------------------------------
+
+include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
+include $(ACE_ROOT)/include/makeinclude/macros.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.common.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU
+
+include $(ACE_ROOT)/include/makeinclude/rules.local.GNU
+
+ex03.html : mm.cpp
+	../colorize < mm.cpp > ex03.html
diff --git a/docs/tutorials/Chap_3/README b/docs/tutorials/Chap_3/README
new file mode 100644
index 00000000000..228579ca4c5
--- /dev/null
+++ b/docs/tutorials/Chap_3/README
@@ -0,0 +1,14 @@
+Note:
+
+Example 2 (ex02.html) will not compile and work on Win32 because
+it relies on SystemV Shared Memory and fork() which are not
+available on that platoform.
+
+Example 3 (ex03.html) is basically the same but uses a memory-mapped
+file instead of SYSV Shared Memory.  It also takes a single command
+line parament 's' to start it in server mode or 'c' to start it
+in client mode.  (This is to work around the lack of fork()).
+
+(Thanks to Nanbor Wang for working this out for us.)
+
+JCEJ - 08/01/1999
diff --git a/docs/tutorials/Chap_3/ex03.html b/docs/tutorials/Chap_3/ex03.html
new file mode 100644
index 00000000000..743f0b395d2
--- /dev/null
+++ b/docs/tutorials/Chap_3/ex03.html
@@ -0,0 +1,115 @@
+
+// $Id$
+
+#include "ace/Memory_Pool.h"
+#include "ace/Shared_Memory_MM.h"
+#include "ace/Malloc.h"
+#include "ace/Malloc_T.h"
+#include "ace/Thread_Manager.h"
+
+#define DATA_SIZE 100
+#define MESSAGE1 "Hiya over there client process"
+#define MESSAGE2  "Did you hear me the first time?"
+LPCTSTR poolname="My_Pool";
+
+typedef ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> Malloc_Allocator;
+
+static void *
+server (void * = 0)
+{
+  ACE_MMAP_Memory_Pool_Options opt;
+
+  //Create the memory allocator passing it the shared memory
+  //pool that you want to use
+  Malloc_Allocator shm_allocator(poolname,poolname,&opt);
+
+  //Create a message, allocate memory for it and bind it with
+  //a name so that the client can the find it in the memory
+  //pool
+  char* Message1=(char*)shm_allocator.malloc(strlen(MESSAGE1)+1);
+
+  ACE_OS::strcpy(Message1,MESSAGE1);
+  shm_allocator.bind("FirstMessage",Message1);
+  ACE_DEBUG((LM_DEBUG,"<<%s\n",Message1));
+
+  //How about a second message
+  char* Message2=(char*)shm_allocator.malloc(strlen(MESSAGE2)+1);
+  ACE_OS::strcpy(Message2,MESSAGE2);
+  shm_allocator.bind("SecondMessage",Message2);
+  ACE_DEBUG((LM_DEBUG,"<<%s\n",Message2));
+
+  //Set the Server to go to sleep for a while so that the client has
+  //a chance to do its stuff
+  ACE_DEBUG((LM_DEBUG, "Server done writing.. going to sleep zzz..\n\n\n"));
+  ACE_OS::sleep(10); 
+
+  ACE_DEBUG ((LM_DEBUG, "server exit\n"));
+
+  return 0;
+}
+
+static void *
+client (void * = 0)
+{
+  ACE_MMAP_Memory_Pool_Options opt;
+
+  //Create the memory allocator passing it the shared memory
+  //pool that you want to use
+  Malloc_Allocator shm_allocator(poolname,poolname,&opt);
+
+  //Lets get that first message.  Notice that the find is looking up the
+  //memory based on the "name" that was bound to it by the server.
+  void *Message1 = 0;
+  if(shm_allocator.find("FirstMessage") == -1 )
+    {
+      ACE_ERROR((LM_ERROR,
+                 "Client ack\n"));
+      return 0;
+    }
+  if(shm_allocator.find("FirstMessage",Message1)==-1)
+    {
+      ACE_ERROR((LM_ERROR,
+                 "Client: Problem cant find data that server has sent\n"));
+      return 0;
+    }
+
+  ACE_OS::printf(">>%s\n",(char*) Message1);
+  ACE_OS::fflush(stdout);
+
+  //Lets get that second message now.
+  void *Message2;
+  if(shm_allocator.find("SecondMessage",Message2)==-1)
+    {
+      ACE_ERROR((LM_ERROR,
+                 "Client: Problem cant find data that server has sent\n"));
+      ACE_OS::exit(1);
+    }
+  ACE_OS::printf(">>%s\n",(char*)Message2);
+  ACE_OS::fflush(stdout);
+
+  ACE_DEBUG((LM_DEBUG,"Client done reading! BYE NOW\n"));
+  ACE_OS::fflush(stdout);
+
+  //Get rid of all resources allocated by the server. In other
+  //words get rid of the shared memory pool that had been
+  //previously allocated
+  shm_allocator.remove();
+
+  return 0;
+}
+
+int main (int, char *argv[])
+{
+  switch (*argv[1])
+    {
+    case 's':
+      server ();
+      break;
+    default:
+      client ();
+      break;
+    }
+
+  return 0;
+}
+
diff --git a/docs/tutorials/Chap_3/mm.cpp b/docs/tutorials/Chap_3/mm.cpp new file mode 100644 index 00000000000..2be56fbcc9a --- /dev/null +++ b/docs/tutorials/Chap_3/mm.cpp @@ -0,0 +1,113 @@ +// $Id$ + +#include "ace/Memory_Pool.h" +#include "ace/Shared_Memory_MM.h" +#include "ace/Malloc.h" +#include "ace/Malloc_T.h" +#include "ace/Thread_Manager.h" + +#define DATA_SIZE 100 +#define MESSAGE1 "Hiya over there client process" +#define MESSAGE2 "Did you hear me the first time?" +LPCTSTR poolname="My_Pool"; + +typedef ACE_Malloc Malloc_Allocator; + +static void * +server (void * = 0) +{ + ACE_MMAP_Memory_Pool_Options opt; + + //Create the memory allocator passing it the shared memory + //pool that you want to use + Malloc_Allocator shm_allocator(poolname,poolname,&opt); + + //Create a message, allocate memory for it and bind it with + //a name so that the client can the find it in the memory + //pool + char* Message1=(char*)shm_allocator.malloc(strlen(MESSAGE1)+1); + + ACE_OS::strcpy(Message1,MESSAGE1); + shm_allocator.bind("FirstMessage",Message1); + ACE_DEBUG((LM_DEBUG,"<<%s\n",Message1)); + + //How about a second message + char* Message2=(char*)shm_allocator.malloc(strlen(MESSAGE2)+1); + ACE_OS::strcpy(Message2,MESSAGE2); + shm_allocator.bind("SecondMessage",Message2); + ACE_DEBUG((LM_DEBUG,"<<%s\n",Message2)); + + //Set the Server to go to sleep for a while so that the client has + //a chance to do its stuff + ACE_DEBUG((LM_DEBUG, "Server done writing.. going to sleep zzz..\n\n\n")); + ACE_OS::sleep(10); + + ACE_DEBUG ((LM_DEBUG, "server exit\n")); + + return 0; +} + +static void * +client (void * = 0) +{ + ACE_MMAP_Memory_Pool_Options opt; + + //Create the memory allocator passing it the shared memory + //pool that you want to use + Malloc_Allocator shm_allocator(poolname,poolname,&opt); + + //Lets get that first message. Notice that the find is looking up the + //memory based on the "name" that was bound to it by the server. + void *Message1 = 0; + if(shm_allocator.find("FirstMessage") == -1 ) + { + ACE_ERROR((LM_ERROR, + "Client ack\n")); + return 0; + } + if(shm_allocator.find("FirstMessage",Message1)==-1) + { + ACE_ERROR((LM_ERROR, + "Client: Problem cant find data that server has sent\n")); + return 0; + } + + ACE_OS::printf(">>%s\n",(char*) Message1); + ACE_OS::fflush(stdout); + + //Lets get that second message now. + void *Message2; + if(shm_allocator.find("SecondMessage",Message2)==-1) + { + ACE_ERROR((LM_ERROR, + "Client: Problem cant find data that server has sent\n")); + ACE_OS::exit(1); + } + ACE_OS::printf(">>%s\n",(char*)Message2); + ACE_OS::fflush(stdout); + + ACE_DEBUG((LM_DEBUG,"Client done reading! BYE NOW\n")); + ACE_OS::fflush(stdout); + + //Get rid of all resources allocated by the server. In other + //words get rid of the shared memory pool that had been + //previously allocated + shm_allocator.remove(); + + return 0; +} + +int main (int, char *argv[]) +{ + switch (*argv[1]) + { + case 's': + server (); + break; + default: + client (); + break; + } + + return 0; +} diff --git a/docs/tutorials/colorize b/docs/tutorials/colorize index 60ffaae1348..ee61d4bfb14 100755 --- a/docs/tutorials/colorize +++ b/docs/tutorials/colorize @@ -2,6 +2,7 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' & eval 'exec perl -S $0 $argv:q' if 0; +print "
\n";
 while(  )
 {
   s/ )
   s,\w+::\~?\w+,$&,;
   print STDOUT $_;
 }
+print "
\n"; 0; -- cgit v1.2.1