l3.libnazgul/src/nzg_spaces.c

88 lines
1.8 KiB
C
Raw Normal View History

2020-03-03 22:41:24 +00:00
#include "nzg_global.h"
2004-02-16 21:25:11 +00:00
#include "nzg_iface.h"
#include "nzg_proto.h"
2020-03-03 22:41:24 +00:00
#include <sys/types.h>
#include <sys/mman.h>
2004-02-16 21:25:11 +00:00
/*
* spaceId : identifiant externe de l'espace de msg
* queueNb : nombre de files de messages
* poolNb : nombre de pool de buffers
* queueNbCar : tableau de caracteristiques des different pool
*/
msgSpace * msgSpaceCreate(
msgSpaceId spaceId,
int queueNb,
int poolNb,
msgPool * queueNbCar ){
msgSpace * result;
2019-09-16 14:54:52 +00:00
int shmId;
msgSpaceId nzgId;
2019-09-16 15:17:43 +00:00
msgSpaceList mSList;
static int mSIdNum=-1;
2019-09-16 15:15:37 +00:00
2019-09-16 15:17:43 +00:00
mSIdNum++;
2019-09-16 15:15:37 +00:00
/** recuperation de la liste des msgSpace **/
/* (creation si elle n'existe pas */
/** on cr<63>ee le nouvel element **/
2020-03-03 22:42:59 +00:00
printf("PAGESIZE : %d\n",(int)PAGESIZE);
nzgId=msgSp2nzgId(spaceId);
2019-09-16 15:15:37 +00:00
shmId=shm_open(
nzgId,
O_RDWR|O_CREAT|O_EXCL,
MSGSPACE_DEFAULT_MODE
);
if (shmId < 0 ) {
2020-03-03 22:42:59 +00:00
perror("shm_open");
return NULL;
}
2004-02-16 21:25:11 +00:00
/* on ajoute spaceId a la liste des msgSpace connus */
/* on cr<63>e queueNb files de messages */
/* on cr<63>er poolNb pool de buffers */
/* on attache tout ce beau monde au spaceId */
2004-02-16 21:25:11 +00:00
/* on renvoie un pointeur sur le bon spaceId */
result=NULL;
2004-02-16 21:25:11 +00:00
return result;
}
2019-09-16 15:15:37 +00:00
/*
* spaceId : blabla
*/
2020-03-03 22:42:59 +00:00
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId;
2019-09-16 14:54:52 +00:00
char * nzgId=msgSp2nzgId(spaceId);
2020-03-03 22:42:59 +00:00
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
}
2019-09-16 14:43:39 +00:00
return NULL;
}
void msgSpaceDelete(msgSpaceId spaceId){
2020-03-03 22:41:24 +00:00
//int shmId;
2019-09-16 14:54:52 +00:00
msgSpaceId nzgId=msgSp2nzgId(spaceId);
int er;
if ((er=shm_unlink(nzgId))<0){
perror("shm_unlink");
};
2019-09-16 14:43:39 +00:00
}
2019-09-16 14:54:52 +00:00
msgSpaceId msgSp2nzgId(msgSpaceId spaceId){
char * resNzgId;
int slen;
slen=strlen(spaceId);
2019-09-16 15:15:37 +00:00
resNzgId = (char *)malloc(sizeof(char)*(slen+11));
sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId);
2019-09-16 14:54:52 +00:00
return ((msgSpaceId)resNzgId);
}