54 lines
1.2 KiB
C
54 lines
1.2 KiB
C
|
# 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
|
||
|
if (ftruncate(poolFd, sizeof((buffSize)*buffNb)) == -1){
|
||
|
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;
|
||
|
}
|
||
|
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);
|
||
|
|