* correction de problemes du au changement de types des ID

This commit is contained in:
glenux 2004-02-19 11:49:25 +00:00
parent 07337a9da4
commit 418a0b5448
4 changed files with 71 additions and 63 deletions

View file

@ -4,16 +4,17 @@
#include "nzg_global.h" #include "nzg_global.h"
#define MSGSPACE_DEFAULT_MODE 0600 #define MSGSPACE_DEFAULT_MODE 0600
#define MSGSPACE_ID_LEN 32
typedef char * msgSpaceId; typedef char msgSpaceId[MSGSPACE_ID_LEN];
typedef char * msgSpaceListId; typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
typedef char * msgSpaceListElemId; typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN];
typedef char * msgSpacePoolDataId; typedef char msgSpacePoolDataId[4*MSGSPACE_ID_LEN];
typedef char * msgSpacePoolId; typedef char msgSpacePoolId[4*MSGSPACE_ID_LEN];
typedef char * msgSpaceQueueDataId; typedef char msgSpaceQueueDataId[4*MSGSPACE_ID_LEN];
typedef char * msgSpaceQueueId; typedef char msgSpaceQueueId[4*MSGSPACE_ID_LEN];
/* pid[] */ /* pid[] */
/* liste des processus demandeurs */ /* liste des processus demandeurs */

View file

@ -1,46 +1,53 @@
# include "libnazgul.h" # include "libnazgul.h"
msgPool * msgPoolCreate( /* pid[]
liste process demandeurs */
int msgPoolCreate(
msgSpacePoolId poolId, msgSpacePoolId poolId,
int buffNb, int buffNb,
int buffSize, int buffSize
int * firstBuffIdx,
bool overload
//pid[]
//liste process demandeurs
) { ) {
int pool; int poolFd;
static int poolNb;
msgSpacePoolId id; msgSpacePoolId id;
msgPool * poolAdr;
id = msgSpacePoolId2nzgPoolId(poolId); if (msgSpacePoolId2nzgPoolId(id,poolId,poolNb) == -1){
pool=shm_open(id,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE); fprintf( stderr, "msgPoolId creation failed for id %s\n",
if (pool == -1 ) { (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", fprintf( stderr, "msgPool creation failed: %s\n",
strerror( errno ) ); strerror( errno ) );
return NULL; return -1;
} }
// on met le pool a la taille voulue pour qu'il // on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs // 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", fprintf( stderr, "msgPool resizing failed: %s\n",
strerror( errno ) ); strerror( errno ) );
return NULL; return -1;
} }
// donne l'adr en mappant in the memory close(poolFd);
poolAdr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, pool, 0);
return poolAdr; return 0;
} }
msgSpacePoolId msgSpacePoolId2nzgPoolId(msgSpacePoolId poolId, int num){ int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest,msgSpacePoolId src, int num){
char * resId; if (strlen(src)>MSGSPACE_ID_LEN){
int slen; return -1;
slen=strlen(poolId); }
resId = (char *)malloc(sizeof(char)*(slen+11)); sprintf(dest,"/nzgSpacesPool%s%d",(char *)src,num);
sprintf(resId,"/tmp/.nzg-%s-",(char *)poolId); return 0;
return ((msgSpacePoolId)resId);
} }
//TODO: msgPoolAllocate
// //donne l'adr en mappant in the memory
//poolAddr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, poolFd, 0);

View file

@ -1,23 +1,17 @@
#ifndef _NZG_PROTO #ifndef _NZG_PROTO
#define _NZG_PROTO 1 #define _NZG_PROTO 1
/* nzg_list.c */
char **msgSpaceIdList(void); char **msgSpaceIdList(void);
/* nzg_pool.c */
void * msgAllocate( int msgPoolCreate(msgSpacePoolId poolId, int buffNb, int buffSize);
msgSpace * space, //espace de message concerné int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest, msgSpacePoolId src, int num);
int pool, //numéro de pool ou réaliser l'allocation /* nzg_spaces.c */
int taille, //si l'argument précédent est ANYPOOL, taille requise msgSpace *msgSpaceCreate(msgSpaceId spaceId, int queueNb, int poolNb, msgPool *queueNbCar);
int option // 0 ou NONBLOCK
);
/* nzg_create.c */
msgSpace *msgSpaceCreate(
msgSpaceId spaceId, int queueNb, int poolNb, msgPool *queueNbCar
);
msgSpace *msgSpaceOpen(msgSpaceId spaceId); msgSpace *msgSpaceOpen(msgSpaceId spaceId);
void msgSpaceDelete(msgSpaceId spaceId); int msgSpaceDelete(msgSpaceId spaceId);
msgSpaceId msgSp2nzgId(msgSpaceId spaceId); int msgSp2nzgId(msgSpaceId dest, const msgSpaceId src);
/* nzg_state.c */
#endif #endif

View file

@ -14,7 +14,7 @@ msgSpace * msgSpaceCreate(
int poolNb, int poolNb,
msgPool * queueNbCar ){ msgPool * queueNbCar ){
msgSpaceId nzgId; msgSpaceId nzgId;
msgSpaceList mSList; //msgSpaceList mSList;
int mSFd; // shm file descriptor int mSFd; // shm file descriptor
int i; int i;
static int mSIdNum=-1; static int mSIdNum=-1;
@ -27,7 +27,7 @@ msgSpace * msgSpaceCreate(
/** on créee le nouvel element **/ /** on créee le nouvel element **/
printf("PAGESIZE : %d\n",(int)PAGESIZE); printf("PAGESIZE : %d\n",(int)PAGESIZE);
nzgId=msgSp2nzgId(spaceId); msgSp2nzgId(spaceId,nzgId);
mSFd=shm_open( mSFd=shm_open(
nzgId, nzgId,
O_RDWR|O_CREAT|O_EXCL|O_TRUNC, O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
@ -87,7 +87,8 @@ msgSpace * msgSpaceCreate(
msgSpace * msgSpaceOpen(msgSpaceId spaceId){ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId; int shmId;
char * nzgId=msgSp2nzgId(spaceId); msgSpaceId nzgId;
if (msgSp2nzgId(nzgId,spaceId));
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){ if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open"); perror("shm_open");
return NULL; return NULL;
@ -95,21 +96,26 @@ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
return NULL; return NULL;
} }
void msgSpaceDelete(msgSpaceId spaceId){ int msgSpaceDelete(msgSpaceId spaceId){
//int shmId; //int shmId;
msgSpaceId nzgId=msgSp2nzgId(spaceId); msgSpaceId nzgId;
int er; if (msgSp2nzgId(nzgId,spaceId) == -1){
if ((er=shm_unlink(nzgId))<0){ //TODO: message d'erreur
return -1;
}
if (shm_unlink(nzgId)<0){
perror("shm_unlink"); perror("shm_unlink");
return -1;
}; };
return 0;
} }
msgSpaceId msgSp2nzgId(msgSpaceId spaceId){ int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){
char * resNzgId; if (strlen(src)>MSGSPACE_ID_LEN){
int slen; return -1;
slen=strlen(spaceId); }
resNzgId = (char *)malloc(sizeof(char)*(slen+11));
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */ /* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
sprintf(resNzgId,"/nzgSpace%s",(char *)spaceId); sprintf(dest,"/nzgSpace%s",(char *)src);
return ((msgSpaceId)resNzgId); return 0;
} }