2019-09-17 12:02:24 +00:00
|
|
|
|
# include "libnazgul.h"
|
|
|
|
|
|
|
|
|
|
/* pid[]
|
|
|
|
|
liste process demandeurs */
|
|
|
|
|
|
|
|
|
|
int msgPoolCreate(
|
|
|
|
|
msgSpacePoolId poolId,
|
|
|
|
|
int buffNb,
|
|
|
|
|
int buffSize
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
int poolFd;
|
|
|
|
|
static int poolNb;
|
|
|
|
|
msgSpacePoolId id;
|
|
|
|
|
|
|
|
|
|
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 -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// on met le pool a la taille voulue pour qu'il
|
|
|
|
|
// puisse contenir les buffs
|
2019-09-17 12:07:51 +00:00
|
|
|
|
if (ftruncate(poolFd, (buffSize*buffNb)) == -1){
|
2019-09-17 12:02:24 +00:00
|
|
|
|
fprintf( stderr, "msgPool resizing failed: %s\n",
|
|
|
|
|
strerror( errno ) );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(poolFd);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest,msgSpacePoolId src, int num){
|
|
|
|
|
if (strlen(src)>MSGSPACE_ID_LEN){
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2019-09-17 12:07:51 +00:00
|
|
|
|
#ifdef _NZG_REALFILEID
|
|
|
|
|
sprintf(dest,"/tmp/nzgSpacePool%s%d",(char *)src,num);
|
|
|
|
|
#else
|
|
|
|
|
sprintf(dest,"/nzgSpacePool%s%d",(char *)src,num);
|
|
|
|
|
#endif
|
2019-09-17 12:02:24 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: msgPoolAllocate
|
|
|
|
|
// //donne l'adr en mappant in the memory
|
|
|
|
|
//poolAddr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, poolFd, 0);
|
|
|
|
|
|
2019-09-17 12:17:58 +00:00
|
|
|
|
msgPool * msgPoolAllocate(int poolIdx, msgSpace *msg) {
|
2019-09-17 12:16:29 +00:00
|
|
|
|
msgPool * poolAddr;
|
|
|
|
|
int dataId;
|
2019-09-17 12:17:58 +00:00
|
|
|
|
|
|
|
|
|
// TODO:r<>cup<75>rer l'id du poolData dans le msgSpace
|
|
|
|
|
// d<>tacher le morceau de m<>moire du processus
|
|
|
|
|
|
|
|
|
|
// TODO:r<>cup<75>rer le poolData qui correspond <20> notre poolIdx.
|
|
|
|
|
// attacher la zone m<>moire correspondant <20> l'Id
|
|
|
|
|
// utiliser des s<>maphores pour v<>rouiller les acces en modif
|
|
|
|
|
// sur la poolData de notre
|
2019-09-17 12:16:29 +00:00
|
|
|
|
//msgSpacePoolData spoolData;
|
|
|
|
|
|
|
|
|
|
//dataId = msg->poolDataId;
|
|
|
|
|
|
|
|
|
|
//spoolData[dataId];
|
|
|
|
|
|
|
|
|
|
//donne l'adr en mappant in the memory
|
2004-02-19 23:05:24 +00:00
|
|
|
|
//GYR:poolAddr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, poolFd, 0);
|
2019-09-17 12:16:29 +00:00
|
|
|
|
if(poolAddr == MAP_FAILED) {
|
|
|
|
|
fprintf( stderr, "mmap failed: %s\n",
|
|
|
|
|
strerror( errno ) );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// on renvoie le pointeur sur le bon pool
|
|
|
|
|
return poolAddr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|