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

LOW_sharedMemSegment_SysV.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_sharedMemSegmentSysV.cpp  -  description
00003                              -------------------
00004     begin                : Tue Jul 30 2002
00005     copyright            : (C) 2002 by Harald Roelle, Helmut Reiser
00006     email                : roelle@informatik.uni-muenchen.de, reiser@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017        
00018        
00019 #include <errno.h>
00020 #include <sys/ipc.h>
00021 #include <sys/shm.h>
00022 
00023  
00024 #include "LOW_sharedMemSegment_SysV.h"
00025 
00026 
00027 //=====================================================================================
00028 //
00029 // constructors
00030 //
00031 
00032 LOW_sharedMemSegment_SysV::LOW_sharedMemSegment_SysV( const LOW_sharedMemSegmentFactory::sharedMemSegmentIPCKey_t inKey, const unsigned int inSize) :
00033   sharedMemSegKey( inKey)
00034 {
00035   if ( (sharedMemSegID=shmget( sharedMemSegKey, inSize, SHM_PERMS)) == -1 ) {
00036   
00037     if ( errno == ENOENT ) {  // existed not yet, so create new segment
00038 
00039       if ( (sharedMemSegID=shmget( sharedMemSegKey, inSize, SHM_PERMS | IPC_CREAT)) == -1 )  // create segment
00040         throw sharedMemSeg_error( errno, "Failed to create new shared memory segment", __FILE__, __LINE__);
00041 
00042     }
00043     else {
00044       throw sharedMemSeg_error( errno, "Error getting shared memory segment", __FILE__, __LINE__);
00045     }
00046   }
00047 
00048   if ( (sharedMemPtr=shmat( sharedMemSegID, 0, 0)) == (void*)-1 )
00049     throw sharedMemSeg_error( errno, "Error attaching shared memory segment", __FILE__, __LINE__);
00050 }
00051 
00052 
00053 LOW_sharedMemSegment_SysV::~LOW_sharedMemSegment_SysV()
00054 {
00055   struct shmid_ds  dummy;
00056   shmctl( sharedMemSegID, IPC_RMID, &dummy);
00057   shmdt( sharedMemPtr);
00058 }
00059 
00060 
00061 
00062 //=====================================================================================
00063 //
00064 // methods
00065 //
00066   
00067 void* LOW_sharedMemSegment_SysV::get() const
00068 {
00069   return sharedMemPtr;
00070 }
00071 

Generated on Sun Jan 12 21:07:43 2003 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001