diff --git a/src/nzg_pool.c b/src/nzg_pool.c new file mode 100644 index 0000000..e3eb0be --- /dev/null +++ b/src/nzg_pool.c @@ -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); +}