51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
|
#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;
|
|||
|
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 */
|
|||
|
int bIdx=0;
|
|||
|
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;}
|
|||
|
}
|
|||
|
|