Improve msgSpaceList functions

This commit is contained in:
Glenn Y. Rolland 2019-09-16 17:15:37 +02:00
parent 5290be1ae5
commit 96ab2bed39
4 changed files with 44 additions and 9 deletions

View file

@ -19,10 +19,22 @@ msgSpace * msgSpaceCreate(
msgSpace * result; msgSpace * result;
int shmId; int shmId;
msgSpaceId nzgId; msgSpaceId nzgId;
/* on créee */ msgSpaceList
static spaceIdNum=-1;
spaceIdNum++;
/** recuperation de la liste des msgSpace **/
/* (creation si elle n'existe pas */
/** on créee le nouvel element **/
printf("PAGESIZE : %d\n",(int)PAGESIZE); printf("PAGESIZE : %d\n",(int)PAGESIZE);
nzgId=msgSp2nzgId(spaceId); nzgId=msgSp2nzgId(spaceId);
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){ shmId=shm_open(
nzgId,
O_RDWR|O_CREAT|O_EXCL,
MSGSPACE_DEFAULT_MODE
);
if (shmId < 0 ) {
perror("shm_open"); perror("shm_open");
return NULL; return NULL;
} }
@ -42,6 +54,10 @@ msgSpace * msgSpaceCreate(
} }
/*
* spaceId : blabla
*/
msgSpace * msgSpaceOpen(msgSpaceId spaceId){ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId; int shmId;
char * nzgId=msgSp2nzgId(spaceId); char * nzgId=msgSp2nzgId(spaceId);
@ -65,7 +81,7 @@ msgSpaceId msgSp2nzgId(msgSpaceId spaceId){
char * resNzgId; char * resNzgId;
int slen; int slen;
slen=strlen(spaceId); slen=strlen(spaceId);
resNzgId = (char *)malloc(sizeof(char)*(slen+4)); resNzgId = (char *)malloc(sizeof(char)*(slen+11));
sprintf(resNzgId,"/NZG%s",(char *)spaceId); sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId);
return ((msgSpaceId)resNzgId); return ((msgSpaceId)resNzgId);
} }

View file

@ -1,3 +1,6 @@
#ifndef _NZG_GLOBAL
#define _NZG_GLOBAL 1
#include <unistd.h> /* POSIX et al */ #include <unistd.h> /* POSIX et al */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -7,3 +10,4 @@
#include <sys/mman.h> /* shm_open */ #include <sys/mman.h> /* shm_open */
#define PAGESIZE sysconf(_SC_PAGESIZE) #define PAGESIZE sysconf(_SC_PAGESIZE)
#endif

View file

@ -1,3 +1,7 @@
#ifndef _NZG_IFACE
#define _NZG_IFACE 1
#include "nzg_global.h" #include "nzg_global.h"
#define MSGSPACE_DEFAULT_MODE 0600 #define MSGSPACE_DEFAULT_MODE 0600
@ -12,7 +16,14 @@ typedef struct MsgSpace {
} msgSpace; } msgSpace;
typedef char * msgSpaceListElemId;
typedef struct MsgSpaceListElem {
void * id;
int ownerPid;
/* struct msgSpaceListElem * next; */
msgSpaceListElemId next;
} * msgSpaceList, msgSpaceListElem;
#endif
/* */ /* */

View file

@ -3,10 +3,14 @@
#include "nzg_proto.h" #include "nzg_proto.h"
int main(void) { int main(void) {
// msgSpace mS=0; // msgSpace mS=0;
msgSpaceId testId=(msgSpaceId)"test";
//msgSpace * mSPAC=msgSpaceCreate(testId,0,0,NULL); msgSpaceId testId;
msgSpace * mSPAC;
testId=(msgSpaceId)"test";
mSPAC=msgSpaceCreate(testId,0,0,NULL);
msgSpaceDelete(testId); msgSpaceDelete(testId);
return 0; return 0;
} }