l3.libnazgul/src/nzg_bufferAttachProc.c
2020-03-03 23:46:32 +01:00

41 lines
1 KiB
C

#include "libnazgul.h"
int msgBufferAttachProc(
msgPoolData * poolDataTabAddr,
int poolIndex,
int bufferIndex,
void * addr)
{
msgBufferInfoTabId bufferInfoTabId;
int bufferInfoTabFd;
msgBufferInfo * bufferInfoTabAddr;
int bufferInfoNb;
//récuperer l'ID du BufferInfoTab;
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
if (bufferInfoTabFd<0){
NZG_ERROR("sem_open",bufferInfoTabId);
return -1;
}
/** on regarde dans le tableau d'infos de buffer **/
bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb;
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
PROT_READ|PROT_WRITE,MAP_SHARED,bufferInfoTabFd,(off_t)0);
printf("atta gooo %s\n",bufferInfoTabId);
bufferInfoTabAddr[bufferIndex].ownerPid = getpid();
bufferInfoTabAddr[bufferIndex].addr = addr;
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
{
NZG_ERROR("munmap",bufferInfoTabId);
return -1; }
return 0;
}