SV_Shared_Memory.cpp

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

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6