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