Skip to content

Q2 - 2LATE & CLOSD #39

@Ca-moes

Description

@Ca-moes

Ao dar

if(unlink(fifopath)==-1){perror("Error destroying public fifo:");} 

o fifo é apagado mas o file descriptor ainda existe (pelas palavras do jpdias) e isso faz com que o cliente não consiga escrever mais para o fifo mas o server consegue ler os pedidos que lá estavam.

No programa Q2 vamos ter de mudar:

// while loop to check running time
    while(elapsedTime() < (double) nsecs){        
        // while loop to check public fifo
        if(read(fd_pub,&clientRequest,BUFSIZE)<=0){ continue;}
        // create thread with contents of public fifo
        if(pthread_create(&tid, NULL, thread_func, &clientRequest)!=0){perror("Server-pthread_Create");}
        if(pthread_detach(tid)!=0){perror("Server-pthread_detach");}
    }

    // closing sequence
    if(pthread_mutex_lock(&mut2)!=0){perror("Server-MutexLock");}
    closed.x = 1;
    if(pthread_mutex_unlock(&mut2)!=0){perror("Server-MutexUnLock");}
    float starttime;
    int readreturn;

    // notifies client threads that server is closed
    starttime = elapsedTime();
    do{
        readreturn = read(fd_pub, &clientRequest, BUFSIZE);
    } while (readreturn == 0 && elapsedTime() - starttime < MSATTEMPT);
    if (readreturn > 0){
        if(pthread_create(&tid, NULL, thread_func, &clientRequest)!=0){perror("Server-pthread_Create");}
        if(pthread_detach(tid)!=0){perror("Server-pthread_detach");}
    }
    
    // cleanup
    if(close(fd_pub)==-1){perror("Server-closePublicFifo");}
    if(unlink(fifopath)==-1){perror("Error destroying public fifo:");}
    pthread_exit((void*)0);

Para que após o ciclo while de atender pedidos seja dado unlink e tenha m ciclo igual para dar 2LATE a todos os pedidos que ainda estão no fifo

Metadata

Metadata

Assignees

No one assigned

    Labels

    QnPrograma servidor

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions