* renommage

This commit is contained in:
glenux 2004-02-22 13:11:17 +00:00 committed by Glenn Y. Rolland
parent 79cf5e95d7
commit e3ecc785ae
2 changed files with 143 additions and 0 deletions

72
src/nzg_poolCreate.c Normal file
View file

@ -0,0 +1,72 @@
#include "libnazgul.h"
#include "nzg_ids.h"
int msgPoolCreate(
msgSpaceId spaceId,
int poolIdx,
int buffNb,
int buffSize
) {
int poolFd;
int bufferTabFd;
sem_t * ressourceSem;
msgPoolId poolId;
msgBufferInfoTabId bufferInfoTabId;
msgPoolSemId poolRessourceSemId;
/* creation des infos sur buffers DEBUT */
if (msgBufferInfoTabIdIntern(bufferInfoTabId,spaceId,poolIdx) == -1){
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
return -1;
}
bufferTabFd=shm_open(bufferInfoTabId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
if (bufferTabFd == -1 ) {
fprintf( stderr, "msgInfoTab : %s creation failed: %s\n",bufferInfoTabId,
strerror( errno ) );
return -1;
}
if (ftruncate(bufferTabFd, buffNb*sizeof(msgBufferInfo)) == -1){
fprintf( stderr, "msgBufferInfoTab resizing failed: %s\n",
strerror( errno ) );
return -1;
}
/* creation des infos sur buffers FIN */
/* creation des buffers DEBUT */
if (msgPoolIdIntern(poolId,spaceId,poolIdx) == -1){
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 ) {
fprintf( stderr, "msgPool : %s creation failed: %s\n",poolId,
strerror( errno ) );
return -1;
}
if (ftruncate(poolFd, (buffSize*buffNb)) == -1){
fprintf( stderr, "msgPool resizing failed: %s\n",
strerror( errno ) );
return -1;
}
/* creation des buffers FIN */
if (msgPoolSemIdIntern(poolRessourceSemId,spaceId,poolIdx) == -1){
fprintf( stderr, "msgPoolId creation failed for id %s\n",
(char*)poolRessourceSemId );
return -1;
}
// on met un semaphore sur le pool
ressourceSem = sem_open(poolRessourceSemId, O_CREAT|O_EXCL, 0666, buffNb);
//TODO: verrifier les erreurs sur l'ouverture de la sem
// on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs
close(poolFd);
return 0;
}

71
src/nzg_poolDelete.c Normal file
View file

@ -0,0 +1,71 @@
#include "libnazgul.h"
#include "nzg_ids.h"
int msgPoolDelete(
msgSpaceId spaceId,
int poolIdx,
int buffNb,
int buffSize
) {
int poolFd;
int bufferTabFd;
sem_t * ressourceSem;
msgPoolId poolId;
msgBufferInfoTabId bufferInfoTabId;
msgPoolSemId poolRessourceSemId;
/* creation des infos sur buffers DEBUT */
if (msgBufferInfoTabIdIntern(bufferInfoTabId,spaceId,poolIdx) == -1){
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
return -1;
}
bufferTabFd=shm_open(bufferInfoTabId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
if (bufferTabFd == -1 ) {
fprintf( stderr, "msgInfoTab : %s creation failed: %s\n",bufferInfoTabId,
strerror( errno ) );
return -1;
}
if (ftruncate(bufferTabFd, buffNb*sizeof(msgBufferInfo)) == -1){
fprintf( stderr, "msgBufferInfoTab resizing failed: %s\n",
strerror( errno ) );
return -1;
}
/* creation des infos sur buffers FIN */
/* creation des buffers DEBUT */
if (msgPoolIdIntern(poolId,spaceId,poolIdx) == -1){
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 ) {
fprintf( stderr, "msgPool : %s creation failed: %s\n",poolId,
strerror( errno ) );
return -1;
}
if (ftruncate(poolFd, (buffSize*buffNb)) == -1){
fprintf( stderr, "msgPool resizing failed: %s\n",
strerror( errno ) );
return -1;
}
/* creation des buffers FIN */
if (msgPoolSemIdIntern(poolRessourceSemId,spaceId,poolIdx) == -1){
fprintf( stderr, "msgPoolId creation failed for id %s\n",
(char*)poolRessourceSemId );
return -1;
}
// on met un semaphore sur le pool
ressourceSem = sem_open(poolRessourceSemId, O_CREAT|O_EXCL, 0666, buffNb);
//TODO: verrifier les erreurs sur l'ouverture de la sem
// on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs
close(poolFd);
return 0;
}