*** empty log message ***

This commit is contained in:
glenux 2004-02-25 09:47:53 +00:00
parent 73fdf1dfcb
commit 4dc9de3f20
4 changed files with 46 additions and 66 deletions

View file

@ -26,7 +26,10 @@ void * msgGet(msgSpace * space,int queueIndex,int option){
msgQueueIdIntern(queueId,space->externId,queueIndex); msgQueueIdIntern(queueId,space->externId,queueIndex);
// ouvrir la file // ouvrir la file
queue = msgQueueOpen(queueId); queue = msgQueueOpen(queueId);
if (queue==NULL){
NZG_ERROR("msgQueueOpen",queueId);
goto ERROR;
}
// recupérer l'id de l'ancien element... // recupérer l'id de l'ancien element...
msgQueueRem(queue, oldElemId); msgQueueRem(queue, oldElemId);

View file

@ -40,6 +40,8 @@ int spaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId);
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize); int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
/* poolDataTabClose.c */ /* poolDataTabClose.c */
int msgPoolDataTabClose(msgSpace *space, void *addr); int msgPoolDataTabClose(msgSpace *space, void *addr);
/* poolDataTabCreate.c */
void *msgPoolDataTabCreate(msgSpace *space);
/* poolDataTabLock.c */ /* poolDataTabLock.c */
int msgPoolDataTabLock(msgSpace *space); int msgPoolDataTabLock(msgSpace *space);
/* poolDataTabOpen.c */ /* poolDataTabOpen.c */

View file

