Elaborato_SO/src/custom_msgq.c

49 lines
1.1 KiB
C
Raw Normal View History

2023-05-19 14:48:00 +02:00
#include <sys/msg.h>
2023-05-19 15:21:15 +02:00
#include <custom_msgq.h>
#include <errExit.h>
2023-05-19 14:48:00 +02:00
void msgRcv(void *msgp, size_t size, long mtype) {
if (msgrcv(_MSGQID, msgp, size, mtype, 0) == -1) {
2023-05-21 18:06:19 +02:00
perror("test");
2023-05-19 14:48:00 +02:00
errExitMsg("msgrcv");
}
}
void rcvMsg(msg_t *msg) {
msgRcv(msg, sizeof(msg_t) - sizeof(long), MSG);
}
void rcvMove(move_t *move) {
msgRcv(move, sizeof(move_t) - sizeof(long), MOVE);
}
void rcvPlayer(player_ds *player) {
msgRcv(player, sizeof(player_ds) - sizeof(long), PLAYER);
}
void rcvGame_end(game_end_t *game) {
msgRcv(game, sizeof(game_end_t) - sizeof(long), GAME_END);
}
void msgSnd(void *msgp, size_t size) {
if (msgsnd(_MSGQID, msgp, size, 0) == -1) {
errExitMsg("msgsnd");
}
}
void sndMsg(msg_t *msg) {
msgSnd(msg, sizeof(msg_t) - sizeof(long));
}
void sndMove(move_t *move) {
msgSnd(move, sizeof(move_t) - sizeof(long));
}
void sndPlayer(player_ds *player) {
msgSnd(player, sizeof(player_ds) - sizeof(long));
}
void sndGame_end(game_end_t *game) {
msgSnd(game, sizeof(game_end_t) - sizeof(long));
}