From 751dda12b70c0eb2ceb236c75d4c2bc95e899fc0 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianchi Date: Wed, 31 May 2023 12:15:20 +0200 Subject: [PATCH] il server non chiude piu --- TODO.txt | 4 +++- src/custom_sig.c | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/TODO.txt b/TODO.txt index 7eb1bef..f4912cc 100644 --- a/TODO.txt +++ b/TODO.txt @@ -6,4 +6,6 @@ - messaggio speciale per abbandono -- se le ipcs non si sono chiuse bene non funzia \ No newline at end of file +- se le ipcs non si sono chiuse bene non funzia + +- fa errore quando un giocatore abbandona \ No newline at end of file diff --git a/src/custom_sig.c b/src/custom_sig.c index 5dcf487..72f4c6b 100644 --- a/src/custom_sig.c +++ b/src/custom_sig.c @@ -35,10 +35,12 @@ void sigHandlerServer(int sig) { signal(SIGINT, sigIntHandler2); } + // abbandono di un giocatore if (sig == SIGUSR1) { // il giocatore che abbandona mi manda gia il messaggio dicendo che ha vinto l'altro game_end_t game; rcvGame_end(&game); + printf("vince %d\n", game.winner); sndGame_end(&game); sndGame_end(&game); @@ -46,7 +48,9 @@ void sigHandlerServer(int sig) { kill(_PIDS[0], SIGUSR1); //FIXME: fare una funzione per queste robe perche anche gia scritta a fine F4Server kill(_PIDS[1], SIGUSR1); - _PIDS[0] = 0; + printf("adesso vi chiudo\n"); + + _PIDS[0] = 0; // FIXME: cosi non li prova a richiudere dopo _PIDS[1] = 0; sig = SIGTERM; @@ -129,6 +133,7 @@ void sigHandlerClient(int sig) { printf(PCLIENT "Quitting game\n"); game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1}; sndGame_end(&game); + printf("server pid: %d\n", SERVER_PID); kill(SERVER_PID, SIGUSR1); }