From 418a0b544854a0a98a987b2a04b513ee8373b80c Mon Sep 17 00:00:00 2001 From: glenux Date: Thu, 19 Feb 2004 11:49:25 +0000 Subject: [PATCH] * correction de problemes du au changement de types des ID --- src/nzg_iface.h | 15 ++++++------ src/nzg_pool.c | 59 +++++++++++++++++++++++++++--------------------- src/nzg_proto.h | 26 ++++++++------------- src/nzg_spaces.c | 34 ++++++++++++++++------------ 4 files changed, 71 insertions(+), 63 deletions(-) diff --git a/src/nzg_iface.h b/src/nzg_iface.h index b74393b..aeba9c3 100644 --- a/src/nzg_iface.h +++ b/src/nzg_iface.h @@ -4,16 +4,17 @@ #include "nzg_global.h" #define MSGSPACE_DEFAULT_MODE 0600 +#define MSGSPACE_ID_LEN 32 -typedef char * msgSpaceId; +typedef char msgSpaceId[MSGSPACE_ID_LEN]; -typedef char * msgSpaceListId; -typedef char * msgSpaceListElemId; +typedef char msgSpaceListId[4*MSGSPACE_ID_LEN]; +typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN]; -typedef char * msgSpacePoolDataId; -typedef char * msgSpacePoolId; -typedef char * msgSpaceQueueDataId; -typedef char * msgSpaceQueueId; +typedef char msgSpacePoolDataId[4*MSGSPACE_ID_LEN]; +typedef char msgSpacePoolId[4*MSGSPACE_ID_LEN]; +typedef char msgSpaceQueueDataId[4*MSGSPACE_ID_LEN]; +typedef char msgSpaceQueueId[4*MSGSPACE_ID_LEN]; /* pid[] */ /* liste des processus demandeurs */ diff --git a/src/nzg_pool.c b/src/nzg_pool.c index e3eb0be..c807c3f 100644 --- a/src/nzg_pool.c +++ b/src/nzg_pool.c @@ -1,46 +1,53 @@ # include "libnazgul.h" -msgPool * msgPoolCreate( +/* pid[] + liste process demandeurs */ + +int msgPoolCreate( msgSpacePoolId poolId, int buffNb, - int buffSize, - int * firstBuffIdx, - bool overload - //pid[] - //liste process demandeurs - ) { + int buffSize + ) { - int pool; + int poolFd; + static int poolNb; msgSpacePoolId id; - msgPool * poolAdr; - id = msgSpacePoolId2nzgPoolId(poolId); - pool=shm_open(id,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE); - if (pool == -1 ) { + if (msgSpacePoolId2nzgPoolId(id,poolId,poolNb) == -1){ + fprintf( stderr, "msgPoolId creation failed for id %s\n", + (char*)poolId ); + return -1; + } + + poolFd=shm_open(id,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE); + if (poolFd == -1 ) { fprintf( stderr, "msgPool creation failed: %s\n", strerror( errno ) ); - return NULL; - } + return -1; + } // on met le pool a la taille voulue pour qu'il // puisse contenir les buffs - if (ftruncate(pool, sizeof((buffSize)*buffNb)) == -1){ + if (ftruncate(poolFd, sizeof((buffSize)*buffNb)) == -1){ fprintf( stderr, "msgPool resizing failed: %s\n", strerror( errno ) ); - return NULL; + return -1; } - // donne l'adr en mappant in the memory - poolAdr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, pool, 0); + close(poolFd); - return poolAdr; + return 0; } -msgSpacePoolId msgSpacePoolId2nzgPoolId(msgSpacePoolId poolId, int num){ - char * resId; - int slen; - slen=strlen(poolId); - resId = (char *)malloc(sizeof(char)*(slen+11)); - sprintf(resId,"/tmp/.nzg-%s-",(char *)poolId); - return ((msgSpacePoolId)resId); +int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest,msgSpacePoolId src, int num){ + if (strlen(src)>MSGSPACE_ID_LEN){ + return -1; + } + sprintf(dest,"/nzgSpacesPool%s%d",(char *)src,num); + return 0; } + +//TODO: msgPoolAllocate +// //donne l'adr en mappant in the memory + //poolAddr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, poolFd, 0); + diff --git a/src/nzg_proto.h b/src/nzg_proto.h index 2353ac9..3ab05eb 100644 --- a/src/nzg_proto.h +++ b/src/nzg_proto.h @@ -1,23 +1,17 @@ #ifndef _NZG_PROTO #define _NZG_PROTO 1 +/* nzg_list.c */ char **msgSpaceIdList(void); - -void * msgAllocate( - msgSpace * space, //espace de message concerné - int pool, //numéro de pool ou réaliser l'allocation - int taille, //si l'argument précédent est ANYPOOL, taille requise - int option // 0 ou NONBLOCK - ); - - -/* nzg_create.c */ -msgSpace *msgSpaceCreate( - msgSpaceId spaceId, int queueNb, int poolNb, msgPool *queueNbCar - ); - +/* nzg_pool.c */ +int msgPoolCreate(msgSpacePoolId poolId, int buffNb, int buffSize); +int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest, msgSpacePoolId src, int num); +/* nzg_spaces.c */ +msgSpace *msgSpaceCreate(msgSpaceId spaceId, int queueNb, int poolNb, msgPool *queueNbCar); msgSpace *msgSpaceOpen(msgSpaceId spaceId); -void msgSpaceDelete(msgSpaceId spaceId); -msgSpaceId msgSp2nzgId(msgSpaceId spaceId); +int msgSpaceDelete(msgSpaceId spaceId); +int msgSp2nzgId(msgSpaceId dest, const msgSpaceId src); +/* nzg_state.c */ + #endif diff --git a/src/nzg_spaces.c b/src/nzg_spaces.c index a1ca57c..7aa57c9 100644 --- a/src/nzg_spaces.c +++ b/src/nzg_spaces.c @@ -14,7 +14,7 @@ msgSpace * msgSpaceCreate( int poolNb, msgPool * queueNbCar ){ msgSpaceId nzgId; - msgSpaceList mSList; + //msgSpaceList mSList; int mSFd; // shm file descriptor int i; static int mSIdNum=-1; @@ -27,7 +27,7 @@ msgSpace * msgSpaceCreate( /** on créee le nouvel element **/ printf("PAGESIZE : %d\n",(int)PAGESIZE); - nzgId=msgSp2nzgId(spaceId); + msgSp2nzgId(spaceId,nzgId); mSFd=shm_open( nzgId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, @@ -87,7 +87,8 @@ msgSpace * msgSpaceCreate( msgSpace * msgSpaceOpen(msgSpaceId spaceId){ int shmId; - char * nzgId=msgSp2nzgId(spaceId); + msgSpaceId nzgId; + if (msgSp2nzgId(nzgId,spaceId)); if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){ perror("shm_open"); return NULL; @@ -95,21 +96,26 @@ msgSpace * msgSpaceOpen(msgSpaceId spaceId){ return NULL; } -void msgSpaceDelete(msgSpaceId spaceId){ +int msgSpaceDelete(msgSpaceId spaceId){ //int shmId; - msgSpaceId nzgId=msgSp2nzgId(spaceId); - int er; - if ((er=shm_unlink(nzgId))<0){ + msgSpaceId nzgId; + if (msgSp2nzgId(nzgId,spaceId) == -1){ + //TODO: message d'erreur + return -1; + } + + if (shm_unlink(nzgId)<0){ perror("shm_unlink"); + return -1; }; + return 0; } -msgSpaceId msgSp2nzgId(msgSpaceId spaceId){ - char * resNzgId; - int slen; - slen=strlen(spaceId); - resNzgId = (char *)malloc(sizeof(char)*(slen+11)); +int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){ + if (strlen(src)>MSGSPACE_ID_LEN){ + return -1; + } /* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */ - sprintf(resNzgId,"/nzgSpace%s",(char *)spaceId); - return ((msgSpaceId)resNzgId); + sprintf(dest,"/nzgSpace%s",(char *)src); + return 0; }