*** empty log message ***
This commit is contained in:
parent
14909e802d
commit
607d86085a
12 changed files with 138 additions and 123 deletions
|
@ -73,12 +73,14 @@ void * msgAllocate(msgSpace *space,
|
|||
msgPoolSemIdIntern(ressourceSemId,space->id,i);
|
||||
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||
if (ressourceSemFd == SEM_FAILED){
|
||||
perror("sem_open"); return NULL;
|
||||
NZG_ERROR("sem_open",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
/* on remplit le tableau avec les valeurs des semaphores */
|
||||
|
||||
if (sem_getvalue(ressourceSemFd, ressourceSemVal) < 0){
|
||||
perror("sem_getvalue"); return NULL;
|
||||
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((*ressourceSemVal) < 0){
|
||||
|
@ -95,7 +97,8 @@ void * msgAllocate(msgSpace *space,
|
|||
break;
|
||||
}
|
||||
if( sem_close(ressourceSemFd) <0){
|
||||
perror("sem_getvalue"); return NULL;
|
||||
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
} // if buffSize > taille
|
||||
} // for
|
||||
|
@ -129,13 +132,13 @@ void * msgAllocate(msgSpace *space,
|
|||
msgPoolSemIdIntern(ressourceSemId,space->id,selectedPoolIndex);
|
||||
ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||
if(ressourceSemFd==SEM_FAILED){
|
||||
perror("sem_open");
|
||||
NZG_ERROR("sem_open",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (sem_wait(ressourceSemFd) < 0){
|
||||
perror("sem_wait");
|
||||
NZG_ERROR("sem_wait",ressourceSemId);
|
||||
sem_close(ressourceSemFd);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ int msgBufferAttachProc(
|
|||
|
||||
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||
if (bufferInfoTabFd<0){
|
||||
perror("shm_open");
|
||||
NZG_ERROR("sem_open",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,9 @@ int msgBufferAttachProc(
|
|||
bufferInfoTabAddr[bufferIndex].addr = addr;
|
||||
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{ perror("munmap"); return -1; }
|
||||
{
|
||||
NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1; }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ int msgBufferDetachProc(
|
|||
|
||||
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||
if (bufferInfoTabFd<0){
|
||||
perror("shm_open");
|
||||
NZG_ERROR("shm_open",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,10 @@ int msgBufferDetachProc(
|
|||
bufferInfoTabAddr[bufferIndex].addr = NULL;
|
||||
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{ perror("munmap"); return -1; }
|
||||
{
|
||||
NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@ int bufferInfoNb;
|
|||
int bufferFreeIndex;
|
||||
|
||||
//récuperer l'ID du BufferInfoTab;
|
||||
printf("=>%s<=\n",poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||
|
||||
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||
if (bufferInfoTabFd<0){
|
||||
perror("shm_open");
|
||||
NZG_ERROR("shm_open",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -28,7 +29,10 @@ int bufferFreeIndex;
|
|||
bufferFreeIndex=i;
|
||||
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{ perror("munmap"); return -1; }
|
||||
{
|
||||
NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return bufferFreeIndex;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,37 @@
|
|||
#include "libnazgul.h"
|
||||
#include "nzg_ids.h"
|
||||
|
||||
int msgBufferInfoTabCreate(
|
||||
msgSpaceId externId,
|
||||
msgPoolData * poolDataTabAddr,
|
||||
int poolIdx,
|
||||
int buffNb) {
|
||||
int bufferNb) {
|
||||
|
||||
bufferInfoTabInit(poolIdx);
|
||||
int bufferInfoTabFd;
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
|
||||
/* creation des infos sur buffers DEBUT */
|
||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId,externId,poolIdx) == -1){
|
||||
NZG_ERROR("msgPoolId creation",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
|
||||
if (bufferInfoTabFd == -1 ) {
|
||||
fprintf( stderr, "msgInfoTab : %s creation failed: %s\n",bufferInfoTabId,
|
||||
strerror( errno ) );
|
||||
return -1;
|
||||
}
|
||||
if (ftruncate(bufferInfoTabFd, bufferNb*sizeof(msgBufferInfo)) == -1){
|
||||
fprintf( stderr, "msgBufferInfoTab resizing failed: %s\n",
|
||||
strerror( errno ) );
|
||||
return -1;
|
||||
}
|
||||
close(bufferInfoTabFd);
|
||||
/* creation des infos sur buffers FIN */
|
||||
|
||||
msgBufferInfoTabInit(poolDataTabAddr,poolIdx);
|
||||
|
||||
return -1;NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferInit(msgPoolData * poolDataTabAddr,int poolIndex){
|
||||
int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr,int poolIndex){
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
int bufferInfoTabFd;
|
||||
msgBufferInfo * bufferInfoTabAddr;
|
||||
|
@ -9,16 +9,18 @@ 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){
|
||||
perror("shm_open");
|
||||
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_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||
PROT_WRITE|PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||
printf("fd ?\n"); fflush(stdout);
|
||||
|
||||
int i;
|
||||
for (i=0;i<bufferInfoNb;i++){
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferInit(msgPoolData * poolDataTabAddr,int poolIndex){
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -22,4 +22,6 @@
|
|||
#define SEM_FAILED ((sem_t *)0)
|
||||
#endif
|
||||
|
||||
#define NZG_ERROR(func,str) fprintf(stderr,"%s: %s\n%s in %s:%d\n",func,strerror(errno),str,__FILE__,__LINE__);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,40 +2,19 @@
|
|||
#include "nzg_ids.h"
|
||||
|
||||
int msgPoolCreate(
|
||||
msgSpaceId spaceId,
|
||||
msgSpaceId externId,
|
||||
int poolIdx,
|
||||
int buffNb,
|
||||
int buffSize
|
||||
) {
|
||||
|
||||
int poolFd;
|
||||
int bufferTabFd;
|
||||
sem_t * ressourceSem;
|
||||
msgPoolId poolId;
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
msgPoolSemId poolRessourceSemId;
|
||||
|
||||
|
||||
/* creation des infos sur buffers DEBUT */
|
||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId,spaceId,poolIdx) == -1){
|
||||
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
|
||||
return -1;
|
||||
}
|
||||
bufferTabFd=shm_open(bufferInfoTabId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
|
||||
if (bufferTabFd == -1 ) {
|
||||
fprintf( stderr, "msgInfoTab : %s creation failed: %s\n",bufferInfoTabId,
|
||||
strerror( errno ) );
|
||||
return -1;
|
||||
}
|
||||
if (ftruncate(bufferTabFd, buffNb*sizeof(msgBufferInfo)) == -1){
|
||||
fprintf( stderr, "msgBufferInfoTab resizing failed: %s\n",
|
||||
strerror( errno ) );
|
||||
return -1;
|
||||
}
|
||||
/* creation des infos sur buffers FIN */
|
||||
|
||||
/* creation des buffers DEBUT */
|
||||
if (msgPoolIdIntern(poolId,spaceId,poolIdx) == -1){
|
||||
if (msgPoolIdIntern(poolId,externId,poolIdx) == -1){
|
||||
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
|
||||
return -1;
|
||||
}
|
||||
|
@ -52,7 +31,7 @@ int msgPoolCreate(
|
|||
}
|
||||
/* creation des buffers FIN */
|
||||
|
||||
if (msgPoolSemIdIntern(poolRessourceSemId,spaceId,poolIdx) == -1){
|
||||
if (msgPoolSemIdIntern(poolRessourceSemId,externId,poolIdx) == -1){
|
||||
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
||||
(char*)poolRessourceSemId );
|
||||
return -1;
|
||||
|
|
|
@ -1,26 +1,39 @@
|
|||
#ifndef _NZG_PROTO
|
||||
#define _NZG_PROTO 1
|
||||
|
||||
/* src/nzg_allocate.c */
|
||||
/* nzg_allocate.c */
|
||||
void *msgAllocate(msgSpace *space, int pool, int taille, int option);
|
||||
/* src/nzg_list.c */
|
||||
/* src/nzg_msgList.c */
|
||||
/* nzg_bufferAttachProc.c */
|
||||
int msgBufferAttachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||
/* nzg_buffer.c */
|
||||
int msgBufferGetAttachedProcIndex(msgPoolData *poolDataTabAddr, int poolIndex, void *addr);
|
||||
/* nzg_bufferDetachProc.c */
|
||||
int msgBufferDetachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||
/* nzg_bufferGetFreeIndex.c */
|
||||
int msgBufferGetFreeIndex(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||
/* nzg_bufferInfoTabCreate.c */
|
||||
int msgBufferInfoTabCreate(msgSpaceId externId,msgPoolData * poolDataTabAddr, int poolIdx, int buffNb);
|
||||
/* nzg_bufferInfoTabInit.c */
|
||||
int msgBufferInfoTabInit(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||
/* nzg_ids.c */
|
||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
||||
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx);
|
||||
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
|
||||
int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num);
|
||||
int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num);
|
||||
/* nzg_list.c */
|
||||
/* nzg_msgList.c */
|
||||
msgSpaceListElem *addBegining(msgSpaceListElem *list, int ownerpid);
|
||||
/* src/nzg_pool.c */
|
||||
int msgPoolCreate(msgSpaceId spaceId, int poolIdx, int buffNb, int buffSize);
|
||||
/* src/nzg_spaces.c */
|
||||
msgSpace *msgSpaceCreate(msgSpaceId spaceId, int queueNb, int poolNb, msgPool *poolInfos);
|
||||
/* nzg_poolCreate.c */
|
||||
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
|
||||
/* nzg_poolDelete.c */
|
||||
int msgPoolDelete(msgSpaceId spaceId, int poolIdx);
|
||||
/* nzg_spaceCreate.c */
|
||||
msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb, msgPool *poolInfos);
|
||||
/* nzg_spaceDelete.c */
|
||||
int msgSpaceDelete(msgSpaceId externId);
|
||||
/* nzg_spaceOpen.c */
|
||||
msgSpace *msgSpaceOpen(msgSpaceId spaceId);
|
||||
int msgSpaceDelete(msgSpaceId spaceId);
|
||||
/* src/nzg_buffer.c */
|
||||
int msgBufferGetFreeIndex(msgPoolData * poolDataTab, int poolIndex);
|
||||
int msgBufferAttachProc(msgPoolData * poolDataTab, int poolIndex, int bufferIndex,void *addr);
|
||||
int msgBufferInfoTabIdIntern(
|
||||
msgBufferInfoTabId dest,
|
||||
msgSpaceId src,
|
||||
int num);
|
||||
int msgPoolDelete(
|
||||
msgSpaceId spaceId,
|
||||
int poolIdx
|
||||
);
|
||||
/* nzg_state.c */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,7 +13,7 @@ int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
|
|||
*/
|
||||
|
||||
msgSpace * msgSpaceCreate(
|
||||
msgSpaceId spaceId,
|
||||
msgSpaceId externId,
|
||||
int queueNb,
|
||||
int poolNb,
|
||||
msgPool * poolInfos ){
|
||||
|
@ -25,10 +25,11 @@ msgSpace * msgSpaceCreate(
|
|||
static int mSIdNum=-1;
|
||||
msgSpace * mSAddr;
|
||||
|
||||
msgPoolId poolDataTabId;
|
||||
msgPoolDataTabId poolDataTabId;
|
||||
msgPoolData * mSPoolDataAddr;
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
msgPoolId poolId;
|
||||
|
||||
fprintf(stderr,"Creating msgSpace with id : %s\n",spaceId);
|
||||
|
||||
mSIdNum++;
|
||||
mSAddr=NULL;
|
||||
|
@ -37,19 +38,17 @@ msgSpace * msgSpaceCreate(
|
|||
|
||||
/** on créee le nouvel element **/
|
||||
printf("PAGESIZE : %d\n",(int)PAGESIZE);
|
||||
if (msgSpaceIdIntern(nzgId,spaceId) < 0){
|
||||
if (msgSpaceIdIntern(nzgId,externId) < 0){
|
||||
return NULL;
|
||||
}
|
||||
printf("Id interne : %s\n",nzgId);
|
||||
fprintf(stderr,"Creating msgSpace with id : %s\n",nzgId);
|
||||
mSFd=shm_open(
|
||||
nzgId,
|
||||
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||
MSGSPACE_DEFAULT_MODE
|
||||
);
|
||||
if (mSFd == -1 ) {
|
||||
fprintf( stderr, "msgSpace %s creation failed: %s\n",
|
||||
(char*)nzgId,
|
||||
strerror( errno ) );
|
||||
NZG_ERROR("shm_open : msgSpace creation",nzgId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -76,13 +75,13 @@ msgSpace * msgSpaceCreate(
|
|||
close(mSFd);
|
||||
|
||||
/* on remplit la structure */
|
||||
strncpy(mSAddr->id,nzgId,MSGSPACE_ID_LEN);
|
||||
strncpy(mSAddr->id,externId,MSGSPACE_ID_LEN);
|
||||
mSAddr->poolNb=poolNb;
|
||||
mSAddr->queueNb=queueNb;
|
||||
mSAddr->pid=getpid();
|
||||
|
||||
/* creation du poolData */
|
||||
msgPoolDataIdIntern(poolDataTabId,spaceId);
|
||||
msgPoolDataIdIntern(poolDataTabId,externId);
|
||||
strcpy(mSAddr->poolDataTabId,poolDataTabId);
|
||||
|
||||
mSPoolDataFd=shm_open(
|
||||
|
@ -125,14 +124,22 @@ msgSpace * msgSpaceCreate(
|
|||
mSPoolDataAddr[i].bufferSize=poolInfos[i].bufferSize;
|
||||
mSPoolDataAddr[i].allocDispBuffer=0;
|
||||
|
||||
msgPoolId poolId;
|
||||
if (msgPoolIdIntern(poolId,spaceId,i) == -1){
|
||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId,externId,i) == -1){
|
||||
fprintf( stderr, "msgBufferInfoTabId creation failed for id %s\n",
|
||||
(char*)poolId );
|
||||
return NULL;
|
||||
}
|
||||
strcpy(mSPoolDataAddr[i].bufferInfoTabId,bufferInfoTabId);
|
||||
printf("buffIfoTab %d name : %s\n",i,mSPoolDataAddr[i].bufferInfoTabId);
|
||||
msgBufferInfoTabCreate(externId,mSPoolDataAddr,i,poolInfos[i].bufferNb);
|
||||
|
||||
if (msgPoolIdIntern(poolId,externId,i) == -1){
|
||||
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
||||
(char*)poolId );
|
||||
return NULL;
|
||||
}
|
||||
msgPoolCreate(spaceId,i,poolInfos[i].bufferNb,poolInfos[i].bufferSize);
|
||||
strcpy(mSPoolDataAddr[i].id,poolId);
|
||||
msgPoolCreate(externId,i,poolInfos[i].bufferNb,poolInfos[i].bufferSize);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,17 +8,21 @@ int main(void) {
|
|||
msgSpaceId testId;
|
||||
msgSpace * mSPAC;
|
||||
msgPool poolInfos[2];
|
||||
char * montext;
|
||||
|
||||
poolInfos[0].bufferNb=4;
|
||||
poolInfos[0].bufferSize=200;
|
||||
|
||||
poolInfos[1].bufferNb=1;
|
||||
poolInfos[1].bufferSize=700;
|
||||
poolInfos[1].bufferNb=5;
|
||||
poolInfos[1].bufferSize=250;
|
||||
|
||||
strcpy(testId,"test");
|
||||
printf("RequestedId: %s\n",testId);
|
||||
|
||||
mSPAC=msgSpaceCreate(testId,0,2,poolInfos);
|
||||
|
||||
montext=msgAllocate(mSPAC,1,200,0);
|
||||
|
||||
msgSpaceDelete(testId);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue