* mise a jour a partir des modifications communes en TP

This commit is contained in:
glenux 2004-02-19 09:57:25 +00:00
parent 4aaef201bd
commit 9fe32cc284
6 changed files with 52 additions and 12 deletions

View file

@ -7,7 +7,7 @@
#LIBS=
CC=gcc
CFLAGS=-ggdb -Wall
CFLAGS=-ggdb -Wall -O2
#-O2
#LIBS=-lrt
#-verbose

View file

@ -19,10 +19,22 @@ msgSpace * msgSpaceCreate(
msgSpace * result;
int shmId;
msgSpaceId nzgId;
/* on créee */
msgSpaceList
static spaceIdNum=-1;
spaceIdNum++;
/** recuperation de la liste des msgSpace **/
/* (creation si elle n'existe pas */
/** on créee le nouvel element **/
printf("PAGESIZE : %d\n",(int)PAGESIZE);
nzgId=msgSp2nzgId(spaceId);
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
shmId=shm_open(
nzgId,
O_RDWR|O_CREAT|O_EXCL,
MSGSPACE_DEFAULT_MODE
);
if (shmId < 0 ) {
perror("shm_open");
return NULL;
}
@ -42,6 +54,10 @@ msgSpace * msgSpaceCreate(
}
/*
* spaceId : blabla
*/
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId;
char * nzgId=msgSp2nzgId(spaceId);
@ -65,7 +81,7 @@ msgSpaceId msgSp2nzgId(msgSpaceId spaceId){
char * resNzgId;
int slen;
slen=strlen(spaceId);
resNzgId = (char *)malloc(sizeof(char)*(slen+4));
sprintf(resNzgId,"/NZG%s",(char *)spaceId);
resNzgId = (char *)malloc(sizeof(char)*(slen+11));
sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId);
return ((msgSpaceId)resNzgId);
}

View file

@ -1,3 +1,6 @@
#ifndef _NZG_GLOBAL
#define _NZG_GLOBAL 1
#include <unistd.h> /* POSIX et al */
#include <stdio.h>
#include <stdlib.h>
@ -7,3 +10,4 @@
#include <sys/mman.h> /* shm_open */
#define PAGESIZE sysconf(_SC_PAGESIZE)
#endif

View file

@ -1,3 +1,7 @@
#ifndef _NZG_IFACE
#define _NZG_IFACE 1
#include "nzg_global.h"
#define MSGSPACE_DEFAULT_MODE 0600
@ -12,7 +16,14 @@ typedef struct MsgSpace {
} msgSpace;
typedef char * msgSpaceListElemId;
typedef struct MsgSpaceListElem {
void * id;
int ownerPid;
/* struct msgSpaceListElem * next; */
msgSpaceListElemId next;
} * msgSpaceList, msgSpaceListElem;
#endif
/* */

View file

@ -8,12 +8,17 @@
OS=$(shell uname -s)
CC=gcc
CFLAGS=-Wall --static
CFLAGS=-Wall --static -O2 -ggdb
#-O2 -ggdb
INCLUDES=-I ../src/
LIBINC=-L ../src
LIBINC=-L ../src -L /usr/lib
LIBS=-lnazgul
ifeq "SunOS" "${OS}"
LIBS=-lnazgul -lrt
endif
ifeq "Linux" "${OS}"
LIBS=-lnazgul -lrt
endif

View file

@ -3,10 +3,14 @@
#include "nzg_proto.h"
int main(void) {
// msgSpace mS=0;
msgSpaceId testId=(msgSpaceId)"test";
//msgSpace * mSPAC=msgSpaceCreate(testId,0,0,NULL);
// msgSpace mS=0;
msgSpaceId testId;
msgSpace * mSPAC;
testId=(msgSpaceId)"test";
mSPAC=msgSpaceCreate(testId,0,0,NULL);
msgSpaceDelete(testId);
return 0;
}