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;
int shmId;
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);
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");
return NULL;
}
@ -42,6 +54,10 @@ msgSpace * msgSpaceCreate(
}
/*
* spaceId : blabla
*/
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId;
char * nzgId=msgSp2nzgId(spaceId);
@ -65,7 +81,7 @@ msgSpaceId msgSp2nzgId(msgSpaceId spaceId){
char * resNzgId;
int slen;
slen=strlen(spaceId);
resNzgId = (char *)malloc(sizeof(char)*(slen+4));
sprintf(resNzgId,"/NZG%s",(char *)spaceId);
resNzgId = (char *)malloc(sizeof(char)*(slen+11));
sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId);
return ((msgSpaceId)resNzgId);
}

View file

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

View file

@ -1,3 +1,7 @@
#ifndef _NZG_IFACE
#define _NZG_IFACE 1
#include "nzg_global.h"
#define MSGSPACE_DEFAULT_MODE 0600
@ -12,7 +16,14 @@ typedef struct 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"
int main(void) {
// msgSpace mS=0;
msgSpaceId testId=(msgSpaceId)"test";
//msgSpace * mSPAC=msgSpaceCreate(testId,0,0,NULL);
// msgSpace mS=0;
msgSpaceId testId;
msgSpace * mSPAC;
testId=(msgSpaceId)"test";
mSPAC=msgSpaceCreate(testId,0,0,NULL);
msgSpaceDelete(testId);
return 0;
}