This commit is contained in:
stormrider1982 2004-02-19 11:23:14 +00:00
parent ac5359281a
commit 07337a9da4

46
src/nzg_pool.c Normal file
View file

@ -0,0 +1,46 @@
# include "libnazgul.h"
msgPool * msgPoolCreate(
msgSpacePoolId poolId,
int buffNb,
int buffSize,
int * firstBuffIdx,
bool overload
//pid[]
//liste process demandeurs
) {
int pool;
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 ) {
fprintf( stderr, "msgPool creation failed: %s\n",
strerror( errno ) );
return NULL;
}
// on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs
if (ftruncate(pool, sizeof((buffSize)*buffNb)) == -1){
fprintf( stderr, "msgPool resizing failed: %s\n",
strerror( errno ) );
return NULL;
}
// donne l'adr en mappant in the memory
poolAdr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, pool, 0);
return poolAdr;
}
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);
}