Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q2 - 2LATE & CLOSD #39

Closed
Ca-moes opened this issue May 6, 2020 · 0 comments · Fixed by #40
Closed

Q2 - 2LATE & CLOSD #39

Ca-moes opened this issue May 6, 2020 · 0 comments · Fixed by #40
Labels
Qn Programa servidor
Milestone

Comments

@Ca-moes
Copy link
Owner

Ca-moes commented May 6, 2020

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

@Ca-moes Ca-moes added the Qn Programa servidor label May 6, 2020
@Ca-moes Ca-moes added this to the Etapa 2 milestone May 6, 2020
@Ca-moes Ca-moes linked a pull request May 6, 2020 that will close this issue
@Ca-moes Ca-moes pinned this issue May 6, 2020
@Ca-moes Ca-moes added this to Done in ProjectProgression via automation May 9, 2020
@Ca-moes Ca-moes added this to Done in Server Program via automation May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Qn Programa servidor
Projects
Development

Successfully merging a pull request may close this issue.

1 participant