* 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"
#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 */

View file

@ -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);

View file

@ -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

View file

@ -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;
}