This commit is contained in:
Lorenzo Bianchi 2023-05-16 15:55:05 +02:00
parent 96b488e38a
commit 739090da3b
4 changed files with 39 additions and 11 deletions

View File

@ -1,3 +1,3 @@
# Elaborato_SO
Fether super iper ghei++plus
Fether super iper ghei++plus extra

View File

@ -36,6 +36,6 @@ typedef struct {
int board_id;
input_server_t server_in;
char *name_player1, *name_player2;
} msgq_t;
} msg_t;
#endif

View File

@ -2,6 +2,8 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <sys/msg.h>
#include <custom_sem.h>
#include <structures.h>
@ -9,11 +11,22 @@
//TODO: mettere main ma non l'ho fatto per makefile
int client(){
int semid = getSemid(ftok(KEYFILE, 'S'), 2);
// int shmBoardid = getShmid(input.rows, input.collums);
// tile_t *board = shmClientAt(shmBoardid);
// MSGQ
key_t msgKey = ftok(KEYFILE, 'M');
int msqid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
if (msqid == -1) {
errExit("msgq", "F4Client");
}
if (msgrcv(msqid, ) == -1){
errExit("msgrcv", )
}
//
int semid;
semOp(semid, 0, -1); // aspetta che il server gli dia il permesso di connettersi

View File

@ -5,6 +5,7 @@
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/msg.h>
#include <server.h>
#include <structures.h>
@ -48,17 +49,31 @@ int main(int argc, char *argv[]){
sigdelset(&mySet, SIGTERM);
sigprocmask(SIG_SETMASK, &mySet, NULL);
if (signal(SIGINT, sigHandler) == SIG_ERR)
if (signal(SIGINT, sigHandler) == SIG_ERR) {
errExit("signal SIGINT", "f4Server");
if (signal(SIGTERM, sigHandler) == SIG_ERR)
}
if (signal(SIGTERM, sigHandler) == SIG_ERR) {
errExit("signal SIGTERM", "f4Server");
}
//
// MSGQ
key_t msgKey = ftok(KEYFILE, 'M');
int msqid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
if (msqid == -1)
int msgid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
if (msgid == -1) {
errExit("msgq", "F4Server");
}
// msg_t
msg_t msg = {
.mtype = 1,
.server_in = input
};
// msgsnd
if (msgsnd(msgid, &msg, sizeof(msg_t)-sizeof(long), 0) == -1) {
errExit("msgsnd", "F4Server");
}
//