custom_msg rcv and snd

This commit is contained in:
Lorenzo Bianchi 2023-05-19 14:44:40 +02:00
parent 1f42dedc9a
commit 89d37b28c7
2 changed files with 0 additions and 87 deletions

View File

@ -1,33 +0,0 @@
#ifndef CUSTOM_MSG_H
#define CUSTOM_MSG_H
#include <server.h> //FIXME: non penso vada incluso ma serve al momento
#define MAX_NAME 16
static int _MSGQID;
typedef struct {
long mtype; // type 1
int player_id;
input_server_t server_in;
} msg_t;
typedef struct {
long mtype; // type 2
int move;
} move_t;
typedef struct {
long mtype; // type 3
int id;
char name_player[MAX_NAME];
pid_t pid;
} player_ds;
typedef struct {
long mtype; // type 4
int winner; // -1 se draw
} game_end_t;
#endif

View File

@ -1,54 +0,0 @@
#include <custom_msg.h>
#include <sys/msg.h>
void msgRcv(void *msgp, size_t size, long mtype) {
if (msgrcv(_MSGQID, msgp, size, mtype, 0) == -1) {
errExitMsg("msgrcv");
}
}
void rcvMsg(msg_t *msg) {
msgRcv(msg, sizeof(msg_t) - sizeof(long), 1);
}
void rcvMove(move_t *move) {
msgRcv(move, sizeof(move_t) - sizeof(long), 2);
}
void rcvPlayer(player_ds *player) {
msgRcv(player, sizeof(player_ds) - sizeof(long), 3);
}
void rcvGame_end(game_end_t *game) {
msgRcv(game, sizeof(game_end_t) - sizeof(long), 4);
}
void msgSnd(void *msgp, size_t size, long mtype) {
if (msg(_MSGQID, msgp, size, mtype, 0) == -1) {
errExitMsg("msgrcv");
}
}
void sndMsg(msg_t *msg) {
if (msgsnd(_MSGQID, msg, sizeof(msg_t) - sizeof(long), 0) == -1) {
errExitMsg("msgsnd");
}
}
void sndMove(move_t *move) {
if (msgsnd(_MSGQID, move, sizeof(move_t) - sizeof(long), 0) == -1) {
errExitMsg("msgsnd");
}
}
void sndPlayer(player_ds *player) {
if (msgsnd(_MSGQID, player, sizeof(player_ds) - sizeof(long), 0) == -1) {
errExitMsg("msgsnd");
}
}
void sndGame_end(game_end_t *game) {
if (msgsnd(_MSGQID, game, sizeof(game_end_t) - sizeof(long), 0) == -1) {
errExitMsg("msgsnd");
}
}