This commit is contained in:
Lorenzo Bianchi 2023-05-18 11:48:32 +02:00
parent 7b631e5b22
commit 674737db05
2 changed files with 22 additions and 5 deletions

View File

@ -52,4 +52,9 @@ typedef struct {
pid_t pid;
} player_ds;
typedef struct {
long mtype; // type 4
int winner; // -1 se draw
} game_end_t;
#endif

View File

@ -16,6 +16,9 @@
#include <errExit.h>
#include <nonsodovemetterle.h>
int msgid;
int game_state;
tile_t *boardClient = NULL;
void checkClientinput(int argc, char *argv[]);
@ -40,14 +43,18 @@ void sigHandlerClient(int sig) {
}
printf("\n");
exit(0);
}
// Fine partita
if (sig == SIGUSR1) {
game_end_t winner;
if (msgrcv(msgid, &winner, sizeof(game_end_t) - sizeof(long), 4, 0) == -1) {
errExit("msgrcv", "fine partita");
}
game_state = winner.winner;
}
exit(0);
}
@ -56,7 +63,6 @@ int main(int argc, char *argv[]){
checkClientinput(argc, argv);
// SIGNAL
printfClient("Setting up signal\n");
sigset_t mySet;
@ -73,12 +79,18 @@ int main(int argc, char *argv[]){
if (signal(SIGTERM, sigHandlerClient) == SIG_ERR) {
errExit("signal SIGTERM", "F4Client");
}
if (signal(SIGHUP, sigHandlerClient) == SIG_ERR) {
errExit("signal SIGHUP", "F4Client");
}
if (signal(SIGUSR1, sigHandlerClient) == SIG_ERR) {
errExit("signal SIGUSR1", "F4Client");
}
//
// MSGQ
printfClient("Setting up msgq\n");
key_t msgKey = ftok(KEYFILE, 'M');
int msgid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
msgid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
if (msgid == -1) {
errExit("msgget", "F4Client");
}