From a6a69bb22f55640b53b2b6a7d3a3176c57308fbe Mon Sep 17 00:00:00 2001 From: glenux Date: Thu, 26 Feb 2004 10:37:42 +0000 Subject: [PATCH] *** empty log message *** --- src/spaceClose.c | 15 +++++++ test/create_delete.c | 8 ++-- test/msgSpaceState.c | 94 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 src/spaceClose.c create mode 100644 test/msgSpaceState.c diff --git a/src/spaceClose.c b/src/spaceClose.c new file mode 100644 index 0000000..7470009 --- /dev/null +++ b/src/spaceClose.c @@ -0,0 +1,15 @@ +#include "libnazgul.h" + +int msgSpaceClose(msgSpace * space){ + msgSpaceId spaceId; + strcpy(spaceId,space->id); + + if (munmap(space,sizeof(msgSpace)) < 0){ + NZG_ERROR("unmap",spaceId); + goto ERROR; + } + + return 0; +ERROR: + return -1; +} diff --git a/test/create_delete.c b/test/create_delete.c index d0e6572..33b3aa2 100644 --- a/test/create_delete.c +++ b/test/create_delete.c @@ -33,11 +33,11 @@ int main(void) { if (pid ==0){ mSPAC=msgSpaceOpen(testId); - sleep(2); + sleep(5); montext=msgAllocate(mSPAC,2,180,0); - sleep(2); + sleep(5); montext=msgAllocate(mSPAC,2,170,0); - sleep(2); + sleep(5); montext=msgAllocate(mSPAC,2,270,0); } else { @@ -49,7 +49,7 @@ int main(void) { montext=msgAllocate(mSPAC,2,270,0); *montext=17; printf("### test Valeur1 %d ###\n",(int)*montext); - sleep(2); + sleep(5); montext=msgAllocate(mSPAC,2,270,0); msgFree(mSPAC,(void *)montext); //msgFree(mSPAC,(void *)montext); diff --git a/test/msgSpaceState.c b/test/msgSpaceState.c new file mode 100644 index 0000000..e00d730 --- /dev/null +++ b/test/msgSpaceState.c @@ -0,0 +1,94 @@ +#include +#include "libnazgul.h" + +void usage(char * myname){ + printf("Usage: %s [--all | msgSpaceId1 msgSpaceId2 ... ]\n",myname); +} + +int about(char * spaceId){ + msgPoolDataTabSemId ressourceSemId; + sem_t * ressourceSemFd; + int i; + msgPoolData * poolDataTab; + msgSpace * space; + int ressourceSemVal; + if (strlen(spaceId)> MSGSPACE_ID_LEN){ + //verif de la longueur + fprintf(stderr,"Too long ident : %s\n",spaceId); + goto ERROR; + } else { + int err; + msgSpaceListLock(); + err=msgSpaceListFindId(spaceId); + msgSpaceListUnlock(); + if (err < 1){ + if (err==0){ + // le msgSpace existe + space=msgSpaceOpen(spaceId); + // on lit les informations sur le msgSpace + // les pool + for (i=0;ipoolNb;i++){ + msgPoolSemIdIntern(ressourceSemId,space->externId,i); + ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0); + if (ressourceSemFd == SEM_FAILED){ + NZG_ERROR("sem_open",ressourceSemId); + goto ERROR; + } + if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){ + NZG_ERROR("sem_getvalue",ressourceSemId); + goto ERROR; + } + //msgPoolDataTabLock(space); + //msgPoolDataTabUnlock(space); + poolDataTab= msgPoolDataTabOpen(space); + // donner le nombre de buffer disponibles + printf("- %d/%d free buffers in pool #%d\n", + ressourceSemVal, + poolDataTab[i].bufferNb, + i); + msgPoolDataTabClose(space,poolDataTab); + if(sem_close(ressourceSemFd) <0){ + NZG_ERROR("sem_getvalue",ressourceSemId); + goto ERROR; + } + // pour chaque buffer, dire s'il est libre ou pas + // et le processus/addresse associé + } + msgSpaceClose(space); + } else { + // zut, il y a soit une erreur + NZG_ERROR("spaceListFindId : error ",spaceId); + } + // on quitte : l'element n'existe + fprintf(stderr,"Ident %s does not exist.\n",spaceId); + } + } + return 0; +ERROR: + return -1; +} + +int main(int argc,char **argv){ + printf("Args %d\n",argc); + if (argc<2){ + usage(argv[0]); + }else { + if (argc==2){ + if (strcmp("--all",argv[1])==0){ + // listing + printf("[ Listing of msgSpaces ]\n"); + } else { + // only one msgSpaceId + printf("[ About %s ]\n",argv[1]); + about(argv[1]); + } + } else { + int i; + for (i=1;i