Continue msgSpace naming

This commit is contained in:
Glenn Y. Rolland 2019-09-17 14:17:58 +02:00
parent 665cb90dd6
commit 4b9ddb3187
4 changed files with 79 additions and 47 deletions

View file

@ -11,5 +11,7 @@
#include <errno.h> #include <errno.h>
#define PAGESIZE sysconf(_SC_PAGESIZE) #define PAGESIZE sysconf(_SC_PAGESIZE)
#define MSGSPACE_DEFAULT_MODE 0600
#define MSGSPACE_ID_LEN 32
#endif #endif

View file

@ -1,11 +1,7 @@
#ifndef _NZG_IFACE #ifndef _NZG_IFACE
#define _NZG_IFACE 1 #define _NZG_IFACE 1
#include "nzg_global.h" #include "nzg_global.h"
#define MSGSPACE_DEFAULT_MODE 0600
#define MSGSPACE_ID_LEN 32
typedef char msgSpaceId[MSGSPACE_ID_LEN]; typedef char msgSpaceId[MSGSPACE_ID_LEN];
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN]; typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
@ -19,12 +15,17 @@ typedef char msgSpaceQueueId[4*MSGSPACE_ID_LEN];
/* pid[] */ /* pid[] */
/* liste des processus demandeurs */ /* liste des processus demandeurs */
typedef struct MsgPool { typedef struct MsgPool {
int bufferSize;
int bufferNb;
} msgPool;
typedef struct MsgPoolData {
msgSpacePoolId id; msgSpacePoolId id;
int bufferNb; int bufferNb;
int bufferSize; int bufferSize;
int allocDispBuffer; int allocDispBuffer;
int allocOverload; int allocOverload;
} msgPool; } msgPoolData;
/* TODO: queueId */ /* TODO: queueId */

View file

