2004-02-22 13:11:17 +00:00
|
|
|
#include "libnazgul.h"
|
2004-02-23 18:50:52 +00:00
|
|
|
#include "ids.h"
|
2004-02-22 13:11:17 +00:00
|
|
|
|
|
|
|
int msgPoolCreate(
|
2004-02-22 15:29:36 +00:00
|
|
|
msgSpaceId externId,
|
2004-02-22 13:11:17 +00:00
|
|
|
int poolIdx,
|
|
|
|
int buffNb,
|
|
|
|
int buffSize
|
|
|
|
) {
|
|
|
|
|
|
|
|
int poolFd;
|
2019-09-17 12:47:35 +00:00
|
|
|
sem_t * ressourceSemFd;
|
2004-02-22 13:11:17 +00:00
|
|
|
msgPoolId poolId;
|
|
|
|
msgPoolSemId poolRessourceSemId;
|
|
|
|
|
|
|
|
/* creation des buffers DEBUT */
|
2004-02-22 15:29:36 +00:00
|
|
|
if (msgPoolIdIntern(poolId,externId,poolIdx) == -1){
|
2004-02-22 13:11:17 +00:00
|
|
|
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
poolFd=shm_open(poolId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
|
|
|
|
if (poolFd == -1 ) {
|
2004-02-22 15:29:36 +00:00
|
|
|
fprintf( stderr, "msgPool : %s creation failed: %s\n",poolId,
|
|
|
|
strerror( errno ) );
|
|
|
|
return -1;
|
2004-02-22 13:11:17 +00:00
|
|
|
}
|
|
|
|
if (ftruncate(poolFd, (buffSize*buffNb)) == -1){
|
2004-02-22 15:29:36 +00:00
|
|
|
fprintf( stderr, "msgPool resizing failed: %s\n",
|
|
|
|
strerror( errno ) );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* creation des buffers FIN */
|
|
|
|
|
|
|
|
if (msgPoolSemIdIntern(poolRessourceSemId,externId,poolIdx) == -1){
|
2004-02-22 13:11:17 +00:00
|
|
|
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
2004-02-22 15:29:36 +00:00
|
|
|
(char*)poolRessourceSemId );
|
2004-02-22 13:11:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// on met un semaphore sur le pool
|
2004-02-23 10:30:02 +00:00
|
|
|
ressourceSemFd = sem_open(poolRessourceSemId, O_CREAT|O_EXCL,SEM_DEFAULT_MODE, buffNb);
|
2019-09-17 12:47:35 +00:00
|
|
|
if (ressourceSemFd == SEM_FAILED){
|
|
|
|
NZG_ERROR("sem_open : creation de la ressource",poolRessourceSemId);
|
2004-02-25 10:32:41 +00:00
|
|
|
goto ERROR;
|
2019-09-17 12:47:35 +00:00
|
|
|
} else {
|
|
|
|
NZG_ERROR("sem_open : creation oki",poolRessourceSemId);
|
|
|
|
}
|
|
|
|
|
2004-02-22 13:11:17 +00:00
|
|
|
//TODO: verrifier les erreurs sur l'ouverture de la sem
|
2004-02-22 15:29:36 +00:00
|
|
|
|
2019-09-17 12:47:35 +00:00
|
|
|
sem_close(ressourceSemFd);
|
2004-02-22 13:11:17 +00:00
|
|
|
// on met le pool a la taille voulue pour qu'il
|
|
|
|
// puisse contenir les buffs
|
|
|
|
|
|
|
|
close(poolFd);
|
|
|
|
|
|
|
|
return 0;
|
2004-02-25 10:32:41 +00:00
|
|
|
ERROR:
|
|
|
|
return -1;
|
2004-02-22 13:11:17 +00:00
|
|
|
}
|
|
|
|
|