diff --git a/TODO.txt b/TODO.txt index 7caa50e..a9b34c1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -6,4 +6,6 @@ - se le ipcs non si sono chiuse bene non funzia -- controllare pareggi \ No newline at end of file +- controllare se funzionano pareggi + +- non funziona labbandono del giocatore non di turno \ No newline at end of file diff --git a/src/F4Server.c b/src/F4Server.c index 283d062..dc2df53 100644 --- a/src/F4Server.c +++ b/src/F4Server.c @@ -108,5 +108,5 @@ int main(int argc, char *argv[]){ kill(_PIDS[0], SIGUSR1); kill(_PIDS[1], SIGUSR1); - return 0; + raise(SIGTERM); } diff --git a/src/custom_sig.c b/src/custom_sig.c index f543595..5b6b20c 100644 --- a/src/custom_sig.c +++ b/src/custom_sig.c @@ -44,13 +44,20 @@ void sigHandlerServer(int sig) { sndGame_end(&game); sndGame_end(&game); - kill(_PIDS[0], SIGUSR1); //FIXME: fare una funzione per queste robe perche anche gia scritta a fine F4Server + semOp(_SEMID, SERVER, -1); kill(_PIDS[1], SIGUSR1); - // aspetto terminazione dei due figli - semOp(_SEMID, 0, -1); - semOp(_SEMID, 1, -1); + // aspetto che i figli ricevano i messaggi + printf("aspettato uno\n"); + semOp(_SEMID, SERVER, -1); + + printf("aspettato\n"); + + printf("%d %d\n", _PIDS[0], _PIDS[1]); + + kill(_PIDS[0], SIGTERM); + kill(_PIDS[1], SIGTERM); raise(SIGTERM); } @@ -129,11 +136,9 @@ void setServerSignal(int sig) { void sigHandlerClient(int sig) { // Ctrl+C if (sig == SIGINT) { - // per la sicurezza premere una seconda volta chiude il client 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); } @@ -152,12 +157,18 @@ void sigHandlerClient(int sig) { // Fine partita if (sig == SIGUSR1) { + struct msqid_ds ds; + if (msgctl(_MSGQID, IPC_STAT, &ds) == -1) + errExitMsg("msgctl"); + printf("msg num: %ld\n", ds.msg_qnum); + + printf("messaggio?\n"); game_end_t winner; rcvGame_end(&winner); printf("messaggio!\n"); - printBoard(); + // printBoard(); if (winner.winner == ID) { printf(PSERVER "YOU WIN!!!\n"); } else if (winner.winner == -1) { @@ -166,7 +177,8 @@ void sigHandlerClient(int sig) { printf(PSERVER "YOU LOSE!!!\n"); } - semOp(_SEMID, ID, 1); + semOp(_SEMID, SERVER, 1); + printf("test\n"); } }