Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

SV_Shared_Memory.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // SV_Shared_Memory.cpp
00003 // $Id: SV_Shared_Memory.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $
00004 
00005 #include "ace/SV_Shared_Memory.h"
00006 #include "ace/Log_Msg.h"
00007 
00008 #if !defined (__ACE_INLINE__)
00009 #include "ace/SV_Shared_Memory.i"
00010 #endif /* __ACE_INLINE__ */
00011 
00012 ACE_RCSID(ace, SV_Shared_Memory, "$Id: SV_Shared_Memory.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $")
00013 
00014 ACE_ALLOC_HOOK_DEFINE(ACE_SV_Shared_Memory)
00015 
00016 void
00017 ACE_SV_Shared_Memory::dump (void) const
00018 {
00019   ACE_TRACE ("ACE_SV_Shared_Memory::dump");
00020 }
00021 
00022 // Creates a shared memory segment of SIZE bytes and *does* attach to
00023 // this segment.
00024 
00025 int
00026 ACE_SV_Shared_Memory::open_and_attach (key_t external_id,
00027                                        size_t sz,
00028                                        int create,
00029                                        int perms,
00030                                        void *virtual_addr,
00031                                        int flags)
00032 {
00033   ACE_TRACE ("ACE_SV_Shared_Memory::open_and_attach");
00034   if (this->open (external_id, sz, create, perms) == -1)
00035     return -1;
00036   else if (this->attach (virtual_addr, flags) == -1)
00037     return -1;
00038   else
00039     return 0;
00040 }
00041 
00042 // Constructor interface to this->open_and_attach () member function.
00043 
00044 ACE_SV_Shared_Memory::ACE_SV_Shared_Memory (key_t external_id,
00045                                             size_t sz,
00046                                             int create,
00047                                             int perms,
00048                                             void *virtual_addr,
00049                                             int flags)
00050 {
00051   ACE_TRACE ("ACE_SV_Shared_Memory::ACE_SV_Shared_Memory");
00052   if (this->open_and_attach (external_id, sz, create,
00053                              perms, virtual_addr, flags) == -1)
00054     ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p\n"),
00055                 ACE_LIB_TEXT ("ACE_SV_Shared_Memory::ACE_SV_Shared_Memory")));
00056 }
00057 
00058 // The "do nothing" constructor.
00059 
00060 ACE_SV_Shared_Memory::ACE_SV_Shared_Memory (void)
00061   : internal_id_ (0),
00062     size_ (0),
00063     segment_ptr_ (0)
00064 {
00065   ACE_TRACE ("ACE_SV_Shared_Memory::ACE_SV_Shared_Memory");
00066 }
00067 
00068 // Added this constructor to accept an internal id, the one generated
00069 // when a server constructs with the key IPC_PRIVATE.  The client can
00070 // be passed ACE_SV_Shared_Memory::internal_id via a socket and call
00071 // this construtor to attach the existing segment.  This prevents
00072 // having to hard-code a key in advance.  Courtesy of Marvin Wolfthal
00073 // (maw@fsg.com).
00074 
00075 ACE_SV_Shared_Memory::ACE_SV_Shared_Memory (ACE_HANDLE int_id,
00076                                             int flags)
00077   : internal_id_ (int_id),
00078     size_ (0)
00079 {
00080   ACE_TRACE ("ACE_SV_Shared_Memory::ACE_SV_Shared_Memory");
00081   if (this->attach (0, flags) == -1)
00082     ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p\n"),
00083                 ACE_LIB_TEXT ("ACE_SV_Shared_Memory::ACE_SV_Shared_Memory")));
00084 }

Generated on Mon Jun 16 11:21:33 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002