From f89c162652d20339d5c40067bbeab73d558bfc57 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianchi Date: Mon, 5 Jun 2023 16:17:20 +0200 Subject: [PATCH] funzia2 --- src/F4Client.c | 2 +- src/F4Server.c | 5 +++++ src/custom_msgq.c | 1 - src/custom_sig.c | 17 +++++------------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/F4Client.c b/src/F4Client.c index 2816b55..7a001dd 100644 --- a/src/F4Client.c +++ b/src/F4Client.c @@ -72,7 +72,7 @@ int main(int argc, char *argv[]){ semOp(_SEMID, ID, -1); printBoard(); - printf(PCLIENT "Waiting for oponent\n"); //FIXME: solo se la partita non รจ finita + printf(PCLIENT "Waiting for opponent\n"); } return 0; diff --git a/src/F4Server.c b/src/F4Server.c index dc2df53..145b385 100644 --- a/src/F4Server.c +++ b/src/F4Server.c @@ -108,5 +108,10 @@ int main(int argc, char *argv[]){ kill(_PIDS[0], SIGUSR1); kill(_PIDS[1], SIGUSR1); + semOp(_SEMID, SERVER, -1); + semOp(_SEMID, SERVER, -1); + + printf("tutto ok\n"); + raise(SIGTERM); } diff --git a/src/custom_msgq.c b/src/custom_msgq.c index 4f3bbcc..c096b8c 100644 --- a/src/custom_msgq.c +++ b/src/custom_msgq.c @@ -85,7 +85,6 @@ void rcvPlayer(player_ds *player) { msgRcv(player, sizeof(player_ds) - sizeof(long), PLAYER); } void rcvGame_end(game_end_t *game) { - printf("aspetto game\n"); msgRcv(game, sizeof(game_end_t) - sizeof(long), GAME_END); } diff --git a/src/custom_sig.c b/src/custom_sig.c index a1ddd09..af67ba1 100644 --- a/src/custom_sig.c +++ b/src/custom_sig.c @@ -126,10 +126,12 @@ void setServerSignal(int sig) { void sigHandlerClient(int sig) { // Ctrl+C if (sig == SIGINT) { - printf(PCLIENT "Quitting game\n"); + printf("\n" PCLIENT "Quitting game\n"); game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1}; sndGame_end(&game); kill(SERVER_PID, SIGUSR1); + + printf(PSERVER "You quit\n"); kill(getpid(), SIGTERM); } @@ -148,19 +150,10 @@ 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"); - printf("%d %d (%ld)\n", ID, winner.winner, winner.mtype); - // printBoard(); + printBoard(); if (winner.winner == ID) { printf(PSERVER "YOU WIN!!!\n"); } else if (winner.winner == -1) { @@ -169,8 +162,8 @@ void sigHandlerClient(int sig) { printf(PSERVER "YOU LOSE!!!\n"); } + // avviso server che ho ricevuto il messaggio semOp(_SEMID, SERVER, 1); - printf("test\n"); } }