l3.libnazgul/src/bufferGetProcAttach.c

52 lines
1.3 KiB
C
Raw Normal View History

2004-02-23 17:28:46 +00:00
#include "libnazgul.h"
int msgBufferGetProcAttach(
msgPoolData * poolDataTabAddr,
int poolNb,
int * poolIndex,
int * bufferIndex,
void * addr
){
msgBufferInfoTabId bufferInfoTabId;
int bufferInfoTabFd;
msgBufferInfo * bufferInfoTabAddr;
int bufferInfoNb;
bool found=false;
int pIdx=0;
2004-03-07 12:26:42 +00:00
int bIdx;
2004-02-23 17:28:46 +00:00
while ((!found) && (pIdx < poolNb)){
/* Pour chaque pool */
//r<>cuperer l'ID du BufferInfoTab;
strcpy(bufferInfoTabId, poolDataTabAddr[pIdx].bufferInfoTabId);
bufferInfoNb=poolDataTabAddr[pIdx].bufferNb;
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
if (bufferInfoTabFd<0)
{ NZG_ERROR("shm_open",bufferInfoTabId); return -1; }
/** on regarde dans le tableau d'infos de buffer **/
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
/* on cherche dans chacun des buffers */
2004-03-07 12:26:42 +00:00
bIdx=0;
2004-02-23 17:28:46 +00:00
while((!found) && bIdx<bufferInfoNb){
if (bufferInfoTabAddr[bIdx].addr == addr){
found=true;
(*bufferIndex)=bIdx;
};
bIdx++;
}
if (found){ (*poolIndex)=pIdx; }
/* on d<>tache le morceau de m<>moire */
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
{ NZG_ERROR("munmap",bufferInfoTabId); return -1; }
close(bufferInfoTabFd);
pIdx++;
}
if (found){ return 0; } else {return -1;}
}