Improve code

This commit is contained in:
Glenn Y. Rolland 2020-03-03 23:42:59 +01:00
parent 4f4eb5b1a2
commit f80d3d5864
6 changed files with 35 additions and 11 deletions

View file

@ -1,4 +1,10 @@
#include <unistd.h> /* POSIX et al */
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <fcntl.h> /* pour O_RDWR */
#include <sys/types.h>
#include <sys/mman.h>
#include "nzg_iface.h" #include "nzg_iface.h"
#include "nzg_proto.h" #include "nzg_proto.h"
@ -16,7 +22,20 @@ msgSpace * msgSpaceCreate(
msgPool * queueNbCar // tableau de caracteristiques des different pool msgPool * queueNbCar // tableau de caracteristiques des different pool
){ ){
printf("PAGESIZE : %d\n",(int)PAGESIZE);
// on créee // on créee
char * nzgId;
int slen;
int shmId;
slen=strlen(spaceId);
nzgId = (char *)malloc(sizeof(char)*(slen+4));
sprintf(nzgId,"/NZG%s",spaceId);
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
}
// on ajoute spaceId a la liste des msgSpace connus // on ajoute spaceId a la liste des msgSpace connus
// on crée queueNb files de messages // on crée queueNb files de messages
@ -32,7 +51,17 @@ msgSpace * msgSpaceCreate(
} }
void msgSpaceOpen(msgSpaceId){ 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);
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
}
return NULL; return NULL;
} }

3
src/nzg_global.h Normal file
View file

@ -0,0 +1,3 @@
#include <unistd.h>
#define PAGESIZE sysconf(_SC_PAGESIZE)

View file

@ -1,4 +1,5 @@
#include "types.h" #include "nzg_global.h"
#define MSGSPACE_DEFAULT_MODE 0600
typedef char * msgSpaceId; typedef char * msgSpaceId;

View file

@ -1,9 +0,0 @@
#include "nzg_iface.h"
#include "nzg_proto.h"
int main(void) {
//show existing MsgSpaces
char ** msID=msgSpaceIdList(); //renvoie un msgSpaceId
msID=msID;
return 0;
}

View file