Add base functions for msgSpace

This commit is contained in:
Glenn Y. Rolland 2019-09-16 16:54:52 +02:00
parent f80d3d5864
commit 6e40948677
2 changed files with 26 additions and 17 deletions

View file

@ -4,7 +4,7 @@
#include <string.h>
#include <fcntl.h> /* pour O_RDWR */
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/mman.h> /* shm_open */
#include "nzg_iface.h"
#include "nzg_proto.h"
@ -21,15 +21,10 @@ msgSpace * msgSpaceCreate(
int poolNb, // nombre de pool de buffers
msgPool * queueNbCar // tableau de caracteristiques des different pool
){
int shmId;
printf("PAGESIZE : %d\n",(int)PAGESIZE);
// on créee
char * nzgId;
int slen;
int shmId;
slen=strlen(spaceId);
nzgId = (char *)malloc(sizeof(char)*(slen+4));
sprintf(nzgId,"/NZG%s",spaceId);
msgSpaceId nzgId=msgSp2nzgId(spaceId);
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
@ -52,12 +47,8 @@ msgSpace * msgSpaceCreate(
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
char * nzgId;
int slen;
int shmId;
slen=strlen(spaceId);
nzgId = (char *)malloc(sizeof(char)*(slen+4));
sprintf(nzgId,"/NZG%s",spaceId);
char * nzgId=msgSp2nzgId(spaceId);
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
@ -66,7 +57,19 @@ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
}
void msgSpaceDelete(msgSpaceId spaceId){
//
int shmId;
msgSpaceId nzgId=msgSp2nzgId(spaceId);
int er;
if ((er=shm_unlink(nzgId))<0){
perror("shm_unlink");
};
}
msgSpaceId msgSp2nzgId(msgSpaceId spaceId){
char * resNzgId;
int slen;
slen=strlen(spaceId);
resNzgId = (char *)malloc(sizeof(char)*(slen+4));
sprintf(resNzgId,"/NZG%s",(char *)spaceId);
return ((msgSpaceId)resNzgId);
}

View file

@ -8,11 +8,17 @@ msgSpace * msgSpaceCreate(
msgPool * queueNbCar // tableau de caracteristiques des different pool
);
msgSpace * msgSpaceOpen(msgSpaceId spaceId);
void * msgAllocate(
msgSpace * space, //espace de message concerné
int pool, //numéro de pool ou réaliser l'allocation
int taille, //si l'argument précédent est ANYPOOL, taille requise
int option // 0 ou NONBLOCK
);
/* nzg_create.c */
msgSpace *msgSpaceCreate(msgSpaceId spaceId, int queueNb, int poolNb, msgPool *queueNbCar);
msgSpace *msgSpaceOpen(msgSpaceId spaceId);
void msgSpaceDelete(msgSpaceId spaceId);
msgSpaceId msgSp2nzgId(msgSpaceId spaceId);