l3.libnazgul/src/nzg_bufferAttachProc.c

38 lines
943 B
C
Raw Normal View History

2019-09-17 12:45:48 +00:00
#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){
perror("shm_open");
return -1;
}
/** on regarde dans le tableau d'infos de buffer **/
bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb;
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
bufferInfoTabAddr[bufferIndex].ownerPid = getpid();
bufferInfoTabAddr[bufferIndex].addr = addr;
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
{ perror("munmap"); return -1; }
return 0;
}