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

34 lines
1,012 B
C

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