From b54dc1c8ec88e63d4f476332273cea914df54488 Mon Sep 17 00:00:00 2001 From: glenux Date: Sat, 21 Feb 2004 18:50:38 +0000 Subject: [PATCH] *** empty log message *** --- src/nzg_global.h | 5 +++++ src/nzg_ids.c | 2 +- src/nzg_ids.h | 2 +- src/nzg_iface.h | 8 ++++---- src/nzg_pool.c | 3 ++- src/nzg_spaces.c | 35 ++++++++++++++++++++++++++--------- test/Makefile | 14 ++++++++++---- 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/nzg_global.h b/src/nzg_global.h index ece9009..68fb7ce 100644 --- a/src/nzg_global.h +++ b/src/nzg_global.h @@ -17,4 +17,9 @@ #define SHM_DEFAULT_MODE 0600 #define MSGSPACE_ID_LEN 32 #define ERR_UNHANDLED "Gérer mieu les erreurs" + +#ifndef SEM_FAILED +#define SEM_FAILED ((sem_t *)0) +#endif + #endif diff --git a/src/nzg_ids.c b/src/nzg_ids.c index 928abbc..d0e39e1 100644 --- a/src/nzg_ids.c +++ b/src/nzg_ids.c @@ -33,7 +33,7 @@ int msgPoolSemIdIntern( return 0; } -int msgPoolDataIdIntern(msgPoolDataId dest,const msgSpaceId src ){ +int msgPoolDataIdIntern(msgPoolDataTabId dest,const msgSpaceId src ){ if (strlen(src)>MSGSPACE_ID_LEN){ return -1; } diff --git a/src/nzg_ids.h b/src/nzg_ids.h index ef77d7e..61f9a16 100644 --- a/src/nzg_ids.h +++ b/src/nzg_ids.h @@ -7,7 +7,7 @@ /* nzg_ids.c */ int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src); int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx); -int msgPoolDataIdIntern(msgPoolDataId dest, const msgSpaceId src); +int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src); int msgSpacePoolId2nzgPoolId(msgPoolId dest, msgPoolId src, int num); diff --git a/src/nzg_iface.h b/src/nzg_iface.h index d0fe46b..1fd07df 100644 --- a/src/nzg_iface.h +++ b/src/nzg_iface.h @@ -10,8 +10,8 @@ typedef char msgSpaceId[MSGSPACE_ID_LEN]; typedef char msgSpaceListId[4*MSGSPACE_ID_LEN]; typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN]; -typedef char msgPoolDataId[4*MSGSPACE_ID_LEN]; -typedef char msgPoolDataSemId[4*MSGSPACE_ID_LEN]; +typedef char msgPoolDataTabId[4*MSGSPACE_ID_LEN]; +typedef char msgPoolDataTabSemId[4*MSGSPACE_ID_LEN]; typedef char msgPoolId[4*MSGSPACE_ID_LEN]; typedef char msgPoolSemId[4*MSGSPACE_ID_LEN]; @@ -42,8 +42,8 @@ typedef struct MsgSpace { int poolNb; int queueNb; int pid; - msgPoolDataId poolDataId; - msgPoolDataSemId poolDataSemId; + msgPoolDataTabId poolDataTabId; + msgPoolDataTabSemId poolDataTabSemId; } msgSpace; diff --git a/src/nzg_pool.c b/src/nzg_pool.c index fd4684a..53fa9bc 100644 --- a/src/nzg_pool.c +++ b/src/nzg_pool.c @@ -1,4 +1,5 @@ -# include "libnazgul.h" +#include "libnazgul.h" +#include "nzg_ids.h" /* pid[] liste process demandeurs */ diff --git a/src/nzg_spaces.c b/src/nzg_spaces.c index e5f4f6e..7eba557 100644 --- a/src/nzg_spaces.c +++ b/src/nzg_spaces.c @@ -28,7 +28,7 @@ msgSpace * msgSpaceCreate( static int mSIdNum=-1; msgSpace * mSAddr; - msgPoolId poolDataId; + msgPoolId poolDataTabId; msgPoolData * mSPoolDataAddr; fprintf(stderr,"Creating msgSpace with id : %s\n",spaceId); @@ -85,16 +85,17 @@ msgSpace * msgSpaceCreate( mSAddr->pid=getpid(); /* creation du poolData */ - msgPoolDataIdIntern(poolDataId,spaceId); + msgPoolDataIdIntern(poolDataTabId,spaceId); + strcpy(mSAddr->poolDataTabId,poolDataTabId); mSPoolDataFd=shm_open( - poolDataId, + poolDataTabId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, MSGSPACE_DEFAULT_MODE ); if (mSPoolDataFd == -1 ) { fprintf( stderr, "poolData %s creation failed: %s\n", - (char*)poolDataId, + (char*)poolDataTabId, strerror( errno ) ); return NULL; } @@ -126,8 +127,10 @@ msgSpace * msgSpaceCreate( mSPoolDataAddr[i].bufferNb=poolInfos[i].bufferNb; mSPoolDataAddr[i].bufferSize=poolInfos[i].bufferSize; mSPoolDataAddr[i].allocDispBuffer=0; - mSPoolDataAddr[i].allocOverload=false; - //TODO: remplir l'ID : mSPoolDataAddr[i].id + + msgPoolId poolId; + msgPoolCreate(poolId,poolInfos[i].bufferNb,poolInfos[i].bufferSize); + strcpy(mSPoolDataAddr[i].id,poolId); } @@ -143,27 +146,41 @@ msgSpace * msgSpaceCreate( */ msgSpace * msgSpaceOpen(msgSpaceId spaceId){ - int shmId; + int shmFd; msgSpaceId nzgId; + msgSpace * mSAddr; if (msgSpaceIdIntern(nzgId,spaceId) < 0){ return NULL; } - if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){ + if ((shmFd=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){ perror("shm_open"); return NULL; } - return NULL; + mSAddr=mmap(NULL,sizeof(msgSpace),PROT_READ|PROT_WRITE,MAP_SHARED,shmFd,(off_t)0); + + return mSAddr; } int msgSpaceDelete(msgSpaceId spaceId){ fprintf(stderr,"Deleting msgSpace with id : %s\n",spaceId); //int shmId; msgSpaceId nzgId; + msgSpace * space; if (msgSpaceIdIntern(nzgId,spaceId) == -1){ //TODO: message d'erreur return -1; } + space = msgSpaceOpen(spaceId); + + printf("openned successfully !\n"); + printf("Unlinking DataTab... "); + if (shm_unlink(space->poolDataTabId) < 0){ + perror("shm_unlink"); + return -1; + } + printf("ok\n"); + if (shm_unlink(nzgId)<0){ perror("shm_unlink"); return -1; diff --git a/test/Makefile b/test/Makefile index e2798a6..aeb1886 100644 --- a/test/Makefile +++ b/test/Makefile @@ -9,18 +9,24 @@ OS=$(shell uname -s) CC=gcc -CFLAGS=-Wall --static -O2 -ggdb +CFLAGS=-Wall -O2 -ggdb #-O2 -ggdb INCLUDES=-I /usr/include -I ../src/ LIBINC=-L /usr/lib -L ../src -LIBS=-lnazgul +BASELIBS=-lnazgul +LIBS=$(BASELIBS) + +ifeq "HP-UX" "${OS}" + LIBS=$(BASELIBS) -lpthread -lrt +endif + ifeq "SunOS" "${OS}" - LIBS=-lnazgul -lrt + LIBS=$(BASELIBS) -lrt endif ifeq "Linux" "${OS}" - LIBS=-lnazgul -lrt -lpthread + LIBS=$(BASELIBS) -lrt -lpthread endif PRJNAME=Libnazgul