00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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 ) {
00038
00039 if ( (sharedMemSegID=shmget( sharedMemSegKey, inSize, SHM_PERMS | IPC_CREAT)) == -1 )
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
00065
00066
00067 void* LOW_sharedMemSegment_SysV::get() const
00068 {
00069 return sharedMemPtr;
00070 }
00071