Continue msgSpace feature implementation

This commit is contained in:
Glenn Y. Rolland 2019-09-17 14:44:44 +02:00
parent 111d3683b1
commit c7a7897184
6 changed files with 39 additions and 16 deletions

View file

@ -17,4 +17,9 @@
#define SHM_DEFAULT_MODE 0600
#define MSGSPACE_ID_LEN 32
#define ERR_UNHANDLED "Gérer mieu les erreurs"
#ifndef SEM_FAILED
#define SEM_FAILED ((sem_t *)0)
#endif
#endif

View file

@ -33,7 +33,7 @@ int msgPoolSemIdIntern(
return 0;
}
int msgPoolDataIdIntern(msgPoolDataId dest,const msgSpaceId src ){
int msgPoolDataIdIntern(msgPoolDataTabId dest,const msgSpaceId src ){
if (strlen(src)>MSGSPACE_ID_LEN){
return -1;
}

View file

@ -7,7 +7,7 @@
/* nzg_ids.c */
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx);
int msgPoolDataIdIntern(msgPoolDataId dest, const msgSpaceId src);
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
int msgSpacePoolId2nzgPoolId(msgPoolId dest, msgPoolId src, int num);

View file

@ -10,8 +10,8 @@ typedef char msgSpaceId[MSGSPACE_ID_LEN];
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN];
typedef char msgPoolDataId[4*MSGSPACE_ID_LEN];
typedef char msgPoolDataSemId[4*MSGSPACE_ID_LEN];
typedef char msgPoolDataTabId[4*MSGSPACE_ID_LEN];
typedef char msgPoolDataTabSemId[4*MSGSPACE_ID_LEN];
typedef char msgPoolId[4*MSGSPACE_ID_LEN];
typedef char msgPoolSemId[4*MSGSPACE_ID_LEN];
@ -42,8 +42,8 @@ typedef struct MsgSpace {
int poolNb;
int queueNb;
int pid;
msgPoolDataId poolDataId;
msgPoolDataSemId poolDataSemId;
msgPoolDataTabId poolDataTabId;
msgPoolDataTabSemId poolDataTabSemId;
} msgSpace;

View file

@ -1,4 +1,5 @@
# include "libnazgul.h"
#include "libnazgul.h"
#include "nzg_ids.h"
/* pid[]
liste process demandeurs */

View file

@ -28,7 +28,7 @@ msgSpace * msgSpaceCreate(
static int mSIdNum=-1;
msgSpace * mSAddr;
msgPoolId poolDataId;
msgPoolId poolDataTabId;
msgPoolData * mSPoolDataAddr;
fprintf(stderr,"Creating msgSpace with id : %s\n",spaceId);
@ -85,16 +85,17 @@ msgSpace * msgSpaceCreate(
mSAddr->pid=getpid();
/* creation du poolData */
msgPoolDataIdIntern(poolDataId,spaceId);
msgPoolDataIdIntern(poolDataTabId,spaceId);
strcpy(mSAddr->poolDataTabId,poolDataTabId);
mSPoolDataFd=shm_open(
poolDataId,
poolDataTabId,
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
MSGSPACE_DEFAULT_MODE
);
if (mSPoolDataFd == -1 ) {
fprintf( stderr, "poolData %s creation failed: %s\n",
(char*)poolDataId,
(char*)poolDataTabId,
strerror( errno ) );
return NULL;
}
@ -126,8 +127,10 @@ msgSpace * msgSpaceCreate(
mSPoolDataAddr[i].bufferNb=poolInfos[i].bufferNb;
mSPoolDataAddr[i].bufferSize=poolInfos[i].bufferSize;
mSPoolDataAddr[i].allocDispBuffer=0;
mSPoolDataAddr[i].allocOverload=false;
//TODO: remplir l'ID : mSPoolDataAddr[i].id
msgPoolId poolId;
msgPoolCreate(poolId,poolInfos[i].bufferNb,poolInfos[i].bufferSize);
strcpy(mSPoolDataAddr[i].id,poolId);
}
@ -143,27 +146,41 @@ msgSpace * msgSpaceCreate(
*/
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId;
int shmFd;
msgSpaceId nzgId;
msgSpace * mSAddr;
if (msgSpaceIdIntern(nzgId,spaceId) < 0){
return NULL;
}
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
if ((shmFd=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
}
return NULL;
mSAddr=mmap(NULL,sizeof(msgSpace),PROT_READ|PROT_WRITE,MAP_SHARED,shmFd,(off_t)0);
return mSAddr;
}
int msgSpaceDelete(msgSpaceId spaceId){
fprintf(stderr,"Deleting msgSpace with id : %s\n",spaceId);
//int shmId;
msgSpaceId nzgId;
msgSpace * space;
if (msgSpaceIdIntern(nzgId,spaceId) == -1){
//TODO: message d'erreur
return -1;
}
space = msgSpaceOpen(spaceId);
printf("openned successfully !\n");
printf("Unlinking DataTab... ");
if (shm_unlink(space->poolDataTabId) < 0){
perror("shm_unlink");
return -1;
}
printf("ok\n");
if (shm_unlink(nzgId)<0){
perror("shm_unlink");
return -1;