@ -55,9 +55,17 @@ int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest,msgSpacePoolId src, int num){
// //donne l'adr en mappant in the memory // //donne l'adr en mappant in the memory
//poolAddr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, poolFd, 0); //poolAddr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, poolFd, 0);
msgPool * msgPoolAllocate(int poolFd, msgSpace *msg) { msgPool * msgPoolAllocate(int poolIdx, msgSpace *msg) {
msgPool * poolAddr; msgPool * poolAddr;
int dataId; int dataId;
// TODO:récupérer l'id du poolData dans le msgSpace
// détacher le morceau de mémoire du processus
// TODO:récupérer le poolData qui correspond à notre poolIdx.
// attacher la zone mémoire correspondant à l'Id
// utiliser des sémaphores pour vérouiller les acces en modif
// sur la poolData de notre
//msgSpacePoolData spoolData; //msgSpacePoolData spoolData;
//dataId = msg->poolDataId; //dataId = msg->poolDataId;

View file

@ -1,7 +1,11 @@
#include "libnazgul.h" #include "libnazgul.h"
/* prototypes des fonctions annexes à ne pas exporter */ /* prototypes des f#define MSGSPACE_DEFAULT_MODE 0600
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src ); #define MSGSPACE_ID_LEN 32
onctions annexes à ne pas exporter */
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
/* /*
* spaceId : identifiant externe de l'espace de msg * spaceId : identifiant externe de l'espace de msg
@ -18,17 +22,20 @@ msgSpace * msgSpaceCreate(
msgSpaceId nzgId; msgSpaceId nzgId;
/* msgSpaceList mSList; */ /* msgSpaceList mSList; */
int mSFd; // shm file descriptor int mSFd; // shm file descriptor
int mSPoolDataFd; // shm file descriptor
int i; int i;
static int mSIdNum=-1; static int mSIdNum=-1;
msgSpace * mSAddr; msgSpace * mSAddr;
msgSpacePoolId poolDataId;
msgPoolData * mSPoolDataAddr;
fprintf(stderr,"Creating msgSpace with id : %s\n",spaceId); fprintf(stderr,"Creating msgSpace with id : %s\n",spaceId);
mSIdNum++; mSIdNum++;
mSAddr=NULL; mSAddr=NULL;
/** recuperation de la liste des msgSpace **/ /** recuperation de la liste des msgSpace **/
/* (creation si elle n'existe pas */ /* (creation si elle n'existe pas */
/** on créee le nouvel element **/ /** on créee le nouvel element **/
printf("PAGESIZE : %d\n",(int)PAGESIZE); printf("PAGESIZE : %d\n",(int)PAGESIZE);
@ -43,7 +50,7 @@ msgSpace * msgSpaceCreate(
); );
if (mSFd == -1 ) { if (mSFd == -1 ) {
fprintf( stderr, "msgSpace %s creation failed: %s\n", fprintf( stderr, "msgSpace %s creation failed: %s\n",
(char*)nzgId, (char*)nzgId,
strerror( errno ) ); strerror( errno ) );
return NULL; return NULL;
} }
@ -57,43 +64,57 @@ msgSpace * msgSpaceCreate(
/* Map the memory object */ /* Map the memory object */
mSAddr = mmap( 0, sizeof( *mSAddr ), mSAddr = mmap( 0, sizeof( *mSAddr ),
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED, mSFd, 0 ); MAP_SHARED, mSFd, 0 );
if( mSAddr == MAP_FAILED ) { if( mSAddr == MAP_FAILED ) {
fprintf( stderr, "mmap failed: %s\n", fprintf( stderr, "mmap failed: %s\n",
strerror( errno ) ); strerror( errno ) );
return NULL; return NULL;
} }
printf( "Map addr is 0x%08x\n", (int)mSAddr ); printf( "Map addr is 0x%08x\n", (int)mSAddr );
/* on ferme le descripteur du fichier */ /* on ferme le descripteur du fichier */
close(mSFd); close(mSFd);
/* on remplit la structure */ /* on remplit la structure */
strncpy(mSAddr->id,nzgId,MSGSPACE_ID_LEN); strncpy(mSAddr->id,nzgId,MSGSPACE_ID_LEN);
mSAddr->poolNb=poolNb; mSAddr->poolNb=poolNb;
mSAddr->queueNb=queueNb; mSAddr->queueNb=queueNb;
mSAddr->pid=getpid(); mSAddr->pid=getpid();
/* TODO: creation du poolData */ /* creation du poolData */
msgPoolDataIdIntern(poolDataId,spaceId);
/* TODO: on ajoute spaceId a la liste des msgSpace connus */ mSPoolDataFd=shm_open(
poolDataId,
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
MSGSPACE_DEFAULT_MODE
);
if (mSPoolDataFd == -1 ) {
fprintf( stderr, "poolData %s creation failed: %s\n",
(char*)poolDataId,
strerror( errno ) );
return NULL;
}
/* TODO:allocation de la bonne zone mémoire pour le poolData */
/* TODO: on crée queueNb files de messages */ /* TODO: on ajoute spaceId a la liste des msgSpace connus */
/* on créer poolNb pool de buffers */ /* TODO: on crée queueNb files de messages */
/* et on "attache" tout ce beau monde au spaceId */
for (i=0;i<poolNb;i++){
// creation d'une pool
// mSAddr-> /* on créer poolNb pool de buffers */
/* et on "attache" tout ce beau monde au spaceId */
for (i=0;i<poolNb;i++){
// creation d'une pool
} // mSAddr->
}
/* on renvoie un pointeur sur le bon spaceId */ /* on renvoie un pointeur sur le bon spaceId */
return mSAddr; return mSAddr;
} }
@ -121,7 +142,7 @@ int msgSpaceDelete(msgSpaceId spaceId){
if (msgSpaceIdIntern(nzgId,spaceId) == -1){ if (msgSpaceIdIntern(nzgId,spaceId) == -1){
//TODO: message d'erreur //TODO: message d'erreur
return -1; return -1;
} }
if (shm_unlink(nzgId)<0){ if (shm_unlink(nzgId)<0){
perror("shm_unlink"); perror("shm_unlink");
@ -143,7 +164,7 @@ int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src ){
return 0; return 0;
} }
int msgSpacePoolDataIdIntern(msgSpaceId dest,const msgSpaceId src ){ int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src ){
if (strlen(src)>MSGSPACE_ID_LEN){ if (strlen(src)>MSGSPACE_ID_LEN){
return -1; return -1;
} }