voila
This commit is contained in:
parent
ac5359281a
commit
07337a9da4
1 changed files with 46 additions and 0 deletions
46
src/nzg_pool.c
Normal file
46
src/nzg_pool.c
Normal 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);
|
||||
}
|
Loading…
Reference in a new issue