@ -21,19 +21,18 @@ msgSpace * msgSpaceCreate(
msgSpaceId nzgId; msgSpaceId nzgId;
/* msgSpaceList mSList; */ /* msgSpaceList mSList; */
int mSFd; // shm file descriptor int mSFd; // shm file descriptor
int mSPoolDataFd; // shm file descriptor int i;
int i;
static int mSIdNum=-1; static int mSIdNum=-1;
msgSpace * mSAddr; msgSpace * space;
msgPoolDataTabId poolDataTabId; msgPoolDataTabId poolDataTabId;
msgPoolData * mSPoolDataAddr; msgPoolData * poolDataTabAddr;
msgBufferInfoTabId bufferInfoTabId; msgBufferInfoTabId bufferInfoTabId;
msgPoolId poolId; msgPoolId poolId;
sem_t * mSDataTabSemFd; sem_t * mSDataTabSemFd;
mSIdNum++; mSIdNum++;
mSAddr=NULL; space=NULL;
/** recuperation de la liste des msgSpace **/ /** recuperation de la liste des msgSpace **/
/* (creation si elle n'existe pas */ /* (creation si elle n'existe pas */
@ -54,114 +53,92 @@ msgSpace * msgSpaceCreate(
} }
/* on redimentionne l'element */ /* on redimentionne l'element */
if (ftruncate(mSFd, sizeof(* mSAddr)) == -1){ if (ftruncate(mSFd, sizeof(* space)) == -1){
fprintf( stderr, "msgSpace resizing failed: %s\n", fprintf( stderr, "msgSpace resizing failed: %s\n",
strerror( errno ) ); strerror( errno ) );
return NULL; return NULL;
} }
/* Map the memory object */ /* Map the memory object */
mSAddr = mmap( 0, sizeof( *mSAddr ), space = mmap( 0, sizeof( *space ),
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED, mSFd, 0 ); MAP_SHARED, mSFd, 0 );
if( mSAddr == MAP_FAILED ) { if( space == MAP_FAILED ) {
fprintf( stderr, "mmap failed: %s\n", fprintf( stderr, "mmap failed: %s\n",
strerror( errno ) ); strerror( errno ) );
return NULL; return NULL;
} }
printf( "CREAT: msgSpace mapped to 0x%08x in %d\n", (int)mSAddr,(int)getpid()); printf( "CREAT: msgSpace mapped to 0x%08x in %d\n", (int)space,(int)getpid());
/* on ferme le descripteur du fichier */ /* on ferme le descripteur du fichier */
close(mSFd); close(mSFd);
/* on remplit la structure */ /* on remplit la structure */
strncpy(mSAddr->id,externId,MSGSPACE_ID_LEN); strncpy(space->id,externId,MSGSPACE_ID_LEN);
mSAddr->poolNb=poolNb; space->poolNb=poolNb;
mSAddr->queueNb=queueNb; space->queueNb=queueNb;
mSAddr->pid=getpid(); space->pid=getpid();
msgPoolDataTabSemIdIntern(mSAddr->poolDataTabSemId,externId); msgPoolDataTabSemIdIntern(space->poolDataTabSemId,externId);
/* creation du poolData */ /* creation du poolData */
msgPoolDataIdIntern(poolDataTabId,externId); msgPoolDataIdIntern(poolDataTabId,externId);
strcpy(mSAddr->poolDataTabId,poolDataTabId); strcpy(space->poolDataTabId,poolDataTabId);
strcpy(mSAddr->externId,externId); strcpy(space->externId,externId);
mSDataTabSemFd=sem_open(mSAddr->poolDataTabSemId, mSDataTabSemFd=sem_open(space->poolDataTabSemId,
O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); O_CREAT|O_EXCL,SEM_DEFAULT_MODE,0);
if (mSDataTabSemFd == SEM_FAILED){ if (mSDataTabSemFd == SEM_FAILED){
NZG_ERROR("sem_open : creation de la ressource", NZG_ERROR("sem_open : creation de la ressource",
mSAddr->poolDataTabSemId); space->poolDataTabSemId);
return NULL; return NULL;
} else { } else {
NZG_ERROR("sem_open : creation oki", NZG_ERROR("sem_open : creation oki",
mSAddr->poolDataTabSemId); space->poolDataTabSemId);
} }
sem_wait(mSDataTabSemFd); sem_close(mSDataTabSemFd);
mSPoolDataFd=shm_open( // msgPoolDataTabLock(space);
poolDataTabId,
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
MSGSPACE_DEFAULT_MODE
);
if (mSPoolDataFd == -1 ) {
fprintf( stderr, "poolData %s creation failed: %s\n",
(char*)poolDataTabId,
strerror( errno ) );
return NULL;
}
/* allocation de la bonne zone mémoire pour le poolData */ /* attacher le tableau des msgPoolData */
if (ftruncate(mSPoolDataFd, poolNb*sizeof(msgPoolData)) == -1){ poolDataTabAddr=msgPoolDataTabCreate(space);
fprintf( stderr, "msgSpace resizing failed: %s\n",
strerror( errno ) );
return NULL;
}
/* TODO: attacher chacun des msgPoolData :
* - y écrire les informations passées en param
* - creer les zones mémoires de chacune des pool
*/
mSPoolDataAddr = mmap( 0, sizeof( *mSAddr ),
PROT_READ | PROT_WRITE,
MAP_SHARED, mSFd, 0 );
if( mSPoolDataAddr == MAP_FAILED ) {
fprintf( stderr, "mmap failed: %s\n",
strerror( errno ) );
return NULL;
}
close(mSPoolDataFd);
printf( "msgPoolData map addr is 0x%08x\n", (int)mSPoolDataAddr );
for (i=0;i<poolNb;i++){ for (i=0;i<poolNb;i++){
/* Pour chacun des poolData
* - y écrire les informations passées en param
* - creer les zones mémoires de chacune des pool
*/
// creation d'une pool // creation d'une pool
mSPoolDataAddr[i].bufferNb=poolInfos[i].bufferNb; poolDataTabAddr[i].bufferNb=poolInfos[i].bufferNb;
mSPoolDataAddr[i].bufferSize=poolInfos[i].bufferSize; poolDataTabAddr[i].bufferSize=poolInfos[i].bufferSize;
mSPoolDataAddr[i].allocDispBuffer=0; poolDataTabAddr[i].allocDispBuffer=0;
if (msgBufferInfoTabIdIntern(bufferInfoTabId,externId,i) == -1){ if (msgBufferInfoTabIdIntern(bufferInfoTabId,externId,i) == -1){
fprintf( stderr, "msgBufferInfoTabId creation failed for id %s\n", fprintf( stderr, "msgBufferInfoTabId creation failed for id %s\n",
(char*)poolId ); (char*)poolId );
return NULL; return NULL;
} }
strcpy(mSPoolDataAddr[i].bufferInfoTabId,bufferInfoTabId); strcpy(poolDataTabAddr[i].bufferInfoTabId,bufferInfoTabId);
printf("buffIfoTab %d name : %s\n",i,mSPoolDataAddr[i].bufferInfoTabId); printf("buffIfoTab %d name : %s\n",i,poolDataTabAddr[i].bufferInfoTabId);
msgBufferInfoTabCreate(externId,mSPoolDataAddr,i,poolInfos[i].bufferNb); msgBufferInfoTabCreate(externId,poolDataTabAddr,i,poolInfos[i].bufferNb);
if (msgPoolIdIntern(poolId,externId,i) == -1){ if (msgPoolIdIntern(poolId,externId,i) == -1){
fprintf( stderr, "msgPoolId creation failed for id %s\n", fprintf( stderr, "msgPoolId creation failed for id %s\n",
(char*)poolId ); (char*)poolId );
return NULL; return NULL;
} }
strcpy(mSPoolDataAddr[i].poolId,poolId); strcpy(poolDataTabAddr[i].poolId,poolId);
msgPoolCreate(externId,i,poolInfos[i].bufferNb,poolInfos[i].bufferSize); msgPoolCreate(externId,i,poolInfos[i].bufferNb,poolInfos[i].bufferSize);
} }
msgPoolDataTabClose(space,poolDataTabAddr);
/* TODO: on ajoute spaceId a la liste des msgSpace connus */ /* TODO: on ajoute spaceId a la liste des msgSpace connus */
/* TODO: on crée queueNb files de messages */ /* TODO: on crée queueNb files de messages */
/* on renvoie un pointeur sur le bon spaceId */ /* on renvoie un pointeur sur le bon spaceId */
sem_post(mSDataTabSemFd); msgPoolDataTabUnlock(space);
return mSAddr; return space;
ERROR:
return NULL;
} }

View file

@ -23,8 +23,6 @@ int main(void) {
pid_t pid=fork(); pid_t pid=fork();
if (pid ==0){ if (pid ==0){
mSPAC=msgSpaceOpen(testId); mSPAC=msgSpaceOpen(testId);
sleep(2); sleep(2);