Compare commits
No commits in common. "f65f6b957a1a060c8f3ae58de62b7c04ab7134ca" and "695876af0d3116705d6f0f9775afe2980eff455b" have entirely different histories.
f65f6b957a
...
695876af0d
67 changed files with 2231 additions and 2561 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,6 +1 @@
|
|||
*.a
|
||||
*.c~
|
||||
*.h~
|
||||
*.log
|
||||
*.o
|
||||
test/test_*
|
||||
|
|
3
.ssh-agent
Normal file
3
.ssh-agent
Normal file
|
@ -0,0 +1,3 @@
|
|||
SSH_AUTH_SOCK=/tmp/ssh-QHib2992/agent.2992; export SSH_AUTH_SOCK;
|
||||
SSH_AGENT_PID=2993; export SSH_AGENT_PID;
|
||||
echo Agent pid 2993;
|
|
@ -1,9 +1,9 @@
|
|||
\documentclass[12pt,a4paper]{report}
|
||||
%\usepackage{a4wide}
|
||||
\usepackage{a4wide}
|
||||
\usepackage{geometry}
|
||||
%\usepackage{typehtml}
|
||||
\usepackage{typehtml}
|
||||
\usepackage[latin1]{inputenc}
|
||||
%\usepackage{listings}
|
||||
\usepackage{listings}
|
||||
\usepackage[french]{babel}
|
||||
\usepackage{fancyheadings}
|
||||
\usepackage{color}
|
||||
|
|
|
@ -9,8 +9,11 @@
|
|||
|
||||
/* TODO: prevoir le cas des négatifs dans la taille ... */
|
||||
|
||||
void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
||||
{
|
||||
void * msgAllocate(msgSpace *space,
|
||||
int pool,
|
||||
int taille,
|
||||
int option
|
||||
){
|
||||
void * resultAddr=NULL;
|
||||
int bufferFreeSize;
|
||||
int i;
|
||||
|
@ -29,8 +32,10 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
int bufferFreeIndex;
|
||||
msgPoolData * mSPoolDataTabAddr;
|
||||
|
||||
|
||||
selectedPoolIndex=-1;
|
||||
|
||||
|
||||
mSPoolDataTabAddr=msgPoolDataTabOpen(space);
|
||||
if (mSPoolDataTabAddr==NULL){
|
||||
NZG_ERROR("msgPoolDataTabOpen",space->poolDataTabId);
|
||||
|
@ -71,40 +76,29 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
fprintf(stderr,"[ ALLOCATION ANYPOOL : %d ]\n",(int)getpid());
|
||||
// choisir le pool au hasard (ou presque)
|
||||
for(i=0; i<(space->poolNb); i++) {
|
||||
printf("- boucle %d\n", i);
|
||||
fflush(stdout);
|
||||
printf("- boucle %d\n",i); fflush(stdout);
|
||||
if(mSPoolDataTabAddr[i].bufferSize >= taille) {
|
||||
printf("( buffSize > taille )\n");
|
||||
fflush(stdout);
|
||||
printf("( buffSize > taille )\n"); fflush(stdout);
|
||||
/* choisir le numero du semaphore
|
||||
en fonction du nombre de lock poses / nombre de buffer */
|
||||
msgPoolSemIdIntern(ressourceSemId, space->id,
|
||||
i);
|
||||
ressourceSemFd =
|
||||
sem_open(ressourceSemId, O_CREAT,
|
||||
SEM_DEFAULT_MODE, 0);
|
||||
msgPoolSemIdIntern(ressourceSemId,space->id,i);
|
||||
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||
if (ressourceSemFd == SEM_FAILED){
|
||||
NZG_ERROR("sem_open",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
/* on remplit le tableau avec les valeurs des semaphores */
|
||||
|
||||
if (sem_getvalue
|
||||
(ressourceSemFd, &ressourceSemVal) < 0) {
|
||||
NZG_ERROR("sem_getvalue",
|
||||
ressourceSemId);
|
||||
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
|
||||
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
printf("RESSOURCESEMVAL %d\n",ressourceSemVal);
|
||||
if (ressourceSemVal <= 0){
|
||||
printf("resVal < 0 : %d\n",
|
||||
ressourceSemVal);
|
||||
printf("resVal < 0 : %d\n",ressourceSemVal);
|
||||
/* il y a ressourceSemVal processus qui attendent déja... */
|
||||
semPoolCoef[nbLockedSem] =
|
||||
(float)((1 -
|
||||
ressourceSemVal) /
|
||||
mSPoolDataTabAddr[i].
|
||||
bufferNb);
|
||||
(float) ((1-ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb);
|
||||
nbLockedSem++;
|
||||
}
|
||||
if(sem_trywait(ressourceSemFd)==0) {
|
||||
|
@ -116,15 +110,13 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
break;
|
||||
}
|
||||
if( sem_close(ressourceSemFd) <0){
|
||||
NZG_ERROR("sem_getvalue",
|
||||
ressourceSemId);
|
||||
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
} // if buffSize > taille
|
||||
} // for
|
||||
|
||||
printf("ERRORDETECT outFor\n");
|
||||
fflush(stdout);
|
||||
printf("ERRORDETECT outFor\n"); fflush(stdout);
|
||||
|
||||
if (!gotRessourceSem) {
|
||||
printf("Calcul du meilleur en cas de liberation\n");
|
||||
|
@ -133,8 +125,7 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
/* on cherche le pool avec le moins de lock poses / nbre de buffer
|
||||
* le numéro du pool est stocké dans idxPoolOptimum */
|
||||
for(i=0; i<nbLockedSem; i++) {
|
||||
printf("Coef %d : %d\n", i,
|
||||
(int)semPoolCoef[i]);
|
||||
printf("Coef %d : %d\n",i,(int)semPoolCoef[i]);
|
||||
if ((semPoolCoef[i] != -1)
|
||||
&& (semPoolCoef[i] < minPoolCoef)) {
|
||||
minPoolCoef = semPoolCoef[i];
|
||||
|
@ -156,14 +147,13 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
}
|
||||
|
||||
if (!gotRessourceSem){
|
||||
msgPoolSemIdIntern(ressourceSemId, space->externId,
|
||||
selectedPoolIndex);
|
||||
ressourceSemFd =
|
||||
sem_open(ressourceSemId, O_CREAT, SEM_DEFAULT_MODE, 0);
|
||||
msgPoolSemIdIntern(ressourceSemId,space->externId,selectedPoolIndex);
|
||||
ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||
if(ressourceSemFd==SEM_FAILED){
|
||||
NZG_ERROR("sem_open",ressourceSemId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//TODO:virer la ligne suivante:
|
||||
sem_getvalue(ressourceSemFd, &ressourceSemVal);
|
||||
|
||||
|
@ -176,6 +166,7 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
printf("Passed %s\n",ressourceSemId);
|
||||
}
|
||||
|
||||
|
||||
/* on a acqui un semaphore pour la ressouce */
|
||||
/* on acquiert le droit de modifier les infos sur la ressource */
|
||||
/* on protege le tableau des associations */
|
||||
|
@ -183,8 +174,7 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
|
||||
/* on modifie maintenant les données */
|
||||
/* - on récupere l'index du premier buffer libre */
|
||||
bufferFreeIndex =
|
||||
msgBufferGetFreeIndex(mSPoolDataTabAddr, selectedPoolIndex);
|
||||
bufferFreeIndex = msgBufferGetFreeIndex(mSPoolDataTabAddr,selectedPoolIndex);
|
||||
if (bufferFreeIndex < 0){
|
||||
// aucun buffer libre ?
|
||||
NZG_ERROR("msgBufferGetFreeIndex","");
|
||||
|
@ -197,26 +187,25 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
|||
bufferFreeSize=mSPoolDataTabAddr[selectedPoolIndex].bufferSize;
|
||||
printf("BufferSize : %d\n", bufferFreeSize);
|
||||
|
||||
resultAddr =
|
||||
msgBufferMap(mSPoolDataTabAddr, selectedPoolIndex, bufferFreeIndex);
|
||||
resultAddr=msgBufferMap(mSPoolDataTabAddr,selectedPoolIndex,bufferFreeIndex);
|
||||
if (resultAddr==NULL){
|
||||
NZG_ERROR("msgBufferMap",
|
||||
mSPoolDataTabAddr[selectedPoolIndex].poolId);
|
||||
NZG_ERROR("msgBufferMap",mSPoolDataTabAddr[selectedPoolIndex].poolId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
/* - on s'enregistre aupres de ce buffer */
|
||||
msgBufferAttachProc(mSPoolDataTabAddr,
|
||||
selectedPoolIndex, bufferFreeIndex, resultAddr);
|
||||
selectedPoolIndex,
|
||||
bufferFreeIndex,
|
||||
resultAddr);
|
||||
|
||||
// munmap(mSPoolDataTabAddr,(space->poolNb) * sizeof( msgPoolData ));
|
||||
/* unmapper le msgPoolDataTab */
|
||||
msgPoolDataTabClose(space,mSPoolDataTabAddr);
|
||||
msgPoolDataTabUnlock(space);
|
||||
|
||||
printf("alloc de %p\n", (void *)resultAddr);
|
||||
printf( "alloc de 0x%08x\n", (int)resultAddr);
|
||||
return resultAddr;
|
||||
|
||||
ERROR:
|
||||
NZG_ERROR("msgAllocate","error processing");
|
||||
msgPoolDataTabUnlock(space);
|
||||
|
|
10
src/buffer.c
10
src/buffer.c
|
@ -1,11 +1,15 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferGetAttachedProcIndex(msgPoolData * poolDataTabAddr,
|
||||
int poolIndex, void *addr)
|
||||
{
|
||||
int msgBufferGetAttachedProcIndex(
|
||||
msgPoolData * poolDataTabAddr,
|
||||
int poolIndex,
|
||||
void * addr
|
||||
){
|
||||
|
||||
//TODO: parcourrir tous les index, et regarder s'il y
|
||||
//a une addresse qui correspond avec le meme processus...
|
||||
//et renvoyer l'index du buffer correspondant a l'addresse...
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferAttachProc(msgPoolData * poolDataTabAddr,
|
||||
int poolIndex, int bufferIndex, void *addr)
|
||||
int msgBufferAttachProc(
|
||||
msgPoolData * poolDataTabAddr,
|
||||
int poolIndex,
|
||||
int bufferIndex,
|
||||
void * addr)
|
||||
{
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
int bufferInfoTabFd;
|
||||
|
@ -11,6 +14,7 @@ int msgBufferAttachProc(msgPoolData * poolDataTabAddr,
|
|||
//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);
|
||||
|
@ -20,17 +24,18 @@ int msgBufferAttachProc(msgPoolData * poolDataTabAddr,
|
|||
/** 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);
|
||||
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) {
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{
|
||||
NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
return -1; }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferDetachProc(msgPoolData * poolDataTabAddr,
|
||||
int poolIndex, int bufferIndex, void *addr)
|
||||
{
|
||||
int msgBufferDetachProc(
|
||||
msgPoolData * poolDataTabAddr,
|
||||
int poolIndex,
|
||||
int bufferIndex,
|
||||
void * addr
|
||||
){
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
int bufferInfoTabFd;
|
||||
msgBufferInfo * bufferInfoTabAddr;
|
||||
|
@ -11,6 +14,7 @@ int msgBufferDetachProc(msgPoolData * poolDataTabAddr,
|
|||
printf("Detaching %d,%d\n",poolIndex,bufferIndex);
|
||||
//récuperer l'ID du BufferInfoTab;
|
||||
|
||||
|
||||
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||
|
||||
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||
|
@ -22,16 +26,17 @@ int msgBufferDetachProc(msgPoolData * poolDataTabAddr,
|
|||
/** 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);
|
||||
PROT_READ|PROT_WRITE,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||
|
||||
bufferInfoTabAddr[bufferIndex].ownerPid = (pid_t)-1;
|
||||
bufferInfoTabAddr[bufferIndex].addr = NULL;
|
||||
|
||||
if (munmap(bufferInfoTabAddr, bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{
|
||||
NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr, int poolIndex)
|
||||
{
|
||||
int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr,int poolIndex){
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
int bufferInfoTabFd;
|
||||
msgBufferInfo * bufferInfoTabAddr;
|
||||
|
@ -21,23 +20,20 @@ int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr, int poolIndex)
|
|||
/** 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_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||
|
||||
i=0;
|
||||
while ((i<bufferInfoNb)
|
||||
&& (bufferInfoTabAddr[i].ownerPid != (pid_t) - 1)) {
|
||||
i++;
|
||||
}
|
||||
if (i == bufferInfoNb) {
|
||||
return -1;
|
||||
}
|
||||
&& (bufferInfoTabAddr[i].ownerPid != (pid_t)-1)){ i++; }
|
||||
if (i == bufferInfoNb){ return -1; }
|
||||
bufferFreeIndex=i;
|
||||
|
||||
if (munmap(bufferInfoTabAddr, bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{
|
||||
NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return bufferFreeIndex;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferGetProcAttach(msgPoolData * poolDataTabAddr,
|
||||
int msgBufferGetProcAttach(
|
||||
msgPoolData * poolDataTabAddr,
|
||||
int poolNb,
|
||||
int *poolIndex, int *bufferIndex, void *addr)
|
||||
{
|
||||
int * poolIndex,
|
||||
int * bufferIndex,
|
||||
void * addr
|
||||
){
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
int bufferInfoTabFd;
|
||||
msgBufferInfo * bufferInfoTabAddr;
|
||||
|
@ -18,17 +21,13 @@ int msgBufferGetProcAttach(msgPoolData * poolDataTabAddr,
|
|||
strcpy(bufferInfoTabId, poolDataTabAddr[pIdx].bufferInfoTabId);
|
||||
bufferInfoNb=poolDataTabAddr[pIdx].bufferNb;
|
||||
|
||||
bufferInfoTabFd =
|
||||
shm_open(bufferInfoTabId, O_RDWR, SHM_DEFAULT_MODE);
|
||||
if (bufferInfoTabFd < 0) {
|
||||
NZG_ERROR("shm_open", bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||
if (bufferInfoTabFd<0)
|
||||
{ NZG_ERROR("shm_open",bufferInfoTabId); return -1; }
|
||||
|
||||
/** on regarde dans le tableau d'infos de buffer **/
|
||||
bufferInfoTabAddr =
|
||||
mmap(NULL, bufferInfoNb * sizeof(msgBufferInfo), PROT_READ,
|
||||
MAP_SHARED, bufferInfoTabFd, (off_t) 0);
|
||||
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
|
||||
PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||
|
||||
/* on cherche dans chacun des buffers */
|
||||
bIdx=0;
|
||||
|
@ -39,23 +38,14 @@ int msgBufferGetProcAttach(msgPoolData * poolDataTabAddr,
|
|||
};
|
||||
bIdx++;
|
||||
}
|
||||
if (found) {
|
||||
(*poolIndex) = pIdx;
|
||||
}
|
||||
if (found){ (*poolIndex)=pIdx; }
|
||||
/* on détache le morceau de mémoire */
|
||||
if (munmap
|
||||
(bufferInfoTabAddr,
|
||||
bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
||||
NZG_ERROR("munmap", bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{ NZG_ERROR("munmap",bufferInfoTabId); return -1; }
|
||||
close(bufferInfoTabFd);
|
||||
pIdx++;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (found){ return 0; } else {return -1;}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgBufferInfoTabCreate(msgSpaceId externId,
|
||||
int msgBufferInfoTabCreate(
|
||||
msgSpaceId externId,
|
||||
msgPoolData * poolDataTabAddr,
|
||||
int poolIdx, int bufferNb)
|
||||
{
|
||||
int poolIdx,
|
||||
int bufferNb) {
|
||||
|
||||
int bufferInfoTabFd;
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
|
@ -15,12 +16,10 @@ int msgBufferInfoTabCreate(msgSpaceId externId,
|
|||
return -1;
|
||||
}
|
||||
|
||||
bufferInfoTabFd =
|
||||
shm_open(bufferInfoTabId, O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
||||
MSGSPACE_DEFAULT_MODE);
|
||||
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));
|
||||
fprintf( stderr, "msgInfoTab : %s creation failed: %s\n",bufferInfoTabId,
|
||||
strerror( errno ) );
|
||||
return -1;
|
||||
}
|
||||
if (ftruncate(bufferInfoTabFd, bufferNb*sizeof(msgBufferInfo)) == -1){
|
||||
|
@ -33,7 +32,6 @@ int msgBufferInfoTabCreate(msgSpaceId externId,
|
|||
|
||||
msgBufferInfoTabInit(poolDataTabAddr,poolIdx);
|
||||
|
||||
return -1;
|
||||
NZG_ERROR("munmap", bufferInfoTabId);
|
||||
return -1;NZG_ERROR("munmap",bufferInfoTabId);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr, int poolIndex)
|
||||
{
|
||||
int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr,int poolIndex){
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
int bufferInfoTabFd;
|
||||
msgBufferInfo * bufferInfoTabAddr;
|
||||
|
@ -11,8 +10,7 @@ int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr, int poolIndex)
|
|||
//récuperer l'ID du BufferInfoTab;
|
||||
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||
|
||||
printf("msgBufferInfoTabId %d open >>%s<<\n", 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);
|
||||
|
@ -22,17 +20,15 @@ int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr, int poolIndex)
|
|||
/** 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);
|
||||
PROT_WRITE|PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||
|
||||
for (i=0;i<bufferInfoNb;i++){
|
||||
bufferInfoTabAddr[i].ownerPid = (pid_t)-1;
|
||||
}
|
||||
|
||||
if (munmap(bufferInfoTabAddr, bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
||||
perror("munmap");
|
||||
return -1;
|
||||
}
|
||||
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||
{ perror("munmap"); return -1; }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
void *msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex)
|
||||
{
|
||||
|
||||
void * msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex) {
|
||||
void * resultAddr;
|
||||
int bufferSize, bufferNb;
|
||||
int poolBufferTabFd;
|
||||
|
@ -11,30 +11,32 @@ void *msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex)
|
|||
strcpy(poolBufferTabId, poolDataTab[poolIndex].poolId);
|
||||
bufferSize=poolDataTab[poolIndex].bufferSize;
|
||||
bufferNb=poolDataTab[poolIndex].bufferNb;
|
||||
if (bufferNb < 0) {
|
||||
// do something with bufferNb
|
||||
}
|
||||
|
||||
poolBufferTabFd=shm_open(poolBufferTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||
if (poolBufferTabFd<0){
|
||||
NZG_ERROR("shm_open",poolBufferTabId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
// mapper le buffer dans l'espace mémoire du processus
|
||||
/* on s'arrete juste derriere l'index qui nous intéresse */
|
||||
resultAddr = mmap(NULL, bufferSize * (bufferIndex + 1), PROT_READ | PROT_WRITE, //PROT_NONE
|
||||
MAP_SHARED, poolBufferTabFd, (off_t) 0);
|
||||
resultAddr=mmap(NULL,
|
||||
bufferSize*(bufferIndex+1),
|
||||
PROT_READ|PROT_WRITE, //PROT_NONE
|
||||
MAP_SHARED,
|
||||
poolBufferTabFd,
|
||||
(off_t)0);
|
||||
if(resultAddr == MAP_FAILED) {
|
||||
NZG_ERROR("mmap", poolBufferTabId);
|
||||
goto ERROR;
|
||||
}
|
||||
printf("Mapped from %p to %p\n",
|
||||
(void *)resultAddr,
|
||||
(void *)(resultAddr + bufferSize * (bufferIndex + 1))
|
||||
printf( "Mapped from 0x%08x to 0x%08x\n",
|
||||
(int)resultAddr,
|
||||
(int)resultAddr+ bufferSize*(bufferIndex+1)
|
||||
);
|
||||
|
||||
resultAddr=resultAddr +( bufferSize*bufferIndex);
|
||||
printf("Moved to %p\n", (void *)resultAddr);
|
||||
printf( "Moved to 0x%08x\n",(int)resultAddr );
|
||||
|
||||
/* mprotect(
|
||||
resultAddr,
|
||||
|
|
17
src/free.c
17
src/free.c
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgFree(msgSpace * space, void *addr)
|
||||
{
|
||||
int msgFree(msgSpace * space, void * addr){
|
||||
|
||||
int poolIndex;
|
||||
int bufferIndex;
|
||||
|
@ -12,7 +11,7 @@ int msgFree(msgSpace * space, void *addr)
|
|||
int bufferNb;
|
||||
int bufferSize;
|
||||
void * realAddr;
|
||||
printf("[ FREE %p ]\n", (void *)addr);
|
||||
printf("[ FREE 0x%08x ]\n",(int)addr);
|
||||
/* on acquiert le droit de modifier les infos sur la ressource */
|
||||
/* on protege le tableau des associations */
|
||||
if (msgPoolDataTabLock(space) <0){
|
||||
|
@ -26,11 +25,14 @@ int msgFree(msgSpace * space, void *addr)
|
|||
|
||||
// TODO: verouiller semaphore DataInfo ??
|
||||
|
||||
poolIndex = -1;
|
||||
bufferIndex = -1;
|
||||
err = msgBufferGetProcAttach(poolDataTabAddr,
|
||||
poolIndex=-1; bufferIndex=-1;
|
||||
err=msgBufferGetProcAttach(
|
||||
poolDataTabAddr,
|
||||
space->poolNb,
|
||||
&poolIndex, &bufferIndex, addr);
|
||||
&poolIndex,
|
||||
&bufferIndex,
|
||||
addr
|
||||
);
|
||||
|
||||
printf("Found : %d\n",err);
|
||||
printf("Freing pool: %d, buffer: %d\n",poolIndex,bufferIndex);
|
||||
|
@ -61,3 +63,4 @@ int msgFree(msgSpace * space, void *addr)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
#define NONBLOCK -1
|
||||
|
||||
void *msgGet(msgSpace * space, int queueIndex, int option)
|
||||
{
|
||||
void * msgGet(msgSpace * space,int queueIndex,int option){
|
||||
void * resultAddr;
|
||||
msgQueueId queueId;
|
||||
msgQueue * queue;
|
||||
|
@ -43,12 +42,12 @@ void *msgGet(msgSpace * space, int queueIndex, int option)
|
|||
/* on récupere la taille des buffer dans la pool du buffer */
|
||||
poolDataTab=msgPoolDataTabOpen(space);
|
||||
// mapper le buffer dans l'espace mémoire du processus
|
||||
resultAddr =
|
||||
msgBufferMap(poolDataTab, oldElem->poolIndex, oldElem->bufferIndex);
|
||||
resultAddr=msgBufferMap(poolDataTab,oldElem->poolIndex,oldElem->bufferIndex);
|
||||
// attacher au buffer...
|
||||
if (msgBufferAttachProc(poolDataTab,
|
||||
oldElem->poolIndex,
|
||||
oldElem->bufferIndex, resultAddr) < 0) {
|
||||
oldElem->bufferIndex,
|
||||
resultAddr) <0){
|
||||
NZG_ERROR("msgBufferAttachProc",oldElemId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
|
|
@ -25,10 +25,12 @@
|
|||
#define SEM_FAILED ((sem_t *)0)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _NZG_REALFILEID
|
||||
#define DEFAULT_MSGSPACELISTID "/tmp/nzgSpaceList"
|
||||
#else
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef _NZG_GLOBAL
|
||||
#define _NZG_GLOBAL 1
|
||||
|
||||
#include <unistd.h> /* POSIX et al */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h> /* pour O_RDWR */
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h> /* shm_open */
|
||||
#include <errno.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#define PAGESIZE sysconf(_SC_PAGESIZE)
|
||||
#define MSGSPACE_DEFAULT_MODE 0600
|
||||
#define SEM_DEFAULT_MODE 0600
|
||||
#define SHM_DEFAULT_MODE 0600
|
||||
#define MSGSPACE_ID_LEN 32
|
||||
#define ERR_UNHANDLED "Gérer mieu les erreurs"
|
||||
|
||||
#define ANYPOOL -1
|
||||
#define SPECIFICPOOL 0
|
||||
|
||||
#ifndef SEM_FAILED
|
||||
#define SEM_FAILED ((sem_t *)0)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _NZG_REALFILEID
|
||||
#define DEFAULT_MSGSPACELISTID "/tmp/nzgSpaceList"
|
||||
#else
|
||||
#define DEFAULT_MSGSPACELISTID "/nzgSpaceList"
|
||||
#endif
|
||||
|
||||
#ifdef _NZG_REALFILEID
|
||||
#define DEFAULT_MSGSPACELISTSEMID "/tmp/nzgSpaceListSem"
|
||||
#else
|
||||
#define DEFAULT_MSGSPACELISTSEMID "/nzgSpaceListSem"
|
||||
#endif
|
||||
|
||||
#define NZG_ERROR(func,str) fprintf(stderr,"*** %s: %s***\n%s in %s:%d\n",func,strerror(errno),str,__FILE__,__LINE__);
|
||||
|
||||
#endif
|
62
src/ids.c
62
src/ids.c
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src)
|
||||
{
|
||||
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src ){
|
||||
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -14,9 +13,9 @@ int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src)
|
|||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId)
|
||||
{
|
||||
int msgPoolDataTabSemIdIntern(
|
||||
msgPoolSemId destSemId,
|
||||
const msgSpaceId externId){
|
||||
if (strlen(externId)>MSGSPACE_ID_LEN*4){
|
||||
return -1;
|
||||
}
|
||||
|
@ -28,10 +27,10 @@ int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId)
|
|||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int msgPoolSemIdIntern(msgPoolSemId destSemId,
|
||||
const msgSpaceId srcPoolId, int poolIdx)
|
||||
{
|
||||
int msgPoolSemIdIntern(
|
||||
msgPoolSemId destSemId,
|
||||
const msgSpaceId srcPoolId,
|
||||
int poolIdx){
|
||||
if (strlen(srcPoolId)>MSGSPACE_ID_LEN*4){
|
||||
return -1;
|
||||
}
|
||||
|
@ -44,8 +43,7 @@ int msgPoolSemIdIntern(msgPoolSemId destSemId,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src)
|
||||
{
|
||||
int msgPoolDataIdIntern(msgPoolDataTabId dest,const msgSpaceId src ){
|
||||
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -58,8 +56,8 @@ int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num)
|
||||
{
|
||||
|
||||
int msgPoolIdIntern(msgPoolId dest,msgPoolId src, int num){
|
||||
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -71,8 +69,10 @@ int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num)
|
||||
{
|
||||
int msgBufferInfoTabIdIntern(
|
||||
msgBufferInfoTabId dest,
|
||||
msgSpaceId src,
|
||||
int num){
|
||||
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -84,9 +84,10 @@ int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgQueueProtSemIdIntern(msgQueueSemId dest,
|
||||
msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueProtSemIdIntern(
|
||||
msgQueueSemId dest,
|
||||
msgSpaceId externId,
|
||||
int queueIdx){
|
||||
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -98,9 +99,10 @@ int msgQueueProtSemIdIntern(msgQueueSemId dest,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgQueueReadSemIdIntern(msgQueueSemId dest,
|
||||
msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueReadSemIdIntern(
|
||||
msgQueueSemId dest,
|
||||
msgSpaceId externId,
|
||||
int queueIdx){
|
||||
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -112,8 +114,10 @@ int msgQueueReadSemIdIntern(msgQueueSemId dest,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueIdIntern(
|
||||
msgQueueId dest,
|
||||
msgSpaceId externId,
|
||||
int queueIdx){
|
||||
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -125,8 +129,10 @@ int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter)
|
||||
{
|
||||
int msgQueueElemIdIntern(
|
||||
msgQueueElemId dest,
|
||||
msgQueueId src,
|
||||
int counter){
|
||||
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -134,8 +140,7 @@ int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId)
|
||||
{
|
||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId,msgSpaceId externId){
|
||||
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||
return -1;
|
||||
}
|
||||
|
@ -148,3 +153,6 @@ int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId)
|
|||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
16
src/ids.h
16
src/ids.h
|
@ -2,13 +2,21 @@
|
|||
#define _NZG_IDS 1
|
||||
#include "libnazgul.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/* nzg_ids.c */
|
||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
||||
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId,
|
||||
int poolIdx);
|
||||
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 msgQueueSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueSemIdIntern(
|
||||
msgQueueSemId dest,
|
||||
msgSpaceId externId,
|
||||
int queueIdx);
|
||||
int msgQueueIdIntern(
|
||||
msgQueueId dest,
|
||||
msgSpaceId externId,
|
||||
int queueIdx);
|
||||
|
||||
#endif
|
||||
|
|
22
src/ids.h~
22
src/ids.h~
|
@ -1,22 +0,0 @@
|
|||
#ifndef _NZG_IDS
|
||||
#define _NZG_IDS 1
|
||||
#include "libnazgul.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/* 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 msgQueueSemIdIntern(
|
||||
msgQueueSemId dest,
|
||||
msgSpaceId externId,
|
||||
int queueIdx);
|
||||
int msgQueueIdIntern(
|
||||
msgQueueId dest,
|
||||
msgSpaceId externId,
|
||||
int queueIdx);
|
||||
|
||||
#endif
|
|
@ -46,6 +46,7 @@ typedef struct MsgPoolData {
|
|||
|
||||
/* TODO: queueId */
|
||||
|
||||
|
||||
typedef struct MsgSpace {
|
||||
msgSpaceId id;
|
||||
msgSpaceId externId;
|
||||
|
@ -56,6 +57,7 @@ typedef struct MsgSpace {
|
|||
msgPoolDataTabSemId poolDataTabSemId;
|
||||
} msgSpace;
|
||||
|
||||
|
||||
typedef struct MsgSpaceListElem {
|
||||
msgSpaceListElemId id;
|
||||
|
||||
|
|
91
src/iface.h~
91
src/iface.h~
|
@ -1,91 +0,0 @@
|
|||
#ifndef _NZG_IFACE
|
||||
#define _NZG_IFACE 1
|
||||
|
||||
#include "global.h"
|
||||
|
||||
typedef enum { true=1, false=0} bool;
|
||||
|
||||
typedef char msgSpaceId[MSGSPACE_ID_LEN];
|
||||
|
||||
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
|
||||
typedef char msgSpaceListSemId[4*MSGSPACE_ID_LEN];
|
||||
typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN];
|
||||
|
||||
typedef char msgPoolDataTabId[4*MSGSPACE_ID_LEN];
|
||||
typedef char msgPoolDataTabSemId[4*MSGSPACE_ID_LEN];
|
||||
|
||||
typedef char msgBufferInfoTabId[4*MSGSPACE_ID_LEN];
|
||||
|
||||
typedef char msgPoolId[4*MSGSPACE_ID_LEN];
|
||||
typedef char msgPoolSemId[4*MSGSPACE_ID_LEN];
|
||||
|
||||
typedef char msgQueueDataId[4*MSGSPACE_ID_LEN];
|
||||
typedef char msgQueueId[4*MSGSPACE_ID_LEN];
|
||||
typedef char msgQueueElemId[4*MSGSPACE_ID_LEN];
|
||||
typedef char msgQueueSemId[4*MSGSPACE_ID_LEN];
|
||||
|
||||
/* pid[] */
|
||||
/* liste des processus demandeurs */
|
||||
typedef struct MsgPool {
|
||||
int bufferSize;
|
||||
int bufferNb;
|
||||
} msgPool;
|
||||
|
||||
typedef struct MsgBufferInfo {
|
||||
pid_t ownerPid;
|
||||
void * addr;
|
||||
} msgBufferInfo;
|
||||
|
||||
typedef struct MsgPoolData {
|
||||
msgPoolId poolId;
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
int bufferNb;
|
||||
int bufferSize;
|
||||
int allocDispBuffer;
|
||||
} msgPoolData;
|
||||
|
||||
/* TODO: queueId */
|
||||
|
||||
|
||||
typedef struct MsgSpace {
|
||||
msgSpaceId id;
|
||||
msgSpaceId externId;
|
||||
int poolNb;
|
||||
int queueNb;
|
||||
int pid;
|
||||
msgPoolDataTabId poolDataTabId;
|
||||
msgPoolDataTabSemId poolDataTabSemId;
|
||||
} msgSpace;
|
||||
|
||||
|
||||
typedef struct MsgSpaceListElem {
|
||||
msgSpaceListElemId id;
|
||||
|
||||
msgSpaceId spaceId;
|
||||
msgSpaceListElemId next;
|
||||
} msgSpaceListElem;
|
||||
|
||||
typedef struct MsgSpaceList {
|
||||
msgSpaceListId id;
|
||||
|
||||
int elemCounter;
|
||||
msgSpaceListElemId headId;
|
||||
msgSpaceListElemId tailId;
|
||||
} msgSpaceList;
|
||||
|
||||
typedef struct MsgQueueElem {
|
||||
msgQueueElemId id;
|
||||
int poolIndex;
|
||||
int bufferIndex;
|
||||
msgQueueElemId next;
|
||||
} msgQueueElem;
|
||||
|
||||
typedef struct MsgQueue {
|
||||
msgQueueId id;
|
||||
int elemCounter;
|
||||
msgQueueElemId headId;
|
||||
msgQueueElemId tailId;
|
||||
} msgQueue;
|
||||
|
||||
#endif
|
||||
/* */
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef _LIBNAZGUL
|
||||
#define _LIBNAZGUL 1
|
||||
|
||||
#include "global.h"
|
||||
#include "iface.h"
|
||||
#include "proto.h"
|
||||
|
||||
#endif
|
|
@ -1,8 +1,12 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize)
|
||||
{
|
||||
int msgPoolCreate(
|
||||
msgSpaceId externId,
|
||||
int poolIdx,
|
||||
int buffNb,
|
||||
int buffSize
|
||||
) {
|
||||
|
||||
int poolFd;
|
||||
sem_t * ressourceSemFd;
|
||||
|
@ -11,13 +15,10 @@ int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize)
|
|||
|
||||
/* creation des buffers DEBUT */
|
||||
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;
|
||||
}
|
||||
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 ) {
|
||||
fprintf( stderr, "msgPool : %s creation failed: %s\n",poolId,
|
||||
strerror( errno ) );
|
||||
|
@ -35,17 +36,14 @@ int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize)
|
|||
(char*)poolRessourceSemId );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// on met un semaphore sur le pool
|
||||
ressourceSemFd =
|
||||
sem_open(poolRessourceSemId, O_CREAT | O_EXCL, SEM_DEFAULT_MODE,
|
||||
buffNb);
|
||||
ressourceSemFd = sem_open(poolRessourceSemId, O_CREAT|O_EXCL,SEM_DEFAULT_MODE, buffNb);
|
||||
if (ressourceSemFd == SEM_FAILED){
|
||||
NZG_ERROR("sem_open : creation de la ressource",
|
||||
poolRessourceSemId);
|
||||
NZG_ERROR("sem_open : creation de la ressource",poolRessourceSemId);
|
||||
goto ERROR;
|
||||
} else {
|
||||
printf("[ Created %s with %d ressources ]\n",
|
||||
poolRessourceSemId, buffNb);
|
||||
printf("[ Created %s with %d ressources ]\n",poolRessourceSemId,buffNb);
|
||||
}
|
||||
|
||||
//TODO: verrifier les erreurs sur l'ouverture de la sem
|
||||
|
@ -60,3 +58,4 @@ int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgPoolDataTabClose(msgSpace * space, void *addr)
|
||||
{
|
||||
int msgPoolDataTabClose(msgSpace * space,void * addr){
|
||||
/* unmapper le msgPoolDataTab */
|
||||
|
||||
if (munmap(addr,(space->poolNb) * sizeof( msgPoolData )) < 0){
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
void *msgPoolDataTabCreate(msgSpace * space)
|
||||
{
|
||||
void * msgPoolDataTabCreate(msgSpace * space){
|
||||
int poolDataFd; // shm file descriptor
|
||||
msgPoolData * poolDataTabAddr;
|
||||
poolDataFd = shm_open(space->poolDataTabId,
|
||||
poolDataFd=shm_open(
|
||||
space->poolDataTabId,
|
||||
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||
MSGSPACE_DEFAULT_MODE);
|
||||
MSGSPACE_DEFAULT_MODE
|
||||
);
|
||||
if (poolDataFd == -1 ) {
|
||||
NZG_ERROR("shm_open :create",space->poolDataTabId);
|
||||
goto ERROR;
|
||||
|
@ -37,3 +38,5 @@ void *msgPoolDataTabCreate(msgSpace * space)
|
|||
ERROR:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
|
||||
#define DEBUG 0
|
||||
|
||||
int msgPoolDataTabLock(msgSpace * space)
|
||||
{
|
||||
int msgPoolDataTabLock(msgSpace * space){
|
||||
int semval;
|
||||
sem_t * poolDataTabSemFd;
|
||||
semval=0;
|
||||
if (DEBUG) {
|
||||
printf("Locking %s\n", space->poolDataTabSemId);
|
||||
}
|
||||
if (DEBUG) {printf("Locking %s\n",space->poolDataTabSemId);}
|
||||
|
||||
poolDataTabSemFd = sem_open(space->poolDataTabSemId, O_CREAT,
|
||||
SEM_DEFAULT_MODE, 1);
|
||||
poolDataTabSemFd=sem_open(
|
||||
space->poolDataTabSemId
|
||||
,O_CREAT,
|
||||
SEM_DEFAULT_MODE,
|
||||
1);
|
||||
if(poolDataTabSemFd==SEM_FAILED){
|
||||
NZG_ERROR("sem_open",space->poolDataTabSemId);
|
||||
goto ERROR;
|
||||
|
@ -25,9 +25,7 @@ int msgPoolDataTabLock(msgSpace * space)
|
|||
}
|
||||
|
||||
sem_getvalue(poolDataTabSemFd,&semval);
|
||||
if (DEBUG) {
|
||||
printf("(AfternValue:%d)\n", semval);
|
||||
}
|
||||
if (DEBUG) { printf("(AfternValue:%d)\n",semval);}
|
||||
|
||||
sem_close(poolDataTabSemFd);
|
||||
|
||||
|
@ -35,3 +33,4 @@ int msgPoolDataTabLock(msgSpace * space)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
void *msgPoolDataTabOpen(msgSpace * space)
|
||||
{
|
||||
void * msgPoolDataTabOpen(msgSpace * space){
|
||||
int poolDataTabFd;
|
||||
void * poolDataTabAddr;
|
||||
|
||||
poolDataTabFd=shm_open(space->poolDataTabId,
|
||||
O_RDWR, MSGSPACE_DEFAULT_MODE);
|
||||
O_RDWR,
|
||||
MSGSPACE_DEFAULT_MODE);
|
||||
if (poolDataTabFd == -1 ) {
|
||||
NZG_ERROR("shm_open",space->poolDataTabId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
|
||||
poolDataTabAddr = mmap( NULL, (space->poolNb) * sizeof( msgPoolData ),
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, poolDataTabFd, 0 );
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
#define DEBUG 0
|
||||
|
||||
int msgPoolDataTabUnlock(msgSpace * space)
|
||||
{
|
||||
int msgPoolDataTabUnlock(msgSpace * space){
|
||||
int semval;
|
||||
sem_t * poolDataTabSemFd;
|
||||
if (DEBUG) {
|
||||
printf("Unlocking %s\n", space->poolDataTabSemId);
|
||||
}
|
||||
poolDataTabSemFd = sem_open(space->poolDataTabSemId, O_CREAT,
|
||||
SEM_DEFAULT_MODE, 1);
|
||||
if (DEBUG) { printf("Unlocking %s\n",space->poolDataTabSemId); }
|
||||
poolDataTabSemFd=sem_open(
|
||||
space->poolDataTabSemId
|
||||
,O_CREAT,
|
||||
SEM_DEFAULT_MODE,
|
||||
1);
|
||||
if(poolDataTabSemFd==SEM_FAILED){
|
||||
NZG_ERROR("sem_open",space->poolDataTabSemId);
|
||||
goto ERROR;
|
||||
|
@ -24,9 +24,7 @@ int msgPoolDataTabUnlock(msgSpace * space)
|
|||
|
||||
semval=0;
|
||||
sem_getvalue(poolDataTabSemFd,&semval);
|
||||
if (DEBUG) {
|
||||
printf("(AfternValue:%d)\n", semval);
|
||||
}
|
||||
if (DEBUG) { printf("(AfternValue:%d)\n",semval); }
|
||||
|
||||
sem_close(poolDataTabSemFd);
|
||||
|
||||
|
@ -34,3 +32,4 @@ int msgPoolDataTabUnlock(msgSpace * space)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +1,32 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgPoolDelete(msgSpaceId spaceId, int poolIdx)
|
||||
{
|
||||
int msgPoolDelete(
|
||||
msgSpaceId spaceId,
|
||||
int poolIdx
|
||||
) {
|
||||
|
||||
msgPoolId poolId;
|
||||
msgBufferInfoTabId bufferInfoTabId;
|
||||
msgPoolSemId poolRessourceSemId;
|
||||
|
||||
|
||||
/* suppression des infos sur buffers DEBUT */
|
||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId,spaceId,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;
|
||||
}
|
||||
|
||||
if (shm_unlink(bufferInfoTabId) <0 ) {
|
||||
fprintf(stderr, "msgInfoTab : %s deletion failed: %s\n",
|
||||
bufferInfoTabId, strerror(errno));
|
||||
fprintf( stderr, "msgInfoTab : %s deletion failed: %s\n",bufferInfoTabId,
|
||||
strerror( errno ) );
|
||||
return -1;
|
||||
}
|
||||
/* suppression des infos sur buffers FIN */
|
||||
|
||||
/* suppression des buffers DEBUT */
|
||||
if (msgPoolIdIntern(poolId,spaceId,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;
|
||||
}
|
||||
if (shm_unlink(poolId) <0 ) {
|
||||
|
|
36
src/proto.h
36
src/proto.h
|
@ -4,22 +4,17 @@
|
|||
/* allocate.c */
|
||||
void *msgAllocate(msgSpace *space, int pool, int taille, int option);
|
||||
/* bufferAttachProc.c */
|
||||
int msgBufferAttachProc(msgPoolData * poolDataTabAddr, int poolIndex,
|
||||
int bufferIndex, void *addr);
|
||||
int msgBufferAttachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||
/* buffer.c */
|
||||
int msgBufferGetAttachedProcIndex(msgPoolData * poolDataTabAddr, int poolIndex,
|
||||
void *addr);
|
||||
int msgBufferGetAttachedProcIndex(msgPoolData *poolDataTabAddr, int poolIndex, void *addr);
|
||||
/* bufferDetachProc.c */
|
||||
int msgBufferDetachProc(msgPoolData * poolDataTabAddr, int poolIndex,
|
||||
int bufferIndex, void *addr);
|
||||
int msgBufferDetachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||
/* bufferGetFreeIndex.c */
|
||||
int msgBufferGetFreeIndex(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||
/* bufferGetProcAttach.c */
|
||||
int msgBufferGetProcAttach(msgPoolData * poolDataTabAddr, int poolNb,
|
||||
int *poolIndex, int *bufferIndex, void *addr);
|
||||
int msgBufferGetProcAttach(msgPoolData *poolDataTabAddr, int poolNb, int *poolIndex, int *bufferIndex, void *addr);
|
||||
/* bufferInfoTabCreate.c */
|
||||
int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData * poolDataTabAddr,
|
||||
int poolIdx, int bufferNb);
|
||||
int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData *poolDataTabAddr, int poolIdx, int bufferNb);
|
||||
/* bufferInfoTabInit.c */
|
||||
int msgBufferInfoTabInit(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||
/* bufferMap.c */
|
||||
|
@ -30,21 +25,16 @@ int msgFree(msgSpace * space, void *addr);
|
|||
void *msgGet(msgSpace *space, int queueIndex, int option);
|
||||
/* ids.c */
|
||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
||||
const msgSpaceId externId);
|
||||
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId,
|
||||
int poolIdx);
|
||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId);
|
||||
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);
|
||||
int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId,
|
||||
int queueIdx);
|
||||
int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId,
|
||||
int queueIdx);
|
||||
int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter);
|
||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId,
|
||||
msgSpaceId externId);
|
||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId);
|
||||
/* list.c */
|
||||
/* poolCreate.c */
|
||||
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
|
||||
|
@ -71,8 +61,7 @@ int msgQueueDelete(msgQueueId externId, int queueIdx);
|
|||
/* queueElemClose.c */
|
||||
int msgQueueElemClose(msgQueueElem *queueElem);
|
||||
/* queueElemCreate.c */
|
||||
int msgQueueElemCreate(msgQueueElemId finalQueueElemId, msgQueueId queueId,
|
||||
int counter);
|
||||
int msgQueueElemCreate(msgQueueElemId finalQueueElemId, msgQueueId queueId, int counter);
|
||||
/* queueElemDelete.c */
|
||||
int msgQueueElemDelete(msgQueueElemId queueElemId);
|
||||
/* queueElemOpen.c */
|
||||
|
@ -96,8 +85,7 @@ int msgQueueRem(msgQueue * queue, msgQueueElemId oldElemId);
|
|||
/* spaceClose.c */
|
||||
int msgSpaceClose(msgSpace *space);
|
||||
/* spaceCreate.c */
|
||||
msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb,
|
||||
msgPool * poolInfos);
|
||||
msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb, msgPool *poolInfos);
|
||||
/* spaceDelete.c */
|
||||
int msgSpaceDelete(msgSpaceId externId);
|
||||
/* spaceListAdd.c */
|
||||
|
|
118
src/proto.h~
118
src/proto.h~
|
@ -1,118 +0,0 @@
|
|||
#ifndef _NZG_PROTO
|
||||
#define _NZG_PROTO 1
|
||||
|
||||
/* allocate.c */
|
||||
void *msgAllocate(msgSpace *space, int pool, int taille, int option);
|
||||
/* bufferAttachProc.c */
|
||||
int msgBufferAttachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||
/* buffer.c */
|
||||
int msgBufferGetAttachedProcIndex(msgPoolData *poolDataTabAddr, int poolIndex, void *addr);
|
||||
/* bufferDetachProc.c */
|
||||
int msgBufferDetachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||
/* bufferGetFreeIndex.c */
|
||||
int msgBufferGetFreeIndex(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||
/* bufferGetProcAttach.c */
|
||||
int msgBufferGetProcAttach(msgPoolData *poolDataTabAddr, int poolNb, int *poolIndex, int *bufferIndex, void *addr);
|
||||
/* bufferInfoTabCreate.c */
|
||||
int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData *poolDataTabAddr, int poolIdx, int bufferNb);
|
||||
/* bufferInfoTabInit.c */
|
||||
int msgBufferInfoTabInit(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||
/* bufferMap.c */
|
||||
void *msgBufferMap(msgPoolData *poolDataTab, int poolIndex, int bufferIndex);
|
||||
/* free.c */
|
||||
int msgFree(msgSpace *space, void *addr);
|
||||
/* get.c */
|
||||
void *msgGet(msgSpace *space, int queueIndex, int option);
|
||||
/* ids.c */
|
||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId);
|
||||
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);
|
||||
int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx);
|
||||
int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter);
|
||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId);
|
||||
/* list.c */
|
||||
/* poolCreate.c */
|
||||
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
|
||||
/* poolDataTabClose.c */
|
||||
int msgPoolDataTabClose(msgSpace *space, void *addr);
|
||||
/* poolDataTabCreate.c */
|
||||
void *msgPoolDataTabCreate(msgSpace *space);
|
||||
/* poolDataTabLock.c */
|
||||
int msgPoolDataTabLock(msgSpace *space);
|
||||
/* poolDataTabOpen.c */
|
||||
void *msgPoolDataTabOpen(msgSpace *space);
|
||||
/* poolDataTabUnlock.c */
|
||||
int msgPoolDataTabUnlock(msgSpace *space);
|
||||
/* poolDelete.c */
|
||||
int msgPoolDelete(msgSpaceId spaceId, int poolIdx);
|
||||
/* put.c */
|
||||
int msgPut(msgSpace *space, int queueIndex, void *addr);
|
||||
/* queueAdd.c */
|
||||
int msgQueueAdd(msgQueue *queue, msgQueueElemId newElemId);
|
||||
/* queueClose.c */
|
||||
int msgQueueClose(msgQueue *queue);
|
||||
/* queueDelete.c */
|
||||
int msgQueueDelete(msgQueueId externId, int queueIdx);
|
||||
/* queueElemClose.c */
|
||||
int msgQueueElemClose(msgQueueElem *queueElem);
|
||||
/* queueElemCreate.c */
|
||||
int msgQueueElemCreate(msgQueueElemId finalQueueElemId, msgQueueId queueId, int counter);
|
||||
/* queueElemDelete.c */
|
||||
int msgQueueElemDelete(msgQueueElemId queueElemId);
|
||||
/* queueElemOpen.c */
|
||||
void *msgQueueElemOpen(msgQueueElemId queueElemId);
|
||||
/* queueInit.c */
|
||||
msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx);
|
||||
/* queueOpen.c */
|
||||
void *msgQueueOpen(msgQueueId queueId);
|
||||
/* queueProtLock.c */
|
||||
int msgQueueProtLock(msgSpaceId externId, int queueIdx);
|
||||
/* queueProtUnlock.c */
|
||||
int msgQueueProtUnlock(msgSpaceId externId, int queueIdx);
|
||||
/* queueReadLock.c */
|
||||
int msgQueueReadLock(msgSpaceId externId, int queueIdx);
|
||||
/* queueReadTryLock.c */
|
||||
int msgQueueReadTryLock(msgSpaceId externId, int queueIdx);
|
||||
/* queueReadUnlock.c */
|
||||
int msgQueueReadUnlock(msgSpaceId externId, int queueIdx);
|
||||
/* queueRem.c */
|
||||
int msgQueueRem(msgQueue *queue, msgQueueElemId oldElemId);
|
||||
/* spaceClose.c */
|
||||
int msgSpaceClose(msgSpace *space);
|
||||
/* spaceCreate.c */
|
||||
msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb, msgPool *poolInfos);
|
||||
/* spaceDelete.c */
|
||||
int msgSpaceDelete(msgSpaceId externId);
|
||||
/* spaceListAdd.c */
|
||||
int msgSpaceListAdd(msgSpaceListElemId newElemId);
|
||||
/* spaceListClose.c */
|
||||
int msgSpaceListClose(msgSpaceList *list);
|
||||
/* spaceListElemClose.c */
|
||||
int msgSpaceListElemClose(msgSpaceListElem *listElem);
|
||||
/* spaceListElemCreate.c */
|
||||
int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace *space);
|
||||
/* spaceListElemLink.c */
|
||||
/* spaceListElemOpen.c */
|
||||
void *msgSpaceListElemOpen(msgSpaceListElemId listElemId);
|
||||
/* spaceListFindId.c */
|
||||
int msgSpaceListFindId(msgSpaceId externId);
|
||||
int msgSpaceListElemFindId(msgSpaceListElemId elemId, msgSpaceId spaceId);
|
||||
/* spaceListInit.c */
|
||||
int msgSpaceListInit(void);
|
||||
/* spaceListLocking.c */
|
||||
int msgSpaceListLock(void);
|
||||
int msgSpaceListUnlock(void);
|
||||
/* spaceListOpen.c */
|
||||
void *msgSpaceListOpen(void);
|
||||
/* spaceListRem.c */
|
||||
int msgSpaceListRem(msgSpaceId spaceId);
|
||||
/* spaceOpen.c */
|
||||
msgSpace *msgSpaceOpen(msgSpaceId externId);
|
||||
/* spaceState.c */
|
||||
|
||||
#endif
|
20
src/put.c
20
src/put.c
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgPut(msgSpace * space, int queueIndex, void *addr)
|
||||
{
|
||||
int msgPut(msgSpace * space,int queueIndex, void * addr){
|
||||
// retrouver le pool, buffer qui correspondent à l'addresse...
|
||||
msgPoolData * poolDataTabAddr;
|
||||
int poolIndex;
|
||||
|
@ -18,12 +17,14 @@ int msgPut(msgSpace * space, int queueIndex, void *addr)
|
|||
NZG_ERROR("msgPoolDataTabOpen",space->poolDataTabId);
|
||||
goto ERROR;
|
||||
}
|
||||
err = msgBufferGetProcAttach(poolDataTabAddr,
|
||||
err=msgBufferGetProcAttach(
|
||||
poolDataTabAddr,
|
||||
space->poolNb,
|
||||
&poolIndex, &bufferIndex, addr);
|
||||
if (err) {
|
||||
//FIXME
|
||||
}
|
||||
&poolIndex,
|
||||
&bufferIndex,
|
||||
addr
|
||||
);
|
||||
|
||||
// ouvrir la queue avec le bon index
|
||||
msgQueueIdIntern(queueId,space->externId,queueIndex);
|
||||
|
||||
|
@ -45,11 +46,13 @@ int msgPut(msgSpace * space, int queueIndex, void *addr)
|
|||
NZG_ERROR("msgQueueElemClose","");
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
//ajouter le message a la bonne file...
|
||||
if (msgQueueAdd(queue,newElemId) < 0){
|
||||
NZG_ERROR("msgQueueAdd",newElemId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
// fermer la file
|
||||
msgQueueClose(queue);
|
||||
msgQueueProtUnlock(space->externId,queueIndex);
|
||||
|
@ -60,7 +63,8 @@ int msgPut(msgSpace * space, int queueIndex, void *addr)
|
|||
// on laisse une nouvelle ressource de la liste au get
|
||||
msgQueueReadUnlock(space->externId,queueIndex);
|
||||
return 0;
|
||||
|
||||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
// on ajoute en fin de queue...
|
||||
|
||||
int msgQueueAdd(msgQueue * queue, msgQueueElemId newElemId)
|
||||
{
|
||||
int msgQueueAdd(msgQueue * queue, msgQueueElemId newElemId){
|
||||
msgQueueElem * queueOldTailElem;
|
||||
msgQueueElem * queueNewTailElem;
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgQueueClose(msgQueue * queue)
|
||||
{
|
||||
int msgQueueClose(msgQueue * queue){
|
||||
msgQueueId qId;
|
||||
strcpy(qId,queue->id);
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgQueueDelete(msgQueueId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueDelete(msgQueueId externId,int queueIdx){
|
||||
msgQueue * queue;
|
||||
msgQueueId queueId;
|
||||
msgQueueSemId queueProtLockSemId;
|
||||
|
@ -32,3 +31,5 @@ int msgQueueDelete(msgQueueId externId, int queueIdx)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgQueueElemClose(msgQueueElem * queueElem)
|
||||
{
|
||||
int msgQueueElemClose(msgQueueElem * queueElem){
|
||||
msgQueueElemId qId;
|
||||
strcpy(qId,queueElem->id);
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgQueueElemCreate(msgQueueElemId finalQueueElemId,
|
||||
msgQueueId queueId, int counter)
|
||||
{
|
||||
int msgQueueElemCreate(
|
||||
msgQueueElemId finalQueueElemId ,
|
||||
msgQueueId queueId,
|
||||
int counter){
|
||||
msgQueueElemId queueElemId;
|
||||
int queueElemFd;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgQueueElemDelete(msgQueueElemId queueElemId)
|
||||
{
|
||||
int msgQueueElemDelete(msgQueueElemId queueElemId){
|
||||
msgQueueElem * queueElem;
|
||||
msgQueueElemId nextIdToDie;
|
||||
|
||||
|
@ -17,6 +16,7 @@ int msgQueueElemDelete(msgQueueElemId queueElemId)
|
|||
NZG_ERROR("msgQueueElemClose",queueElemId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
// on détruit l'élément
|
||||
shm_unlink(queueElemId);
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
void *msgQueueElemOpen(msgQueueElemId queueElemId)
|
||||
{
|
||||
void * msgQueueElemOpen(msgQueueElemId queueElemId){
|
||||
int queueElemFd;
|
||||
void * queueElemAddr;
|
||||
|
||||
|
@ -15,7 +14,9 @@ void *msgQueueElemOpen(msgQueueElemId queueElemId)
|
|||
queueElemAddr=mmap(NULL,
|
||||
sizeof(msgQueueElem),
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED, queueElemFd, 0);
|
||||
MAP_SHARED,
|
||||
queueElemFd,
|
||||
0);
|
||||
if( queueElemAddr == MAP_FAILED ) {
|
||||
NZG_ERROR("mmap",queueElemId);
|
||||
goto ERROR;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
msgQueue * msgQueueInit(msgSpaceId externId, int queueIdx) {
|
||||
int queueFd;
|
||||
msgQueue * queue;
|
||||
sem_t * semProtectFd;
|
||||
|
@ -13,6 +12,7 @@ msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx)
|
|||
|
||||
queue = NULL;
|
||||
|
||||
|
||||
msgQueueProtSemIdIntern(queueSemProtectId,externId,queueIdx);
|
||||
msgQueueReadSemIdIntern(queueSemReadableId,externId,queueIdx);
|
||||
|
||||
|
@ -23,6 +23,7 @@ msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx)
|
|||
NZG_ERROR("sem_open", queueSemReadableId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
// creation du semaphore de protection
|
||||
semProtectFd = sem_open(queueSemProtectId,
|
||||
O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 0);
|
||||
|
@ -40,16 +41,15 @@ msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
queueFd =
|
||||
shm_open(queueId, O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
||||
MSGSPACE_DEFAULT_MODE);
|
||||
queueFd = shm_open(queueId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, MSGSPACE_DEFAULT_MODE);
|
||||
if(queueFd == -1) {
|
||||
NZG_ERROR("shm_open : queueInit",queueId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(ftruncate(queueFd, sizeof(msgQueue)) == -1) {
|
||||
fprintf(stderr, "Queue resizing failed: %s\n", strerror(errno));
|
||||
fprintf( stderr, "Queue resizing failed: %s\n",
|
||||
strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
void *msgQueueOpen(msgQueueId queueId)
|
||||
{
|
||||
void * msgQueueOpen(msgQueueId queueId){
|
||||
int queueFd;
|
||||
void * queueAddr;
|
||||
|
||||
|
@ -14,7 +13,10 @@ void *msgQueueOpen(msgQueueId queueId)
|
|||
|
||||
queueAddr=mmap(NULL,
|
||||
sizeof(msgQueue),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, queueFd, 0);
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
queueFd,
|
||||
0);
|
||||
if( queueAddr == MAP_FAILED ) {
|
||||
NZG_ERROR("mmap",queueId);
|
||||
goto ERROR;
|
||||
|
|
|
@ -2,16 +2,13 @@
|
|||
#include "ids.h"
|
||||
|
||||
#define DEBUG 0
|
||||
int msgQueueProtLock(msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueProtLock(msgSpaceId externId,int queueIdx){
|
||||
int semval;
|
||||
sem_t * queueSemFd;
|
||||
msgQueueSemId queueSemId;
|
||||
|
||||
msgQueueProtSemIdIntern(queueSemId,externId,queueIdx);
|
||||
if (DEBUG) {
|
||||
printf("Locking %s\n", queueSemId);
|
||||
}
|
||||
if (DEBUG) { printf("Locking %s\n",queueSemId);}
|
||||
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||
if(queueSemFd==SEM_FAILED){
|
||||
NZG_ERROR("sem_open",queueSemId);
|
||||
|
@ -24,9 +21,7 @@ int msgQueueProtLock(msgSpaceId externId, int queueIdx)
|
|||
}
|
||||
semval=0;
|
||||
sem_getvalue(queueSemFd,&semval);
|
||||
if (DEBUG) {
|
||||
printf("(AfterValue:%d)\n", semval);
|
||||
}
|
||||
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||
|
||||
sem_close(queueSemFd);
|
||||
sem_close(queueSemFd);
|
||||
|
@ -35,3 +30,4 @@ int msgQueueProtLock(msgSpaceId externId, int queueIdx)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,16 +3,13 @@
|
|||
|
||||
#define DEBUG 0
|
||||
|
||||
int msgQueueProtUnlock(msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueProtUnlock(msgSpaceId externId,int queueIdx){
|
||||
int semval;
|
||||
sem_t * queueSemFd;
|
||||
msgQueueSemId queueSemId;
|
||||
|
||||
msgQueueProtSemIdIntern(queueSemId,externId,queueIdx);
|
||||
if (DEBUG) {
|
||||
printf("Unlocking %s\n", queueSemId);
|
||||
}
|
||||
if (DEBUG) { printf("Unlocking %s\n",queueSemId); }
|
||||
|
||||
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||
if(queueSemFd==SEM_FAILED){
|
||||
|
@ -26,9 +23,7 @@ int msgQueueProtUnlock(msgSpaceId externId, int queueIdx)
|
|||
}
|
||||
semval=0;
|
||||
sem_getvalue(queueSemFd,&semval);
|
||||
if (DEBUG) {
|
||||
printf("(AfterValue:%d)\n", semval);
|
||||
}
|
||||
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||
|
||||
sem_close(queueSemFd);
|
||||
|
||||
|
@ -36,3 +31,4 @@ int msgQueueProtUnlock(msgSpaceId externId, int queueIdx)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,16 +3,13 @@
|
|||
|
||||
#define DEBUG 0
|
||||
|
||||
int msgQueueReadLock(msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueReadLock(msgSpaceId externId,int queueIdx){
|
||||
int semval;
|
||||
sem_t * queueSemFd;
|
||||
msgQueueSemId queueSemId;
|
||||
|
||||
msgQueueReadSemIdIntern(queueSemId,externId,queueIdx);
|
||||
if (DEBUG) {
|
||||
printf("Locking %s\n", queueSemId);
|
||||
}
|
||||
if (DEBUG) { printf("Locking %s\n",queueSemId); }
|
||||
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||
if(queueSemFd==SEM_FAILED){
|
||||
NZG_ERROR("sem_open",queueSemId);
|
||||
|
@ -25,9 +22,7 @@ int msgQueueReadLock(msgSpaceId externId, int queueIdx)
|
|||
}
|
||||
semval=0;
|
||||
sem_getvalue(queueSemFd,&semval);
|
||||
if (DEBUG) {
|
||||
printf("(AfterValue:%d)\n", semval);
|
||||
}
|
||||
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||
|
||||
sem_close(queueSemFd);
|
||||
|
||||
|
@ -35,3 +30,4 @@ int msgQueueReadLock(msgSpaceId externId, int queueIdx)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#define DEBUG 0
|
||||
|
||||
int msgQueueReadTryLock(msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueReadTryLock(msgSpaceId externId,int queueIdx){
|
||||
int semval;
|
||||
sem_t * queueSemFd;
|
||||
msgQueueSemId queueSemId;
|
||||
|
@ -20,14 +19,10 @@ int msgQueueReadTryLock(msgSpaceId externId, int queueIdx)
|
|||
NZG_ERROR("sem_wait",queueSemId);
|
||||
goto ERROR;
|
||||
}
|
||||
if (DEBUG) {
|
||||
printf("Locking %s\n", queueSemId);
|
||||
}
|
||||
if (DEBUG) { printf("Locking %s\n",queueSemId); }
|
||||
semval=0;
|
||||
sem_getvalue(queueSemFd,&semval);
|
||||
if (DEBUG) {
|
||||
printf("(AfterValue:%d)\n", semval);
|
||||
}
|
||||
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||
|
||||
sem_close(queueSemFd);
|
||||
|
||||
|
@ -35,3 +30,4 @@ int msgQueueReadTryLock(msgSpaceId externId, int queueIdx)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,16 +3,13 @@
|
|||
|
||||
#define DEBUG 0
|
||||
|
||||
int msgQueueReadUnlock(msgSpaceId externId, int queueIdx)
|
||||
{
|
||||
int msgQueueReadUnlock(msgSpaceId externId,int queueIdx){
|
||||
int semval;
|
||||
sem_t * queueSemFd;
|
||||
msgQueueSemId queueSemId;
|
||||
|
||||
msgQueueReadSemIdIntern(queueSemId,externId,queueIdx);
|
||||
if (DEBUG) {
|
||||
printf("Unlocking %s\n", queueSemId);
|
||||
}
|
||||
if (DEBUG) { printf("Unlocking %s\n",queueSemId); }
|
||||
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||
if(queueSemFd==SEM_FAILED){
|
||||
NZG_ERROR("sem_open",queueSemId);
|
||||
|
@ -25,9 +22,8 @@ int msgQueueReadUnlock(msgSpaceId externId, int queueIdx)
|
|||
}
|
||||
semval=0;
|
||||
sem_getvalue(queueSemFd,&semval);
|
||||
if (DEBUG) {
|
||||
printf("(AfterValue:%d)\n", semval);
|
||||
}
|
||||
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||
|
||||
|
||||
sem_close(queueSemFd);
|
||||
|
||||
|
@ -35,3 +31,4 @@ int msgQueueReadUnlock(msgSpaceId externId, int queueIdx)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
// l'id de l'element enlevé vas dans oldElemId
|
||||
|
||||
int msgQueueRem(msgQueue * queue, msgQueueElemId oldElemId)
|
||||
{
|
||||
int msgQueueRem(msgQueue * queue, msgQueueElemId oldElemId){
|
||||
msgQueueElem * queueOldHeadElem;
|
||||
|
||||
|
||||
if (strcmp(queue->headId,queue->id)==0){
|
||||
NZG_ERROR("msgQueueElemRem : Empty queue",queue->id);
|
||||
goto ERROR;
|
||||
|
@ -17,6 +17,7 @@ int msgQueueRem(msgQueue * queue, msgQueueElemId oldElemId)
|
|||
NZG_ERROR("msgQueueElemOpen",oldElemId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
// on indique à la queue le nouveau premier element
|
||||
strcpy(queue->headId,queueOldHeadElem->next);
|
||||
if (strcmp(queueOldHeadElem->next,oldElemId)==0){
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
int msgSpaceClose(msgSpace * space)
|
||||
{
|
||||
int msgSpaceClose(msgSpace * space){
|
||||
msgSpaceId spaceId;
|
||||
strcpy(spaceId,space->id);
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
/* prototypes des fonctions annexes à ne pas exporter */
|
||||
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
||||
const msgSpaceId externId);
|
||||
int msgPoolDataTabSemIdIntern(
|
||||
msgPoolSemId destSemId,const msgSpaceId externId);
|
||||
/*
|
||||
* spaceId : identifiant externe de l'espace de msg
|
||||
* queueNb : nombre de files de messages
|
||||
|
@ -13,9 +13,11 @@ int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
|||
* queueNbCar : tableau de caracteristiques des different pool
|
||||
*/
|
||||
|
||||
msgSpace *msgSpaceCreate(msgSpaceId externId,
|
||||
int queueNb, int poolNb, msgPool * poolInfos)
|
||||
{
|
||||
msgSpace * msgSpaceCreate(
|
||||
msgSpaceId externId,
|
||||
int queueNb,
|
||||
int poolNb,
|
||||
msgPool * poolInfos ){
|
||||
msgSpaceId nzgId;
|
||||
/* msgSpaceList mSList; */
|
||||
int mSFd; // shm file descriptor
|
||||
|
@ -70,9 +72,11 @@ msgSpace *msgSpaceCreate(msgSpaceId externId,
|
|||
printf("spaceListUnlock ok\n");
|
||||
|
||||
fprintf(stderr,"Creating msgSpace with id : %s\n",nzgId);
|
||||
mSFd = shm_open(nzgId,
|
||||
mSFd=shm_open(
|
||||
nzgId,
|
||||
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||
MSGSPACE_DEFAULT_MODE);
|
||||
MSGSPACE_DEFAULT_MODE
|
||||
);
|
||||
if (mSFd == -1 ) {
|
||||
NZG_ERROR("shm_open : msgSpace creation",nzgId);
|
||||
goto ERROR;
|
||||
|
@ -86,14 +90,14 @@ msgSpace *msgSpaceCreate(msgSpaceId externId,
|
|||
|
||||
/* Map the memory object */
|
||||
space = mmap( 0, sizeof( *space ),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, mSFd, 0);
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, mSFd, 0 );
|
||||
if( space == MAP_FAILED ) {
|
||||
NZG_ERROR("mmap",nzgId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
printf("CREAT: msgSpace mapped to 0x%08lx in %d\n", (long)space,
|
||||
(int)getpid());
|
||||
printf( "CREAT: msgSpace mapped to 0x%08x in %d\n", (int)space,(int)getpid());
|
||||
|
||||
/* on ferme le descripteur du fichier */
|
||||
close(mSFd);
|
||||
|
@ -138,18 +142,14 @@ msgSpace *msgSpaceCreate(msgSpaceId externId,
|
|||
poolDataTabAddr[i].bufferSize=poolInfos[i].bufferSize;
|
||||
poolDataTabAddr[i].allocDispBuffer=0;
|
||||
|
||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId, externId, i) ==
|
||||
-1) {
|
||||
fprintf(stderr,
|
||||
"msgBufferInfoTabId creation failed for id %s\n",
|
||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId,externId,i) == -1){
|
||||
fprintf( stderr, "msgBufferInfoTabId creation failed for id %s\n",
|
||||
(char*)poolId );
|
||||
return NULL;
|
||||
}
|
||||
strcpy(poolDataTabAddr[i].bufferInfoTabId,bufferInfoTabId);
|
||||
printf("buffIfoTab %d name : %s\n", i,
|
||||
poolDataTabAddr[i].bufferInfoTabId);
|
||||
msgBufferInfoTabCreate(externId, poolDataTabAddr, i,
|
||||
poolInfos[i].bufferNb);
|
||||
printf("buffIfoTab %d name : %s\n",i,poolDataTabAddr[i].bufferInfoTabId);
|
||||
msgBufferInfoTabCreate(externId,poolDataTabAddr,i,poolInfos[i].bufferNb);
|
||||
|
||||
if (msgPoolIdIntern(poolId,externId,i) == -1){
|
||||
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
||||
|
@ -157,20 +157,17 @@ msgSpace *msgSpaceCreate(msgSpaceId externId,
|
|||
return NULL;
|
||||
}
|
||||
strcpy(poolDataTabAddr[i].poolId,poolId);
|
||||
msgPoolCreate(externId, i, poolInfos[i].bufferNb,
|
||||
poolInfos[i].bufferSize);
|
||||
msgPoolCreate(externId,i,poolInfos[i].bufferNb,poolInfos[i].bufferSize);
|
||||
|
||||
}
|
||||
|
||||
/* on crée queueNb files de messages */
|
||||
printf("Creating queues:\n");
|
||||
for (i=0; i<queueNb;i++){
|
||||
printf("- queue %i...", i);
|
||||
fflush(stdout);
|
||||
printf("- queue %i...",i); fflush(stdout);
|
||||
if (msgQueueInit(space->externId,i) < 0){
|
||||
printf("fail.\n");
|
||||
NZG_ERROR("msgQueueInit : queue ?? for",
|
||||
space->externId);
|
||||
NZG_ERROR("msgQueueInit : queue ?? for",space->externId);
|
||||
goto ERROR;
|
||||
}
|
||||
printf("ok.\n");
|
||||
|
@ -195,3 +192,6 @@ msgSpace *msgSpaceCreate(msgSpaceId externId,
|
|||
ERROR:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
/* prototypes des fonctions annexes à ne pas exporter */
|
||||
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
||||
const msgSpaceId externId);
|
||||
int msgPoolDataTabSemIdIntern(
|
||||
msgPoolSemId destSemId,const msgSpaceId externId);
|
||||
|
||||
int msgSpaceDelete(msgSpaceId externId)
|
||||
{
|
||||
int msgSpaceDelete(msgSpaceId externId){
|
||||
//int shmId;
|
||||
msgSpaceId nzgId;
|
||||
msgSpace * space;
|
||||
|
@ -65,3 +64,4 @@ int msgSpaceDelete(msgSpaceId externId)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
// ajoute un element en début de liste.
|
||||
// fait pointer l'ancien dernier vers lui
|
||||
// il s'enregistre en tant que dernier chez la liste
|
||||
int msgSpaceListAdd(msgSpaceListElemId newElemId)
|
||||
{
|
||||
int msgSpaceListAdd(msgSpaceListElemId newElemId){
|
||||
msgSpaceListElem * listOldTailElem;
|
||||
msgSpaceListElem * listNewTailElem;
|
||||
msgSpaceList * list;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgSpaceListClose(msgSpaceList * list)
|
||||
{
|
||||
int msgSpaceListClose(msgSpaceList * list){
|
||||
|
||||
msgSpaceListId spaceListId;
|
||||
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
#include "ids.h"
|
||||
|
||||
// cree un nouvel elemen
|
||||
int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace * space)
|
||||
int msgSpaceListElemCreate(
|
||||
msgSpaceListElemId listElemId,
|
||||
msgSpace * space)
|
||||
{
|
||||
|
||||
int listElemFd;
|
||||
|
@ -33,7 +35,9 @@ int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace * space)
|
|||
strcpy(listElem->next,listElemId);
|
||||
strcpy(listElem->spaceId,space->id);
|
||||
printf("[ ListElem : id %s,next: %s, Sid: %s ]\n",
|
||||
listElem->id, listElem->next, listElem->spaceId);
|
||||
listElem->id,
|
||||
listElem->next,
|
||||
listElem->spaceId);
|
||||
if (msgSpaceListElemClose(listElem) <0){
|
||||
NZG_ERROR("msgSpaceListElemClose",listElemId);
|
||||
}
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
|
||||
// modifie l'element suivant de l'element choisi
|
||||
// et le fait pointer sur un nouvel ID
|
||||
int msgSpaceListElemLinkNext(msgSpaceListElemId current,
|
||||
msgSpaceListElemId next);
|
||||
int msgSpaceListElemLinkNext(msgSpaceListElemId current,msgSpaceListElemId next);
|
||||
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
#include "ids.h"
|
||||
|
||||
// cree un nouvel elemen
|
||||
void *msgSpaceListElemOpen(msgSpaceListElemId listElemId)
|
||||
{
|
||||
void * msgSpaceListElemOpen(msgSpaceListElemId listElemId){
|
||||
int listElemFd;
|
||||
void * listElemAddr;
|
||||
|
||||
|
@ -15,7 +14,10 @@ void *msgSpaceListElemOpen(msgSpaceListElemId listElemId)
|
|||
|
||||
listElemAddr=mmap(NULL,
|
||||
sizeof(msgQueueElem),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, listElemFd, 0);
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
listElemFd,
|
||||
0);
|
||||
|
||||
if( listElemAddr == MAP_FAILED ) {
|
||||
NZG_ERROR("mmap",listElemId);
|
||||
|
@ -27,4 +29,5 @@ void *msgSpaceListElemOpen(msgSpaceListElemId listElemId)
|
|||
ERROR:
|
||||
return NULL;
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
#define DEBUG 1
|
||||
|
||||
int msgSpaceListFindId(msgSpaceId externId)
|
||||
{
|
||||
int msgSpaceListFindId(msgSpaceId externId){
|
||||
msgSpaceList * list;
|
||||
msgSpaceId spaceId;
|
||||
msgSpaceListElemId listHeadElemId;
|
||||
|
@ -16,21 +15,15 @@ int msgSpaceListFindId(msgSpaceId externId)
|
|||
NZG_ERROR("msgSpaceListOpen","");
|
||||
goto ERROR;
|
||||
}
|
||||
if (DEBUG) {
|
||||
printf("Before ListStrCpy\n");
|
||||
}
|
||||
if (DEBUG) { printf("Before ListStrCpy\n"); }
|
||||
strcpy(listHeadElemId,list->headId);
|
||||
strcpy(listTailElemId,list->tailId);
|
||||
strcpy(listId,list->id);
|
||||
if (DEBUG) {
|
||||
printf("After ListStrCpy\n");
|
||||
}
|
||||
if (DEBUG) { printf("After ListStrCpy\n"); }
|
||||
if ((strcmp(listHeadElemId,listId)==0)
|
||||
&& strcmp(listTailElemId,listId)==0){
|
||||
// si la liste est vide
|
||||
if (DEBUG) {
|
||||
printf("SpaceList : vide\n");
|
||||
}
|
||||
if (DEBUG) { printf("SpaceList : vide\n"); }
|
||||
return 1;
|
||||
} else {
|
||||
return msgSpaceListElemFindId(listHeadElemId,spaceId);
|
||||
|
@ -44,8 +37,7 @@ int msgSpaceListFindId(msgSpaceId externId)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int msgSpaceListElemFindId(msgSpaceListElemId elemId, msgSpaceId spaceId)
|
||||
{
|
||||
int msgSpaceListElemFindId(msgSpaceListElemId elemId,msgSpaceId spaceId){
|
||||
msgSpaceListElem * listElem;
|
||||
msgSpaceListElemId listElemIdNext;
|
||||
msgSpaceId currentElemSpaceId;
|
||||
|
@ -83,3 +75,5 @@ int msgSpaceListElemFindId(msgSpaceListElemId elemId, msgSpaceId spaceId)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
int msgSpaceListInit()
|
||||
{
|
||||
int msgSpaceListInit(){
|
||||
int spaceListFd;
|
||||
sem_t * spaceListSemFd;
|
||||
msgSpaceList *list;
|
||||
|
@ -23,9 +22,12 @@ int msgSpaceListInit()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*Fait un segment de memoir partager sur espace de listelement*/
|
||||
spaceListFd=shm_open(spaceListId,
|
||||
O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0666);
|
||||
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||
0666);
|
||||
if (spaceListFd == -1){
|
||||
spaceListFd=shm_open(spaceListId,O_RDWR,0666);
|
||||
if (spaceListFd == -1){
|
||||
|
@ -71,3 +73,4 @@ int msgSpaceListInit()
|
|||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
|
||||
// verouille le semaphore de la liste
|
||||
|
||||
int msgSpaceListLock()
|
||||
{
|
||||
int msgSpaceListLock(){
|
||||
sem_t * msgSpaceListSemFd;
|
||||
msgSpaceListSemId spaceListSemId;
|
||||
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
|
||||
|
@ -33,13 +33,14 @@ int msgSpaceListLock()
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// deverouille le semaphore de la liste
|
||||
int msgSpaceListUnlock()
|
||||
{
|
||||
int msgSpaceListUnlock(){
|
||||
sem_t * msgSpaceListSemFd;
|
||||
msgSpaceListSemId spaceListSemId;
|
||||
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
|
||||
|
||||
|
||||
/*Ouverture dun semaphore*/
|
||||
msgSpaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,0);
|
||||
if(msgSpaceListSemFd==SEM_FAILED){
|
||||
|
@ -47,12 +48,14 @@ int msgSpaceListUnlock()
|
|||
goto ERROR;
|
||||
}
|
||||
|
||||
|
||||
/*Relachement du semaphore*/
|
||||
if(sem_post(msgSpaceListSemFd)==-1){
|
||||
NZG_ERROR("sem_relache",spaceListSemId);
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Ferme le semaphore */
|
||||
if(sem_close(msgSpaceListSemFd)==-1){
|
||||
NZG_ERROR("sem_close",spaceListSemId);
|
||||
|
@ -63,3 +66,4 @@ int msgSpaceListUnlock()
|
|||
ERROR:
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "libnazgul.h"
|
||||
#include "ids.h"
|
||||
|
||||
void *msgSpaceListOpen()
|
||||
{
|
||||
void * msgSpaceListOpen(){
|
||||
int listFd;
|
||||
void * listAddr;
|
||||
|
||||
|
@ -17,7 +16,10 @@ void *msgSpaceListOpen()
|
|||
|
||||
listAddr=mmap(NULL,
|
||||
sizeof(msgSpaceList),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, listFd, 0);
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
listFd,
|
||||
0);
|
||||
if( listAddr == MAP_FAILED ) {
|
||||
NZG_ERROR("mmap",spaceListId);
|
||||
goto ERROR;
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
#define DEBUG 1
|
||||
|
||||
int msgSpaceListRem(msgSpaceId spaceId)
|
||||
{
|
||||
int msgSpaceListRem(msgSpaceId spaceId){
|
||||
msgSpaceList * list;
|
||||
msgSpaceListElemId listHeadElemId;
|
||||
msgSpaceListElemId listTailElemId;
|
||||
|
@ -22,20 +21,14 @@ int msgSpaceListRem(msgSpaceId spaceId)
|
|||
NZG_ERROR("msgSpaceListOpen","");
|
||||
goto ERROR;
|
||||
}
|
||||
if (DEBUG) {
|
||||
printf("Before ListStrCpy\n");
|
||||
}
|
||||
if (DEBUG) { printf("Before ListStrCpy\n"); }
|
||||
strcpy(listHeadElemId,list->headId);
|
||||
strcpy(listTailElemId,list->tailId);
|
||||
strcpy(listId,list->id);
|
||||
if (DEBUG) {
|
||||
printf("After ListStrCpy\n");
|
||||
}
|
||||
if (DEBUG) { printf("After ListStrCpy\n"); }
|
||||
if ((strcmp(listHeadElemId,listId)==0)
|
||||
&& strcmp(listTailElemId,listId)==0){
|
||||
if (DEBUG) {
|
||||
printf("SpaceList : vide\n");
|
||||
}
|
||||
if (DEBUG) { printf("SpaceList : vide\n"); }
|
||||
return 1;
|
||||
} else {
|
||||
bool found=false;
|
||||
|
@ -74,34 +67,22 @@ int msgSpaceListRem(msgSpaceId spaceId)
|
|||
if (strcmp(prevElemId,currElemId)==0){
|
||||
// si on est en début de liste (prev=current)
|
||||
// - la tete de liste pointe sur le suivant
|
||||
strcpy(list->headId,
|
||||
nextElemId);
|
||||
strcpy(list->headId,nextElemId);
|
||||
} else {
|
||||
if (strcmp
|
||||
(currElemId,
|
||||
nextElemId) == 0) {
|
||||
if (strcmp(currElemId,nextElemId)==0){
|
||||
// si on est en find de liste (current=next)
|
||||
// - on fait pointer la queue de liste sur le précédent
|
||||
strcpy(list->tailId,
|
||||
prevElemId);
|
||||
strcpy(list->tailId,prevElemId);
|
||||
// - on fait pointer le précédent sur lui-meme
|
||||
prevElem =
|
||||
msgSpaceListElemOpen
|
||||
(prevElemId);
|
||||
strcpy(prevElem->next,
|
||||
prevElemId);
|
||||
msgSpaceListElemClose
|
||||
(prevElem);
|
||||
prevElem=msgSpaceListElemOpen(prevElemId);
|
||||
strcpy(prevElem->next,prevElemId);
|
||||
msgSpaceListElemClose(prevElem);
|
||||
}else {
|
||||
// on est en milieu de liste
|
||||
// - on fait pointer le précédent sur le suivant
|
||||
prevElem =
|
||||
msgSpaceListElemOpen
|
||||
(prevElemId);
|
||||
strcpy(prevElem->next,
|
||||
nextElemId);
|
||||
msgSpaceListElemClose
|
||||
(prevElem);
|
||||
prevElem=msgSpaceListElemOpen(prevElemId);
|
||||
strcpy(prevElem->next,nextElemId);
|
||||
msgSpaceListElemClose(prevElem);
|
||||
}
|
||||
}
|
||||
// - on détruit l'actuel
|
||||
|
@ -126,3 +107,4 @@ int msgSpaceListRem(msgSpaceId spaceId)
|
|||
ERROR:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||
|
||||
msgSpace *msgSpaceOpen(msgSpaceId externId)
|
||||
{
|
||||
|
||||
msgSpace * msgSpaceOpen(msgSpaceId externId){
|
||||
int shmFd;
|
||||
msgSpaceId nzgId;
|
||||
msgSpace * mSAddr;
|
||||
|
@ -17,11 +17,10 @@ msgSpace *msgSpaceOpen(msgSpaceId externId)
|
|||
perror("shm_open");
|
||||
return NULL;
|
||||
}
|
||||
mSAddr =
|
||||
mmap(NULL, sizeof(msgSpace), PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
shmFd, (off_t) 0);
|
||||
mSAddr=mmap(NULL,sizeof(msgSpace),PROT_READ|PROT_WRITE,MAP_SHARED,shmFd,(off_t)0);
|
||||
|
||||
printf("OPEN: msgSpace mapped to %p in %d\n", (void *)mSAddr,
|
||||
(int)getpid());
|
||||
printf( "OPEN: msgSpace mapped to 0x%08x in %d\n", (int)mSAddr,(int)getpid());
|
||||
return mSAddr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
#include "libnazgul.h"
|
||||
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
#include "libnazgul.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
// msgSpace mS=0;
|
||||
|
||||
pid_t pid;
|
||||
|
@ -36,6 +35,8 @@ int main(void)
|
|||
|
||||
pid=fork();
|
||||
|
||||
|
||||
|
||||
if (pid ==0){
|
||||
mSPAC=msgSpaceOpen(testId);
|
||||
sleep(5);
|
||||
|
|
|
@ -6,13 +6,11 @@
|
|||
|
||||
#include "libnazgul.h"
|
||||
|
||||
void usage(char *myname)
|
||||
{
|
||||
void usage(char * myname){
|
||||
printf("Usage: %s [--all | msgSpaceId1 msgSpaceId2 ... ]\n",myname);
|
||||
}
|
||||
|
||||
int about(char *spaceId)
|
||||
{
|
||||
int about(char * spaceId){
|
||||
msgPoolDataTabSemId ressourceSemId;
|
||||
sem_t * ressourceSemFd;
|
||||
int i;
|
||||
|
@ -35,35 +33,27 @@ int about(char *spaceId)
|
|||
// on lit les informations sur le msgSpace
|
||||
// les pool
|
||||
for (i=0;i<space->poolNb;i++){
|
||||
msgPoolSemIdIntern(ressourceSemId,
|
||||
space->externId, i);
|
||||
ressourceSemFd =
|
||||
sem_open(ressourceSemId, O_CREAT,
|
||||
SEM_DEFAULT_MODE, 0);
|
||||
msgPoolSemIdIntern(ressourceSemId,space->externId,i);
|
||||
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||
if (ressourceSemFd == SEM_FAILED){
|
||||
NZG_ERROR("sem_open",
|
||||
ressourceSemId);
|
||||
NZG_ERROR("sem_open",ressourceSemId);
|
||||
goto ERROR;
|
||||
}
|
||||
if (sem_getvalue
|
||||
(ressourceSemFd,
|
||||
&ressourceSemVal) < 0) {
|
||||
NZG_ERROR("sem_getvalue",
|
||||
ressourceSemId);
|
||||
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
|
||||
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||
goto ERROR;
|
||||
}
|
||||
msgPoolDataTabLock(space);
|
||||
poolDataTab= msgPoolDataTabOpen(space);
|
||||
// donner le nombre de buffer disponibles
|
||||
printf
|
||||
("- %d/%d free buffers in pool #%d\n",
|
||||
printf("- %d/%d free buffers in pool #%d\n",
|
||||
ressourceSemVal,
|
||||
poolDataTab[i].bufferNb, i);
|
||||
poolDataTab[i].bufferNb,
|
||||
i);
|
||||
msgPoolDataTabClose(space,poolDataTab);
|
||||
msgPoolDataTabUnlock(space);
|
||||
if(sem_close(ressourceSemFd) <0){
|
||||
NZG_ERROR("sem_getvalue",
|
||||
ressourceSemId);
|
||||
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||
goto ERROR;
|
||||
}
|
||||
// pour chaque buffer, dire s'il est libre ou pas
|
||||
|
@ -84,8 +74,7 @@ int about(char *spaceId)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc,char **argv){
|
||||
printf("Args %d\n",argc);
|
||||
if (argc<2){
|
||||
usage(argv[0]);
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
#include "libnazgul.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
// msgSpace mS=0;
|
||||
|
||||
msgSpaceId testId;
|
||||
|
@ -39,13 +38,12 @@ int main(void)
|
|||
montext=msgAllocate(mSPAC,1,280,0);
|
||||
*montext=42;
|
||||
printf("### test Valeur0 %d ###\n",(int)*montext);
|
||||
printf("Put...");
|
||||
fflush(stdout);
|
||||
printf("Put..."); fflush(stdout);
|
||||
msgPut(mSPAC,0,montext);
|
||||
printf("put-ok\n");
|
||||
|
||||
printf("Get...");
|
||||
fflush(stdout);
|
||||
|
||||
printf("Get..."); fflush(stdout);
|
||||
montext=msgGet(mSPAC,0,0);
|
||||
printf("get-ok\n");
|
||||
printf("### test Reception %d ###\n",(int)*montext);
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
#include "libnazgul.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
// msgSpace mS=0;
|
||||
|
||||
msgSpaceId testId;
|
||||
|
@ -39,14 +38,12 @@ int main(void)
|
|||
montext=msgAllocate(mSPAC,1,280,0);
|
||||
*montext=42;
|
||||
printf("### test Valeur0 %d ###\n",(int)*montext);
|
||||
printf("Put1...");
|
||||
fflush(stdout);
|
||||
printf("Put1..."); fflush(stdout);
|
||||
msgPut(mSPAC,0,montext);
|
||||
printf("put1-ok\n");
|
||||
} else {
|
||||
mSPAC=msgSpaceOpen(testId);
|
||||
printf("Get...");
|
||||
fflush(stdout);
|
||||
printf("Get..."); fflush(stdout);
|
||||
montext=msgGet(mSPAC,0,0);
|
||||
printf("get-ok\n");
|
||||
printf("### test Reception %d ###\n",(int)*montext);
|
||||
|
|
Loading…
Add table
Reference in a new issue