1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| void * archivage_ncdf()
{
int Etat;
TRAME *new_trame;
/*Variables pour mqueue*/
struct mq_attr mqArch;
mqd_t mqid;
/*instanciation structure mq_attr*/
mqArch.mq_maxmsg = 10;
mqArch.mq_msgsize = sizeof(TRAME);
mqArch.mq_flags = 0;
mqArch.mq_curmsgs = 0;
int i , j , k , l , trouve;
/*ouverture / creation du messagequeue*/
if((mqid = mq_open(MQNAME,O_CREAT|O_RDWR,0644,&mqArch)) == (mqd_t)ERROR)
{
perror("pb ouverture/creation mqueue");
exit(ERROR);
}
else puts("CREATION OK\n");
/*autorise la tache principale a detruire ce thread*/
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
FOREVER
{
/*reception trame */
new_trame = (TRAME*)malloc(sizeof(TRAME));
bzero(new_trame,sizeof(new_trame));
/*if((mqid = mq_open(MQNAME,O_RDONLY)) == (mqd_t)ERROR){perror("pb reouverture mqueue");exit(ERROR);}*/
if ((Etat = mq_receive(mqid,(void *)new_trame,sizeof(TRAME),NULL)) == -1)
{
if(mq_close(mqid) == ERROR)
{perror("pb ouverture/creation mqueue");exit(ERROR);}
free(new_trame);
perror("pb reception mqueue");exit(ERROR);
}
else printf("RECEPTION OK");
TRAITEMENT DES INFOS
}
} |
Partager